Skip to content

Commit 50a6940

Browse files
authored
Merge pull request #2 from sarthakjdev/acl-setting-fix
fix: object acl setup permission for object writer issue fixed by enabling the public access.
2 parents a2660e0 + 7bb5894 commit 50a6940

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
.DS_Store
3+
.env

dist/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8479,6 +8479,15 @@ exports.default = (bucketName, uploadDirectory, environmentPrefix) => __awaiter(
84798479
]
84808480
}
84818481
}).promise();
8482+
yield s3Client_1.default.putPublicAccessBlock({
8483+
Bucket: bucketName,
8484+
PublicAccessBlockConfiguration: {
8485+
BlockPublicAcls: false,
8486+
BlockPublicPolicy: false,
8487+
IgnorePublicAcls: false,
8488+
RestrictPublicBuckets: false
8489+
}
8490+
}).promise();
84828491
console.log('Configuring bucket website...');
84838492
yield s3Client_1.default.putBucketWebsite({
84848493
Bucket: bucketName,
@@ -10121,6 +10130,7 @@ exports.default = (bucketName) => __awaiter(void 0, void 0, void 0, function* ()
1012110130
return true;
1012210131
}
1012310132
catch (e) {
10133+
console.log(e);
1012410134
return false;
1012510135
}
1012610136
});
@@ -10199,6 +10209,15 @@ exports.default = (bucketName, uploadDirectory, environmentPrefix) => __awaiter(
1019910209
]
1020010210
}
1020110211
}).promise();
10212+
yield s3Client_1.default.putPublicAccessBlock({
10213+
Bucket: bucketName,
10214+
PublicAccessBlockConfiguration: {
10215+
BlockPublicAcls: false,
10216+
BlockPublicPolicy: false,
10217+
IgnorePublicAcls: false,
10218+
RestrictPublicBuckets: false
10219+
}
10220+
}).promise();
1020210221
console.log('Configuring bucket website...');
1020310222
yield s3Client_1.default.putBucketWebsite({
1020410223
Bucket: bucketName,
@@ -26359,16 +26378,18 @@ exports.default = (bucketName, directory) => __awaiter(void 0, void 0, void 0, f
2635926378
try {
2636026379
const fileBuffer = yield fs_1.promises.readFile(filePath);
2636126380
const mimeType = mime_types_1.default.lookup(filePath) || 'application/octet-stream';
26362-
yield s3Client_1.default.putObject({
26381+
const response = yield s3Client_1.default.putObject({
2636326382
Bucket: bucketName,
2636426383
Key: s3Key,
2636526384
Body: fileBuffer,
2636626385
ACL: 'public-read',
2636726386
ServerSideEncryption: 'AES256',
2636826387
ContentType: mimeType
2636926388
}).promise();
26389+
console.log({ response });
2637026390
}
2637126391
catch (e) {
26392+
console.log(e);
2637226393
const message = `Failed to upload ${s3Key}: ${e.code} - ${e.message}`;
2637326394
console.log(message);
2637426395
throw message;

src/actions/prUpdatedAction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ export default async (bucketName: string, uploadDirectory: string, environmentPr
3636
}
3737
}).promise()
3838

39+
await S3.putPublicAccessBlock({
40+
Bucket: bucketName,
41+
PublicAccessBlockConfiguration: {
42+
BlockPublicAcls: false,
43+
BlockPublicPolicy: false,
44+
IgnorePublicAcls: false,
45+
RestrictPublicBuckets: false
46+
}
47+
}).promise()
48+
3949
console.log('Configuring bucket website...')
4050
await S3.putBucketWebsite({
4151
Bucket: bucketName,

src/actions/uploadAction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export default async (bucketName: string, uploadDirectory: string, environmentPr
3535
}
3636
}).promise()
3737

38+
await S3.putPublicAccessBlock({
39+
Bucket: bucketName,
40+
PublicAccessBlockConfiguration: {
41+
BlockPublicAcls: false,
42+
BlockPublicPolicy: false,
43+
IgnorePublicAcls: false,
44+
RestrictPublicBuckets: false
45+
}
46+
}).promise()
47+
3848
console.log('Configuring bucket website...')
3949
await S3.putBucketWebsite({
4050
Bucket: bucketName,

src/utils/checkBucketExists.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default async (bucketName: string) => {
55
await S3.headBucket({ Bucket: bucketName }).promise()
66
return true
77
} catch (e) {
8+
console.log(e)
89
return false
910
}
1011
}

src/utils/s3UploadDirectory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ export default async (bucketName: string, directory: string) => {
2020
const fileBuffer = await fs.readFile(filePath)
2121
const mimeType = mimeTypes.lookup(filePath) || 'application/octet-stream'
2222

23-
await S3.putObject({
23+
const response = await S3.putObject({
2424
Bucket: bucketName,
2525
Key: s3Key,
2626
Body: fileBuffer,
2727
ACL: 'public-read',
2828
ServerSideEncryption: 'AES256',
2929
ContentType: mimeType
3030
}).promise()
31+
32+
console.log({ response })
3133
} catch (e) {
34+
console.log(e)
3235
const message = `Failed to upload ${s3Key}: ${e.code} - ${e.message}`
3336
console.log(message)
3437
throw message

0 commit comments

Comments
 (0)