Skip to content

Commit 9b5cb9d

Browse files
Dynamically choose between sending canned ACL in the request or not
1 parent 1edb6dd commit 9b5cb9d

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

dotnet/src/dotnetframework/Providers/Storage/GXAmazonS3/ExternalProviderS3.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public class ExternalProviderS3 : ExternalProviderBase, ExternalProvider
4949

5050
bool forcePathStyle = false;
5151
bool customEndpoint = false;
52-
52+
53+
bool objectOwnershipEnabled;
54+
5355
public string StorageUri
5456
{
5557
get {
@@ -104,6 +106,8 @@ private void Initialize() {
104106
}
105107
}
106108

109+
objectOwnershipEnabled = !GetPropertyValue(DEFAULT_ACL, DEFAULT_ACL_DEPRECATED, "").Equals("Bucket owner enforced");
110+
107111
#if NETCORE
108112
if (credentials != null)
109113
{
@@ -227,16 +231,19 @@ public string Upload(string localFile, string objectName, GxFileType fileType)
227231
{
228232
BucketName = Bucket,
229233
Key = objectName,
230-
FilePath = localFile,
231-
CannedACL = GetCannedACL(fileType)
234+
FilePath = localFile
232235
};
236+
if (objectOwnershipEnabled)
237+
{
238+
objectRequest.CannedACL = GetCannedACL(fileType);
239+
}
233240
PutObject(objectRequest);
234241
return GetUrlImpl(objectName, fileType);
235242
}
236243

237244
private bool IsPrivateUpload(GxFileType fileType)
238245
{
239-
return GetCannedACL(fileType) != S3CannedACL.PublicRead;
246+
return (GetCannedACL(fileType) != S3CannedACL.PublicRead) && objectOwnershipEnabled;
240247
}
241248

242249
public string Get(string objectName, GxFileType fileType, int urlMinutes = 0)
@@ -327,10 +334,14 @@ public string Copy(string objectName, GxFileType sourceFileType, string newName,
327334
SourceKey = objectName,
328335
DestinationBucket = Bucket,
329336
DestinationKey = newName,
330-
CannedACL = GetCannedACL(destFileType),
331337
MetadataDirective = S3MetadataDirective.REPLACE
332338
};
333339

340+
if (objectOwnershipEnabled)
341+
{
342+
request.CannedACL = GetCannedACL(destFileType);
343+
}
344+
334345
if (TryGetContentType(newName, out string mimeType, DEFAULT_CONTENT_TYPE))
335346
{
336347
request.ContentType = mimeType;
@@ -384,10 +395,14 @@ private string UploadMultipart(string fileName, Stream stream, GxFileType destFi
384395
BucketName = Bucket,
385396
Key = fileName,
386397
PartSize = MULITIPART_POST_PART_SIZE,
387-
InputStream = stream,
388-
CannedACL = GetCannedACL(destFileType)
398+
InputStream = stream
389399
};
390400

401+
if (objectOwnershipEnabled)
402+
{
403+
uploadRequest.CannedACL = GetCannedACL(destFileType);
404+
}
405+
391406
if (TryGetContentType(fileName, out string mimeType))
392407
{
393408
uploadRequest.ContentType = mimeType;
@@ -404,9 +419,14 @@ private string UploadSimple(string fileName, Stream stream, GxFileType destFileT
404419
{
405420
BucketName = Bucket,
406421
Key = fileName,
407-
InputStream = stream,
408-
CannedACL = GetCannedACL(destFileType)
422+
InputStream = stream
409423
};
424+
425+
if (objectOwnershipEnabled)
426+
{
427+
objectRequest.CannedACL = GetCannedACL(destFileType);
428+
}
429+
410430
if (TryGetContentType(fileName, out string mimeType))
411431
{
412432
objectRequest.ContentType = mimeType;
@@ -430,10 +450,14 @@ public string Copy(string url, string newName, string tableName, string fieldNam
430450
SourceKey = url,
431451
DestinationBucket = Bucket,
432452
DestinationKey = resourceKey,
433-
CannedACL = GetCannedACL(destFileType),
434453
MetadataDirective = S3MetadataDirective.REPLACE
435454
};
436455

456+
if (objectOwnershipEnabled)
457+
{
458+
request.CannedACL = GetCannedACL(destFileType);
459+
}
460+
437461
if (TryGetContentType(newName, out string mimeType, DEFAULT_CONTENT_TYPE))
438462
{
439463
request.ContentType = mimeType;
@@ -455,9 +479,12 @@ public string Save(Stream fileStream, string fileName, string tableName, string
455479
{
456480
BucketName = Bucket,
457481
Key = resourceKey,
458-
InputStream = fileStream,
459-
CannedACL = GetCannedACL(destFileType)
482+
InputStream = fileStream
460483
};
484+
if (objectOwnershipEnabled)
485+
{
486+
objectRequest.CannedACL = GetCannedACL(destFileType);
487+
}
461488
if (TryGetContentType(fileName, out string mimeType))
462489
{
463490
objectRequest.ContentType = mimeType;

0 commit comments

Comments
 (0)