-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
28 lines (25 loc) · 964 Bytes
/
index.js
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
27
28
/**
* Credential check
* - aws-lite requires credentials to initialize
* - Architect needs credentials for some things (e.g. Deploy), but also has a variety of offline workflows that interface with AWS service API emulators (e.g. Sandbox)
* - Thus, sometimes it's ok to use dummy creds, but sometimes we need to halt (via this util)
*/
module.exports = function checkAwsCredentials (params, callback) {
let awsLite = require('@aws-lite/client')
let { inventory } = params
let promise
if (!callback) {
promise = new Promise((res, rej) => {
callback = (err, result) => err ? rej(err) : res(result)
})
}
let errMsg = 'Valid AWS credentials needed to continue; missing or invalid credentials'
awsLite({
// aws-lite falls back to AWS_PROFILE or 'default' if undefined
profile: inventory.inv?.aws?.profile,
region: 'us-west-1',
})
.then(() => callback())
.catch(() => callback(Error(errMsg)))
return promise
}