Skip to content

Commit

Permalink
Merge pull request #2 from sarthakjdev/acl-setting-fix
Browse files Browse the repository at this point in the history
fix: object acl setup permission for object writer  issue fixed by enabling the public access.
  • Loading branch information
rishabhrao committed May 7, 2023
2 parents a2660e0 + 7bb5894 commit 50a6940
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.env
23 changes: 22 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8479,6 +8479,15 @@ exports.default = (bucketName, uploadDirectory, environmentPrefix) => __awaiter(
]
}
}).promise();
yield s3Client_1.default.putPublicAccessBlock({
Bucket: bucketName,
PublicAccessBlockConfiguration: {
BlockPublicAcls: false,
BlockPublicPolicy: false,
IgnorePublicAcls: false,
RestrictPublicBuckets: false
}
}).promise();
console.log('Configuring bucket website...');
yield s3Client_1.default.putBucketWebsite({
Bucket: bucketName,
Expand Down Expand Up @@ -10121,6 +10130,7 @@ exports.default = (bucketName) => __awaiter(void 0, void 0, void 0, function* ()
return true;
}
catch (e) {
console.log(e);
return false;
}
});
Expand Down Expand Up @@ -10199,6 +10209,15 @@ exports.default = (bucketName, uploadDirectory, environmentPrefix) => __awaiter(
]
}
}).promise();
yield s3Client_1.default.putPublicAccessBlock({
Bucket: bucketName,
PublicAccessBlockConfiguration: {
BlockPublicAcls: false,
BlockPublicPolicy: false,
IgnorePublicAcls: false,
RestrictPublicBuckets: false
}
}).promise();
console.log('Configuring bucket website...');
yield s3Client_1.default.putBucketWebsite({
Bucket: bucketName,
Expand Down Expand Up @@ -26359,16 +26378,18 @@ exports.default = (bucketName, directory) => __awaiter(void 0, void 0, void 0, f
try {
const fileBuffer = yield fs_1.promises.readFile(filePath);
const mimeType = mime_types_1.default.lookup(filePath) || 'application/octet-stream';
yield s3Client_1.default.putObject({
const response = yield s3Client_1.default.putObject({
Bucket: bucketName,
Key: s3Key,
Body: fileBuffer,
ACL: 'public-read',
ServerSideEncryption: 'AES256',
ContentType: mimeType
}).promise();
console.log({ response });
}
catch (e) {
console.log(e);
const message = `Failed to upload ${s3Key}: ${e.code} - ${e.message}`;
console.log(message);
throw message;
Expand Down
10 changes: 10 additions & 0 deletions src/actions/prUpdatedAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ export default async (bucketName: string, uploadDirectory: string, environmentPr
}
}).promise()

await S3.putPublicAccessBlock({
Bucket: bucketName,
PublicAccessBlockConfiguration: {
BlockPublicAcls: false,
BlockPublicPolicy: false,
IgnorePublicAcls: false,
RestrictPublicBuckets: false
}
}).promise()

console.log('Configuring bucket website...')
await S3.putBucketWebsite({
Bucket: bucketName,
Expand Down
10 changes: 10 additions & 0 deletions src/actions/uploadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export default async (bucketName: string, uploadDirectory: string, environmentPr
}
}).promise()

await S3.putPublicAccessBlock({
Bucket: bucketName,
PublicAccessBlockConfiguration: {
BlockPublicAcls: false,
BlockPublicPolicy: false,
IgnorePublicAcls: false,
RestrictPublicBuckets: false
}
}).promise()

console.log('Configuring bucket website...')
await S3.putBucketWebsite({
Bucket: bucketName,
Expand Down
1 change: 1 addition & 0 deletions src/utils/checkBucketExists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default async (bucketName: string) => {
await S3.headBucket({ Bucket: bucketName }).promise()
return true
} catch (e) {
console.log(e)
return false
}
}
5 changes: 4 additions & 1 deletion src/utils/s3UploadDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export default async (bucketName: string, directory: string) => {
const fileBuffer = await fs.readFile(filePath)
const mimeType = mimeTypes.lookup(filePath) || 'application/octet-stream'

await S3.putObject({
const response = await S3.putObject({
Bucket: bucketName,
Key: s3Key,
Body: fileBuffer,
ACL: 'public-read',
ServerSideEncryption: 'AES256',
ContentType: mimeType
}).promise()

console.log({ response })
} catch (e) {
console.log(e)
const message = `Failed to upload ${s3Key}: ${e.code} - ${e.message}`
console.log(message)
throw message
Expand Down

0 comments on commit 50a6940

Please sign in to comment.