From 34ca6051b64e369f48ae78c5806f84ef83847b04 Mon Sep 17 00:00:00 2001 From: Dylan Richardson Date: Tue, 1 Apr 2025 13:09:34 +0000 Subject: [PATCH] feat(dl-center): add support for arbitrary acls COMPASS-9237 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. --- packages/dl-center/src/download-center.spec.ts | 15 +++++++++++++++ packages/dl-center/src/download-center.ts | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/dl-center/src/download-center.spec.ts b/packages/dl-center/src/download-center.spec.ts index 3d2360ce..e6712aed 100644 --- a/packages/dl-center/src/download-center.spec.ts +++ b/packages/dl-center/src/download-center.spec.ts @@ -79,6 +79,21 @@ describe('download center client', function () { const content = await downloadCenter.downloadAsset('prefix/asset.txt'); expect(content?.toString()).to.contain('content'); }); + + it('can upload a file with private acls and download it back', async function () { + await downloadCenter.uploadAsset( + 'prefix-private/asset.txt', + createReadStream(fixturePath('asset.txt')), + { + acl: 'private', + } + ); + + const content = await downloadCenter.downloadAsset( + 'prefix-private/asset.txt' + ); + expect(content?.toString()).to.contain('content'); + }); }); describe('upload / download config', function () { diff --git a/packages/dl-center/src/download-center.ts b/packages/dl-center/src/download-center.ts index f70e416e..80f60c8c 100644 --- a/packages/dl-center/src/download-center.ts +++ b/packages/dl-center/src/download-center.ts @@ -52,6 +52,7 @@ export type S3BucketConfig = { export type UploadAssetOptions = { contentType?: string; + acl?: string; }; type S3UploadFunc = ( @@ -235,8 +236,10 @@ export class DownloadCenter { throw new Error('s3ObjectKey is required'); } + const acl = options.acl ?? ACL_PUBLIC_READ; + const uploadParams: S3.PutObjectRequest = { - ACL: ACL_PUBLIC_READ, + ACL: acl, Bucket: this.s3BucketName, Key: s3ObjectKey, Body: content,