Skip to content

Commit 8cd7ecc

Browse files
authored
feat(dl-center): add support for arbitrary acls COMPASS-9237 (#525)
This commit adjusts our DownloadCenter's UploadAssetOptions to support taking an optional 'acl' parameter. When we upload an asset to S3, this parameter is used to set the ACL on the put request. If no acl is set, we default to "public-read" to preserve backward compatibility.
1 parent 26a21b6 commit 8cd7ecc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/dl-center/src/download-center.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ describe('download center client', function () {
7979
const content = await downloadCenter.downloadAsset('prefix/asset.txt');
8080
expect(content?.toString()).to.contain('content');
8181
});
82+
83+
it('can upload a file with private acls and download it back', async function () {
84+
await downloadCenter.uploadAsset(
85+
'prefix-private/asset.txt',
86+
createReadStream(fixturePath('asset.txt')),
87+
{
88+
acl: 'private',
89+
}
90+
);
91+
92+
const content = await downloadCenter.downloadAsset(
93+
'prefix-private/asset.txt'
94+
);
95+
expect(content?.toString()).to.contain('content');
96+
});
8297
});
8398

8499
describe('upload / download config', function () {

packages/dl-center/src/download-center.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type S3BucketConfig = {
5252

5353
export type UploadAssetOptions = {
5454
contentType?: string;
55+
acl?: string;
5556
};
5657

5758
type S3UploadFunc = (
@@ -235,8 +236,10 @@ export class DownloadCenter {
235236
throw new Error('s3ObjectKey is required');
236237
}
237238

239+
const acl = options.acl ?? ACL_PUBLIC_READ;
240+
238241
const uploadParams: S3.PutObjectRequest = {
239-
ACL: ACL_PUBLIC_READ,
242+
ACL: acl,
240243
Bucket: this.s3BucketName,
241244
Key: s3ObjectKey,
242245
Body: content,

0 commit comments

Comments
 (0)