Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,24 @@ WriteXmlAttributeString(level + 1, member, variableName, isPayload: true, operat
void ProcessStructure(int level, string variableName, Member member)
{
var shape = member.Shape.IsList ? member.Shape.ListShape : member.Shape ;
variableName = member.Shape.IsList ? variableName : variableName + "." + member.PropertyName;

// Use shape's ListMarshallName if the structure is a list.
var marshallName = member.Shape.IsList ? member.Shape.ListMarshallName ?? "member" : member.MarshallName;
if(member.Shape.IsFlattened || member.IsFlattened)
marshallName = member.LocationName ?? member.ModeledName;
if (member.Shape.IsList)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this so that I can just customize the IsSet method to control marshalling logic. But also, it's the rightr thing to do. It's also related to:
#4247

{
#>
<#=new string(' ', level * 4)#> if (<#=variableName#> != null)
<#=new string(' ', level * 4)#> {
<#+
}
else
{
#>
<#=new string(' ', level * 4)#> if (<#=variableName#>.IsSet<#=member.PropertyName#>())
<#=new string(' ', level * 4)#> {
<#+
}
if (!string.IsNullOrEmpty(member.Shape.XmlNamespace))
{
if (!string.IsNullOrEmpty(member.Shape.XmlNamespacePrefix))
Expand All @@ -521,6 +529,7 @@ WriteXmlAttributeString(level + 1, member, variableName, isPayload: true, operat
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("<#=marshallName#>");
<#+
}
variableName = member.Shape.IsList ? variableName : variableName + "." + member.PropertyName;
ProcessMembers(level + 1, variableName, shape.Members);
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteEndElement();
Expand Down
3 changes: 2 additions & 1 deletion generator/ServiceClientGeneratorLib/ServiceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ public List<Operation> S3AllowListOperations
new Operation(this, "DeleteObject", DocumentRoot[OperationsKey]["DeleteObject"]),
new Operation(this, "DeleteObjects", DocumentRoot[OperationsKey]["DeleteObjects"]),
new Operation(this, "DeleteObjectTagging", DocumentRoot[OperationsKey]["DeleteObjectTagging"]),
new Operation(this, "GetBucketLogging", DocumentRoot[OperationsKey]["GetBucketLogging"])
new Operation(this, "GetBucketLogging", DocumentRoot[OperationsKey]["GetBucketLogging"]),
new Operation(this, "PutBucketLogging", DocumentRoot[OperationsKey]["PutBucketLogging"])
};
}
return _s3AllowListOperations.Where(operation => operation.data != null).ToList();
Expand Down
32 changes: 32 additions & 0 deletions generator/ServiceModels/s3/s3.customizations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,26 @@
},
{
"TargetGrants":{"emitPropertyName":"Grants"}
},
{
"TargetPrefix":{"injectXmlMarshallCode":["TargetPrefixCustomMarshall(publicRequest, xmlWriter);"]}
}
]
},
"PutBucketLoggingRequest":{
"modify":[
{
"LoggingEnabled":{"emitPropertyName":"LoggingConfig", "injectXmlIsSet":["return this._loggingConfig != null && this._loggingConfig.IsSetTargetBucketName();"]}
},
{
"ExpectedBucketOwner":{"injectXmlIsSet":["return !String.IsNullOrEmpty(this._expectedBucketOwner);"]}
}
]
},
"BucketLoggingStatus":{
"modify":[
{
"LoggingEnabled":{"emitPropertyName":"LoggingConfig"}
}
]
}
Expand Down Expand Up @@ -1912,6 +1932,18 @@
],
"UploadPartCopyOutput" : [
"CopyPartResult"
],
"RestoreObjectRequest":[
"RestoreRequest"
],
"CompleteMultipartUploadRequest":[
"MultipartUpload"
],
"DeleteObjectsRequest":[
"Delete"
],
"PutBucketLoggingRequest":[
"BucketLoggingStatus"
]
},
"excludeShapes":[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
Expand All @@ -13,188 +13,34 @@
* permissions and limitations under the License.
*/

using System.IO;
using System.Xml;
using System.Text;
using Amazon.S3.Util;
using Amazon.Runtime;
using Amazon.Runtime.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Amazon.S3.Model;
using Amazon.Runtime.Internal.Transform;
using Amazon.Util;
using Amazon.Runtime.Internal.Util;

#pragma warning disable 1591
using Amazon.Runtime;

#pragma warning disable CS0612,CS0618
namespace Amazon.S3.Model.Internal.MarshallTransformations
{
/// <summary>
/// Enable Bucket Logging Request Marshaller
/// </summary>
public class PutBucketLoggingRequestMarshaller : IMarshaller<IRequest, PutBucketLoggingRequest> ,IMarshaller<IRequest,Amazon.Runtime.AmazonWebServiceRequest>
{
public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
{
return this.Marshall((PutBucketLoggingRequest)input);
}

public IRequest Marshall(PutBucketLoggingRequest putBucketLoggingRequest)
public partial class PutBucketLoggingRequestMarshaller : IMarshaller<IRequest, PutBucketLoggingRequest>, IMarshaller<IRequest, AmazonWebServiceRequest>
{
void TargetPrefixCustomMarshall(PutBucketLoggingRequest publicRequest, XmlWriter xmlWriter)
{
IRequest request = new DefaultRequest(putBucketLoggingRequest, "Amazon.S3");

request.HttpMethod = "PUT";

if (putBucketLoggingRequest.IsSetChecksumAlgorithm())
request.Headers.Add(S3Constants.AmzHeaderSdkChecksumAlgorithm, S3Transforms.ToStringValue(putBucketLoggingRequest.ChecksumAlgorithm));

if (putBucketLoggingRequest.IsSetExpectedBucketOwner())
request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(putBucketLoggingRequest.ExpectedBucketOwner));

if (string.IsNullOrEmpty(putBucketLoggingRequest.BucketName))
throw new System.ArgumentException("BucketName is a required property and must be set before making this call.", "PutBucketLoggingRequest.BucketName");

request.ResourcePath = "/";

request.AddSubResource("logging");

var stringWriter = new XMLEncodedStringWriter(System.Globalization.CultureInfo.InvariantCulture);

using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8, OmitXmlDeclaration = true, NewLineHandling = NewLineHandling.Entitize }))
{
xmlWriter.WriteStartElement("BucketLoggingStatus", S3Constants.S3RequestXmlNamespace);
var bucketLoggingStatusBucketLoggingStatus = putBucketLoggingRequest.LoggingConfig;
if (bucketLoggingStatusBucketLoggingStatus != null)
{
if (bucketLoggingStatusBucketLoggingStatus != null)
{
var loggingEnabledLoggingEnabled = bucketLoggingStatusBucketLoggingStatus;
if (loggingEnabledLoggingEnabled != null && loggingEnabledLoggingEnabled.IsSetTargetBucketName())
{
xmlWriter.WriteStartElement("LoggingEnabled");
xmlWriter.WriteElementString("TargetBucket", S3Transforms.ToXmlStringValue(loggingEnabledLoggingEnabled.TargetBucketName));

var loggingEnabledLoggingEnabledtargetGrantsList = loggingEnabledLoggingEnabled.Grants;
if (loggingEnabledLoggingEnabledtargetGrantsList != null && loggingEnabledLoggingEnabledtargetGrantsList.Count > 0)
{
xmlWriter.WriteStartElement("TargetGrants");
foreach (var loggingEnabledLoggingEnabledtargetGrantsListValue in loggingEnabledLoggingEnabledtargetGrantsList)
{
xmlWriter.WriteStartElement("Grant");
if (loggingEnabledLoggingEnabledtargetGrantsListValue != null)
{
var granteeGrantee = loggingEnabledLoggingEnabledtargetGrantsListValue.Grantee;
if (granteeGrantee != null)
{
xmlWriter.WriteStartElement("xsi","Grantee", "http://www.w3.org/2001/XMLSchema-instance");
if (granteeGrantee.IsSetType())
{
xmlWriter.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", granteeGrantee.Type.ToString());
}
if (granteeGrantee.IsSetDisplayName())
{
xmlWriter.WriteElementString("DisplayName", S3Transforms.ToXmlStringValue(granteeGrantee.DisplayName));
}
if (granteeGrantee.IsSetEmailAddress())
{
xmlWriter.WriteElementString("EmailAddress", S3Transforms.ToXmlStringValue(granteeGrantee.EmailAddress));
}
if (granteeGrantee.IsSetCanonicalUser())
{
xmlWriter.WriteElementString("ID", S3Transforms.ToXmlStringValue(granteeGrantee.CanonicalUser));
}
if (granteeGrantee.IsSetURI())
{
xmlWriter.WriteElementString("URI", S3Transforms.ToXmlStringValue(granteeGrantee.URI));
}
xmlWriter.WriteEndElement();
}

if (loggingEnabledLoggingEnabledtargetGrantsListValue.IsSetPermission())
{
xmlWriter.WriteElementString("Permission", S3Transforms.ToXmlStringValue(loggingEnabledLoggingEnabledtargetGrantsListValue.Permission));
}
}

xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

if (loggingEnabledLoggingEnabled.TargetObjectKeyFormat != null)
{
xmlWriter.WriteStartElement("TargetObjectKeyFormat", "http://s3.amazonaws.com/doc/2006-03-01/");

if (loggingEnabledLoggingEnabled.TargetObjectKeyFormat.PartitionedPrefix != null)
{
xmlWriter.WriteStartElement("PartitionedPrefix", "http://s3.amazonaws.com/doc/2006-03-01/");
if (loggingEnabledLoggingEnabled.TargetObjectKeyFormat.PartitionedPrefix.IsSetPartitionDateSource())
xmlWriter.WriteElementString("PartitionDateSource", "http://s3.amazonaws.com/doc/2006-03-01/", StringUtils.FromString(loggingEnabledLoggingEnabled.TargetObjectKeyFormat.PartitionedPrefix.PartitionDateSource));

xmlWriter.WriteEndElement();
}

if (loggingEnabledLoggingEnabled.TargetObjectKeyFormat.SimplePrefix != null)
{
xmlWriter.WriteStartElement("SimplePrefix", "http://s3.amazonaws.com/doc/2006-03-01/");
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

if (loggingEnabledLoggingEnabled.IsSetTargetPrefix())
{
xmlWriter.WriteElementString("TargetPrefix", S3Transforms.ToXmlStringValue(loggingEnabledLoggingEnabled.TargetPrefix));
}
else
{
xmlWriter.WriteStartElement("TargetPrefix");
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}
}
}

xmlWriter.WriteEndElement();
}

try
if (publicRequest.LoggingConfig.IsSetTargetPrefix())
{
var content = stringWriter.ToString();
request.Content = Encoding.UTF8.GetBytes(content);
request.Headers[HeaderKeys.ContentTypeHeader] = "application/xml";

ChecksumUtils.SetChecksumData(
request,
putBucketLoggingRequest.ChecksumAlgorithm,
fallbackToMD5: false,
isRequestChecksumRequired: true,
headerName: S3Constants.AmzHeaderSdkChecksumAlgorithm
);
xmlWriter.WriteElementString("TargetPrefix", S3Transforms.ToXmlStringValue(publicRequest.LoggingConfig.TargetPrefix));
}
catch (EncoderFallbackException e)
else
{
throw new AmazonServiceException("Unable to marshall request to XML", e);
xmlWriter.WriteStartElement("TargetPrefix");
xmlWriter.WriteEndElement();
}

return request;
}

private static PutBucketLoggingRequestMarshaller _instance;

/// <summary>
/// Singleton for marshaller
/// </summary>
public static PutBucketLoggingRequestMarshaller Instance
{
get
{
if (_instance == null)
{
_instance = new PutBucketLoggingRequestMarshaller();
}
return _instance;
}
}
}
}

This file was deleted.

Loading
Loading