Skip to content
Merged
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
4 changes: 2 additions & 2 deletions generator/ServiceClientGeneratorLib/ServiceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ public List<Operation> S3AllowListOperations
new Operation(this, "DeleteBucketInventoryConfiguration", DocumentRoot[OperationsKey]["DeleteBucketInventoryConfiguration"]),
new Operation(this,"PutBucketRequestPayment", DocumentRoot[OperationsKey]["PutBucketRequestPayment"]),
new Operation(this, "CreateBucketMetadataConfiguration",DocumentRoot[OperationsKey]["CreateBucketMetadataConfiguration"]),
new Operation(this, "GetBucketMetadataConfiguration", DocumentRoot[OperationsKey]["GetBucketMetadataConfiguration"])

new Operation(this, "GetBucketMetadataConfiguration", DocumentRoot[OperationsKey]["GetBucketMetadataConfiguration"]),
new Operation(this, "RenameObject", DocumentRoot[OperationsKey]["RenameObject"]),
};
}
return _s3AllowListOperations.Where(operation => operation.data != null).ToList();
Expand Down
28 changes: 28 additions & 0 deletions generator/ServiceModels/s3/s3.customizations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,34 @@
"ExpectedBucketOwner":{"injectXmlIsSet":["return !String.IsNullOrEmpty(this._expectedBucketOwner);"]}
}
]
},
"RenameObjectRequest":{
"modify":[
{
"ClientToken" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._clientToken);"]}
},
{
"BucketName" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._bucketName);"]}
},
{
"Key" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._key);"]}
},
{
"RenameSource" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._renameSource);"]}
},
{
"DestinationIfMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._destinationIfMatch);"]}
},
{
"DestinationIfNoneMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._destinationIfNoneMatch);"]}
},
{
"SourceIfMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._sourceIfMatch);"]}
},
{
"SourceIfNoneMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._sourceIfNoneMatch);"]}
}
]
}

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,126 +16,38 @@
using Amazon.Runtime;
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Transform;
using Amazon.Runtime.Internal.Util;
using Amazon.S3.Util;
using Amazon.Util;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

#pragma warning disable 1591

namespace Amazon.S3.Model.Internal.MarshallTransformations
{
/// <summary>
/// RenameObject Request Marshaller
/// </summary>
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters")]
public class RenameObjectRequestMarshaller : IMarshaller<IRequest, RenameObjectRequest>, IMarshaller<IRequest, AmazonWebServiceRequest>
/// </summary>
public partial class RenameObjectRequestMarshaller : IMarshaller<IRequest, RenameObjectRequest>, IMarshaller<IRequest, AmazonWebServiceRequest>
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/aws/aws-sdk-net/blob/main/sdk/src/Services/S3/Custom/Model/Internal/MarshallTransformations/RenameObjectRequestMarshaller.cs#L49-L51

THis is a minor difference and i don't know why anyone would do this but the original code also checked the actual request wasn't null. Can we add that to the preMarshallCustomization too?🫠

{
/// <summary>
/// Marshaller the request object to the HTTP request.
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public IRequest Marshall(AmazonWebServiceRequest input)
{
return this.Marshall((RenameObjectRequest)input);
}

/// <summary>
/// Marshaller the request object to the HTTP request.
/// </summary>
/// <param name="renameObjectRequest"></param>
/// <returns></returns>
public IRequest Marshall(RenameObjectRequest renameObjectRequest)
partial void PreMarshallCustomization(DefaultRequest defaultRequest, RenameObjectRequest publicRequest)
{

if (renameObjectRequest == null)
throw new ArgumentNullException(nameof(renameObjectRequest));

var request = new DefaultRequest(renameObjectRequest, "Amazon.S3");
request.HttpMethod = "PUT";
string uriResourcePath = "/{Key+}";
request.AddSubResource("renameObject");

if (renameObjectRequest.IsSetClientToken())
{
request.Headers.Add(HeaderKeys.XAmzClientTokenHeader, S3Transforms.ToStringValue(renameObjectRequest.ClientToken));
}
else
{
request.Headers.Add(HeaderKeys.XAmzClientTokenHeader, Guid.NewGuid().ToString());
}

if (renameObjectRequest.IsSetDestinationIfMatch())
{
request.Headers.Add(HeaderKeys.IfMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.DestinationIfMatch));
}

if (renameObjectRequest.IsSetDestinationIfModifiedSince())
{
request.Headers.Add(HeaderKeys.IfModifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.DestinationIfModifiedSince));
}

if (renameObjectRequest.IsSetDestinationIfNoneMatch())
if (!publicRequest.IsSetRenameSource())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a question for @peterrsongg: In your PRs these usually were generated as well. Why do they have to be hand-written here?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i can answer that. this is because RenameSource is a required header, and currently we only validate that required querystring members and resource path members are set in the generator

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't validate all the properties, just RequestUriMembers and RenameSource is added to the header so we don't validate it as part of the generated code.
https://github.com/aws/aws-sdk-net/blob/muhamoth/S3-generate-RenameObject-operation/generator/ServiceClientGeneratorLib/Generators/Marshallers/BaseMarshaller.tt#L135

{
request.Headers.Add(HeaderKeys.IfNoneMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.DestinationIfNoneMatch));
throw new ArgumentException("RenameSource is a required property and must be set before making this call.", nameof(publicRequest));
}

