Skip to content

Commit ef29e84

Browse files
Generate RenameObject S3 operation
1 parent 3a47b18 commit ef29e84

File tree

10 files changed

+669
-515
lines changed

10 files changed

+669
-515
lines changed

generator/ServiceClientGeneratorLib/ServiceModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ public List<Operation> S3AllowListOperations
578578
new Operation(this, "DeleteBucketMetadataConfiguration", DocumentRoot[OperationsKey]["DeleteBucketMetadataConfiguration"]),
579579
new Operation(this, "ListObjects", DocumentRoot[OperationsKey]["ListObjects"]),
580580
new Operation(this,"UpdateBucketMetadataJournalTableConfiguration", DocumentRoot[OperationsKey]["UpdateBucketMetadataJournalTableConfiguration"]),
581-
new Operation(this, "ListMultipartUploads", DocumentRoot[OperationsKey]["ListMultipartUploads"])
581+
new Operation(this, "ListMultipartUploads", DocumentRoot[OperationsKey]["ListMultipartUploads"]),
582+
new Operation(this, "RenameObject", DocumentRoot[OperationsKey]["RenameObject"]),
582583
};
583584
}
584585
return _s3AllowListOperations.Where(operation => operation.data != null).ToList();

generator/ServiceModels/s3/s3.customizations.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,34 @@
12871287
},
12881288
{
12891289
"Uploads":{"emitPropertyName":"MultipartUploads"}
1290-
1291-
1290+
}
1291+
]
1292+
},
1293+
"RenameObjectRequest":{
1294+
"modify":[
1295+
{
1296+
"ClientToken" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._clientToken);"]}
1297+
},
1298+
{
1299+
"BucketName" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._bucketName);"]}
1300+
},
1301+
{
1302+
"Key" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._key);"]}
1303+
},
1304+
{
1305+
"RenameSource" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._renameSource);"]}
1306+
},
1307+
{
1308+
"DestinationIfMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._destinationIfMatch);"]}
1309+
},
1310+
{
1311+
"DestinationIfNoneMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._destinationIfNoneMatch);"]}
1312+
},
1313+
{
1314+
"SourceIfMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._sourceIfMatch);"]}
1315+
},
1316+
{
1317+
"SourceIfNoneMatch" :{"injectXmlIsSet":["return !string.IsNullOrEmpty(this._sourceIfNoneMatch);"]}
12921318
}
12931319
]
12941320
}

sdk/src/Services/S3/Custom/Model/Internal/MarshallTransformations/RenameObjectRequestMarshaller.cs

Lines changed: 18 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -16,126 +16,38 @@
1616
using Amazon.Runtime;
1717
using Amazon.Runtime.Internal;
1818
using Amazon.Runtime.Internal.Transform;
19-
using Amazon.Runtime.Internal.Util;
19+
using Amazon.S3.Util;
2020
using Amazon.Util;
2121
using System;
22-
using System.Diagnostics.CodeAnalysis;
22+
using System.Globalization;
23+
24+
#pragma warning disable 1591
2325

2426
namespace Amazon.S3.Model.Internal.MarshallTransformations
2527
{
2628
/// <summary>
2729
/// RenameObject Request Marshaller
28-
/// </summary>
29-
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters")]
30-
public class RenameObjectRequestMarshaller : IMarshaller<IRequest, RenameObjectRequest>, IMarshaller<IRequest, AmazonWebServiceRequest>
30+
/// </summary>
31+
public partial class RenameObjectRequestMarshaller : IMarshaller<IRequest, RenameObjectRequest>, IMarshaller<IRequest, AmazonWebServiceRequest>
3132
{
32-
/// <summary>
33-
/// Marshaller the request object to the HTTP request.
34-
/// </summary>
35-
/// <param name="input"></param>
36-
/// <returns></returns>
37-
public IRequest Marshall(AmazonWebServiceRequest input)
33+
partial void PreMarshallCustomization(DefaultRequest defaultRequest, RenameObjectRequest publicRequest)
3834
{
39-
return this.Marshall((RenameObjectRequest)input);
40-
}
41-
42-
/// <summary>
43-
/// Marshaller the request object to the HTTP request.
44-
/// </summary>
45-
/// <param name="renameObjectRequest"></param>
46-
/// <returns></returns>
47-
public IRequest Marshall(RenameObjectRequest renameObjectRequest)
48-
{
49-
if (renameObjectRequest == null)
50-
throw new ArgumentNullException(nameof(renameObjectRequest));
51-
52-
var request = new DefaultRequest(renameObjectRequest, "Amazon.S3");
53-
request.HttpMethod = "PUT";
54-
string uriResourcePath = "/{Key+}";
55-
request.AddSubResource("renameObject");
56-
57-
if (renameObjectRequest.IsSetClientToken())
58-
{
59-
request.Headers.Add(HeaderKeys.XAmzClientTokenHeader, S3Transforms.ToStringValue(renameObjectRequest.ClientToken));
60-
}
61-
else
62-
{
63-
request.Headers.Add(HeaderKeys.XAmzClientTokenHeader, Guid.NewGuid().ToString());
64-
}
65-
66-
if (renameObjectRequest.IsSetDestinationIfMatch())
67-
{
68-
request.Headers.Add(HeaderKeys.IfMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.DestinationIfMatch));
69-
}
70-
71-
if (renameObjectRequest.IsSetDestinationIfModifiedSince())
72-
{
73-
request.Headers.Add(HeaderKeys.IfModifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.DestinationIfModifiedSince));
74-
}
35+
36+
if (defaultRequest == null)
37+
throw new ArgumentNullException(nameof(defaultRequest));
7538

76-
if (renameObjectRequest.IsSetDestinationIfNoneMatch())
39+
if (!publicRequest.IsSetRenameSource())
7740
{
78-
request.Headers.Add(HeaderKeys.IfNoneMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.DestinationIfNoneMatch));
41+
throw new ArgumentException("RenameSource is a required property and must be set before making this call.", nameof(publicRequest));
7942
}
8043

