-
Notifications
You must be signed in to change notification settings - Fork 874
S3 Generate RenameObject operation #4198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
| { | ||
| /// <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()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i can answer that. this is because
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't validate all the properties, just |
||
| { | ||
| 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()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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?🫠