Comparing version 1.2.0 to 1.3.0
38
index.js
@@ -10,2 +10,3 @@ var fs = require('fs'), | ||
loadCredentialsFromEc2Metadata, | ||
loadCredentialsFromEcs, | ||
] | ||
@@ -144,3 +145,40 @@ | ||
var ec2Callbacks = [] | ||
var ecsCallbacks = [] | ||
function loadCredentialsFromEcs(options, cb) { | ||
if (!cb) { cb = options; options = {} } | ||
ecsCallbacks.push(cb) | ||
if (ecsCallbacks.length > 1) return // only want one caller at a time | ||
cb = function(err, credentials) { | ||
ecsCallbacks.forEach(function(cb) { cb(err, credentials) }) | ||
ecsCallbacks = [] | ||
} | ||
if (options.timeout == null) options.timeout = 5000 | ||
options.host = '169.254.170.2' | ||
options.path = process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | ||
return request(options, function(err, res, data) { | ||
if (err && ~TIMEOUT_CODES.indexOf(err.code)) return cb(null, {}) | ||
if (err) return cb(err) | ||
if (res.statusCode != 200) | ||
return cb(new Error('Failed to fetch IAM role: ' + res.statusCode + ' ' + data)) | ||
try { data = JSON.parse(data) } catch (e) { } | ||
if (res.statusCode != 200) | ||
return cb(new Error('Failed to fetch IAM credentials: ' + res.statusCode + ' ' + data)) | ||
cb(null, { | ||
accessKeyId: data.AccessKeyId, | ||
secretAccessKey: data.SecretAccessKey, | ||
sessionToken: data.Token, | ||
expiration: new Date(data.Expiration), | ||
}) | ||
}) | ||
} | ||
function loadCredentialsFromEc2Metadata(options, cb) { | ||
@@ -147,0 +185,0 @@ if (!cb) { cb = options; options = {} } |
{ | ||
"name": "awscred", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Resolves AWS credentials (and region) using env, file and IAM strategies", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -49,3 +49,3 @@ awscred | ||
- `filename`: the name of the INI file to parse, defaults to `'~/.aws/config'` | ||
- `filename`: the name of the INI file to parse, defaults to `'~/.aws/credentials'` for credentials and `'~/.aws/config'` for region | ||
- `profile`: the name of the INI profile to use, defaults to `'default'` | ||
@@ -52,0 +52,0 @@ - `timeout`: the ms timeout on the http call to the EC2 metadata service, defaults to `5000` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14496
269
4
4