Skip to content

Commit

Permalink
feat(publisher-s3): allow ACL omission (#3728)
Browse files Browse the repository at this point in the history
* feat(publisher-s3): allow ACL omission

This allows the caller to omit the ACL from the upload request, per
Amazon's recommendation of using bucket owner-enforced permissions.

* Update packages/publisher/s3/src/Config.ts

Updates the documentation for the `omitAcl` option per the pull request review

Co-authored-by: Felix Rieseberg <[email protected]>

---------

Co-authored-by: Felix Rieseberg <[email protected]>
  • Loading branch information
JHartman5 and felixrieseberg authored Nov 12, 2024
1 parent f947936 commit 2b6da59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/publisher/s3/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export interface PublisherS3Config {
* Default: false
*/
public?: boolean;
/**
* Whether to omit the ACL when creating the S3 object. If set, `public` will have no effect.
*
* Default: false
*/
omitAcl?: boolean;
/**
* The endpoint URI to send requests to.
*
Expand Down
17 changes: 10 additions & 7 deletions packages/publisher/s3/src/PublisherS3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';

import { S3Client } from '@aws-sdk/client-s3';
import { PutObjectCommandInput, S3Client } from '@aws-sdk/client-s3';
import { Progress, Upload } from '@aws-sdk/lib-storage';
import { Credentials } from '@aws-sdk/types';
import { PublisherOptions, PublisherStatic } from '@electron-forge/publisher-static';
Expand Down Expand Up @@ -59,15 +59,18 @@ export default class PublisherS3 extends PublisherStatic<PublisherS3Config> {
await Promise.all(
artifacts.map(async (artifact) => {
d('uploading:', artifact.path);
const params: PutObjectCommandInput = {
Body: fs.createReadStream(artifact.path),
Bucket: this.config.bucket,
Key: this.keyForArtifact(artifact),
};
if (!this.config.omitAcl) {
params.ACL = this.config.public ? 'public-read' : 'private';
}
const uploader = new Upload({
client: s3Client,
leavePartsOnError: true,
params: {
Body: fs.createReadStream(artifact.path),
Bucket: this.config.bucket,
Key: this.keyForArtifact(artifact),
ACL: this.config.public ? 'public-read' : 'private',
},
params,
});

uploader.on('httpUploadProgress', (progress: Progress) => {
Expand Down

0 comments on commit 2b6da59

Please sign in to comment.