forked from elasticio/aws-s3-component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifyCredentials.ts
More file actions
27 lines (24 loc) · 1.09 KB
/
Copy pathverifyCredentials.ts
File metadata and controls
27 lines (24 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { AwsS3Client, Credentials } from './lib/AwsS3Client';
export = async function verifyCredentials(cfg: Credentials): Promise<{ verified: boolean }> {
this.logger.info('Verification started');
const { accessKeyId, accessKeySecret: secretAccessKey, region } = cfg;
if (!accessKeyId || !secretAccessKey || !region) {
const errMessage = 'Parameters accessKeyId, secretAccessKey and region are required';
this.logger.error(errMessage);
throw new Error(errMessage);
}
const client = new AwsS3Client(this, cfg);
try {
const bucketsNames = await client.listBucketNames();
if (bucketsNames.length < 1) {
this.logger.info('API keys are valid but they don\'t have permission to manipulate any existing buckets.');
} else {
this.logger.info('The provided API keys have access the buckets');
}
} catch (e) {
this.logger.error(`Verification failed: ${e?.message || 'Unknown error'}`);
return { verified: false };
}
this.logger.info('Verification succeeded');
return { verified: true };
}