if (renameObjectRequest.IsSetDestinationIfUnmodifiedSince())
{
request.Headers.Add(HeaderKeys.IfUnmodifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.DestinationIfUnmodifiedSince));
}

if (renameObjectRequest.IsSetRenameSource())
{
request.Headers.Add(HeaderKeys.XAmzRenameSourceHeader, S3Transforms.ToStringValue(renameObjectRequest.RenameSource));
}

if (renameObjectRequest.IsSetSourceIfMatch())
{
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.SourceIfMatch));
}

if (renameObjectRequest.IsSetSourceIfModifiedSince())
{
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfModifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.SourceIfModifiedSince));
}

if (renameObjectRequest.IsSetSourceIfNoneMatch())
{
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfNoneMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.SourceIfNoneMatch));
}

if (renameObjectRequest.IsSetSourceIfUnmodifiedSince())
{
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfUnmodifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.SourceIfUnmodifiedSince));
}

if (!renameObjectRequest.IsSetBucketName())
throw new ArgumentException("BucketName is a required property and must be set before making this call.", nameof(renameObjectRequest));
if (!renameObjectRequest.IsSetKey())
throw new ArgumentException("Key is a required property and must be set before making this call.", nameof(renameObjectRequest));
if (!renameObjectRequest.IsSetRenameSource())
throw new ArgumentException("RenameSource is a required property and must be set before making this call.", nameof(renameObjectRequest));

uriResourcePath = uriResourcePath.Replace("{Key+}", StringUtils.FromString(renameObjectRequest.Key));
request.ResourcePath = uriResourcePath;
request.UseQueryString = true;

return request;
}

private static RenameObjectRequestMarshaller _instance;

/// <summary>
/// Singleton for marshaller
/// </summary>
public static RenameObjectRequestMarshaller Instance
{
get
/// For backward compatibility with the previous custom implementation, we automatically generate
/// a unique client token (GUID) when the caller doesn't explicitly set one. This complements the
/// generated RenameObjectRequestMarshaller.Marshall() method (in the Generated folder), which
/// handles the check for ClientToken existence.
if (!publicRequest.IsSetClientToken())
{
if (_instance == null)
{
_instance = new RenameObjectRequestMarshaller();
}
return _instance;
defaultRequest.Headers.Add(HeaderKeys.XAmzClientTokenHeader, Guid.NewGuid().ToString());
}
}
}
Expand Down
Loading