Comparing version 1.4.2 to 1.5.0
90
index.js
@@ -1,5 +0,5 @@ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
http = require('http'), | ||
env = process.env | ||
var fs = require('fs') | ||
var path = require('path') | ||
var http = require('http') | ||
var env = process.env | ||
@@ -41,3 +41,4 @@ var TIMEOUT_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EHOSTUNREACH', 'Unknown system errno 64'] | ||
var out = {}, callsRemaining = 2 | ||
var out = {} | ||
var callsRemaining = 2 | ||
@@ -65,7 +66,9 @@ function checkDone(propName) { | ||
if (credentials.accessKeyId && credentials.secretAccessKey) | ||
if (credentials.accessKeyId && credentials.secretAccessKey) { | ||
return cb(null, credentials) | ||
} | ||
if (i >= credentialsCallChain.length - 1) | ||
if (i >= credentialsCallChain.length - 1) { | ||
return cb(null, {}) | ||
} | ||
@@ -86,7 +89,9 @@ nextCall(i + 1) | ||
if (region) | ||
if (region) { | ||
return cb(null, region) | ||
} | ||
if (i >= regionCallChain.length - 1) | ||
if (i >= regionCallChain.length - 1) { | ||
return cb(null, 'us-east-1') | ||
} | ||
@@ -128,6 +133,16 @@ nextCall(i + 1) | ||
if (err) return cb(err) | ||
cb(null, { | ||
accessKeyId: profile.aws_access_key_id, | ||
secretAccessKey: profile.aws_secret_access_key, | ||
sessionToken: profile.aws_session_token, | ||
if (profile.aws_access_key_id) { | ||
return cb(null, { | ||
accessKeyId: profile.aws_access_key_id, | ||
secretAccessKey: profile.aws_secret_access_key, | ||
sessionToken: profile.aws_session_token, | ||
}) | ||
} | ||
loadProfileFromIniFile(options, 'config', function(err, profile) { | ||
if (err) return cb(err) | ||
cb(null, { | ||
accessKeyId: profile.aws_access_key_id, | ||
secretAccessKey: profile.aws_secret_access_key, | ||
sessionToken: profile.aws_session_token, | ||
}) | ||
}) | ||
@@ -140,5 +155,9 @@ }) | ||
loadProfileFromIniFile(options, 'config', function(err, profile) { | ||
loadProfileFromIniFile(options, 'credentials', function(err, profile) { | ||
if (err) return cb(err) | ||
cb(null, profile.region) | ||
if (profile.region) return cb(null, profile.region) | ||
loadProfileFromIniFile(options, 'config', function(err, profile) { | ||
if (err) return cb(err) | ||
cb(null, profile.region) | ||
}) | ||
}) | ||
@@ -148,3 +167,4 @@ } | ||
function loadRegionFromIniFileSync(options) { | ||
return loadProfileFromIniFileSync(options || {}, 'config').region | ||
return loadProfileFromIniFileSync(options || {}, 'credentials').region || | ||
loadProfileFromIniFileSync(options || {}, 'config').region | ||
} | ||
@@ -167,7 +187,9 @@ | ||
if (res.statusCode == 404) | ||
if (res.statusCode === 404) { | ||
return cb(new Error('Could not find IAM role. Check that you assigned an IAM role to your EC2 instance')) | ||
} | ||
if (res.statusCode != 200) | ||
if (res.statusCode !== 200) { | ||
return cb(new Error('Failed to fetch IAM role: ' + res.statusCode + ' ' + data)) | ||
} | ||
@@ -213,9 +235,11 @@ cb(null, options.path + data.split('\n')[0]) | ||
if (res.statusCode != 200) | ||
if (res.statusCode !== 200) { | ||
return cb(new Error('Failed to fetch IAM credentials: ' + res.statusCode + ' ' + data)) | ||
} | ||
try { data = JSON.parse(data) } catch (e) { } | ||
if (!data.AccessKeyId) | ||
if (!data.AccessKeyId) { | ||
return cb(new Error('Failed to fetch IAM credentials: ' + JSON.stringify(data))) | ||
} | ||
@@ -233,7 +257,7 @@ cb(null, { | ||
function loadProfileFromIniFile(options, defaultFilename, cb) { | ||
var filename = options.filename || path.join(resolveHome(), '.aws', defaultFilename), | ||
profile = options.profile || resolveProfile() | ||
var filename = options.filename || path.join(resolveHome(), '.aws', defaultFilename) | ||
var profile = options.profile || resolveProfile() | ||
fs.readFile(filename, 'utf8', function(err, data) { | ||
if (err && err.code == 'ENOENT') return cb(null, {}) | ||
if (err && err.code === 'ENOENT') return cb(null, {}) | ||
if (err) return cb(err) | ||
@@ -246,5 +270,5 @@ var parsedIni = parseAwsIni(data) | ||
function loadProfileFromIniFileSync(options, defaultFilename) { | ||
var filename = options.filename || path.join(resolveHome(), '.aws', defaultFilename), | ||
profile = options.profile || resolveProfile(), | ||
data | ||
var filename = options.filename || path.join(resolveHome(), '.aws', defaultFilename) | ||
var profile = options.profile || resolveProfile() | ||
var data | ||
@@ -254,3 +278,3 @@ try { | ||
} catch (err) { | ||
if (err.code == 'ENOENT') return {} | ||
if (err.code === 'ENOENT') return {} | ||
throw err | ||
@@ -273,5 +297,5 @@ } | ||
} else if (needRegion) { | ||
return loadRegion(options, function(err, region) { cb(err, {region: region}) }) | ||
return loadRegion(options, function(err, region) { cb(err, { region: region }) }) | ||
} else if (needCreds) { | ||
return loadCredentials(options, function(err, credentials) { cb(err, {credentials: credentials}) }) | ||
return loadCredentials(options, function(err, credentials) { cb(err, { credentials: credentials }) }) | ||
} | ||
@@ -309,6 +333,6 @@ cb(null, {}) | ||
function parseAwsIni(ini) { | ||
var section, | ||
out = Object.create(null), | ||
re = /^\[([^\]]+)\]\s*$|^([a-z_]+)\s*=\s*(.+?)\s*$/, | ||
lines = ini.split(/\r?\n/) | ||
var section | ||
var out = Object.create(null) | ||
var re = /^\[([^\]]+)\]\s*$|^([a-z_]+)\s*=\s*(.+?)\s*$/ | ||
var lines = ini.split(/\r?\n/) | ||
@@ -315,0 +339,0 @@ lines.forEach(function(line) { |
{ | ||
"name": "awscred", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Resolves AWS credentials (and region) using env, file and IAM strategies", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
15955
294