81-
if (renameObjectRequest.IsSetDestinationIfUnmodifiedSince())
82-
{
83-
request.Headers.Add(HeaderKeys.IfUnmodifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.DestinationIfUnmodifiedSince));
84-
}
85-
86-
if (renameObjectRequest.IsSetRenameSource())
87-
{
88-
request.Headers.Add(HeaderKeys.XAmzRenameSourceHeader, S3Transforms.ToStringValue(renameObjectRequest.RenameSource));
89-
}
90-
91-
if (renameObjectRequest.IsSetSourceIfMatch())
92-
{
93-
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.SourceIfMatch));
94-
}
95-
96-
if (renameObjectRequest.IsSetSourceIfModifiedSince())
97-
{
98-
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfModifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.SourceIfModifiedSince));
99-
}
100-
101-
if (renameObjectRequest.IsSetSourceIfNoneMatch())
102-
{
103-
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfNoneMatchHeader, S3Transforms.ToStringValue(renameObjectRequest.SourceIfNoneMatch));
104-
}
105-
106-
if (renameObjectRequest.IsSetSourceIfUnmodifiedSince())
107-
{
108-
request.Headers.Add(HeaderKeys.XAmzRenameSourceIfUnmodifiedSinceHeader, StringUtils.FromDateTimeToRFC822(renameObjectRequest.SourceIfUnmodifiedSince));
109-
}
110-
111-
if (!renameObjectRequest.IsSetBucketName())
112-
throw new ArgumentException("BucketName is a required property and must be set before making this call.", nameof(renameObjectRequest));
113-
if (!renameObjectRequest.IsSetKey())
114-
throw new ArgumentException("Key is a required property and must be set before making this call.", nameof(renameObjectRequest));
115-
if (!renameObjectRequest.IsSetRenameSource())
116-
throw new ArgumentException("RenameSource is a required property and must be set before making this call.", nameof(renameObjectRequest));
117-
118-
uriResourcePath = uriResourcePath.Replace("{Key+}", StringUtils.FromString(renameObjectRequest.Key));
119-
request.ResourcePath = uriResourcePath;
120-
request.UseQueryString = true;
121-
122-
return request;
123-
}
124-
125-
private static RenameObjectRequestMarshaller _instance;
126-
127-
/// <summary>
128-
/// Singleton for marshaller
129-
/// </summary>
130-
public static RenameObjectRequestMarshaller Instance
131-
{
132-
get
44+
// For backward compatibility with the previous custom implementation, we automatically generate
45+
// a unique client token (GUID) when the caller doesn't explicitly set one. This complements the
46+
// generated RenameObjectRequestMarshaller.Marshall() method (in the Generated folder), which
47+
// handles the check for ClientToken existence.
48+
if (!publicRequest.IsSetClientToken())
13349
{
134-
if (_instance == null)
135-
{
136-
_instance = new RenameObjectRequestMarshaller();
137-
}
138-
return _instance;
50+
defaultRequest.Headers.Add(HeaderKeys.XAmzClientTokenHeader, Guid.NewGuid().ToString());
13951
}
14052
}
14153
}

0 commit comments

Comments
 (0)