Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

awscred

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awscred - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

92

index.js

@@ -6,2 +6,5 @@ var fs = require('fs'),

var TIMEOUT_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EHOSTUNREACH', 'Unknown system errno 64']
var httpCallbacks = []
exports.credentialsCallChain = [

@@ -144,6 +147,2 @@ loadCredentialsFromEnv,

var TIMEOUT_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EHOSTUNREACH', 'Unknown system errno 64']
var ec2Callbacks = []
var ecsCallbacks = []
function loadCredentialsFromHttp(options, cb) {

@@ -157,38 +156,20 @@ return process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI ?

ec2Callbacks.push(cb)
if (ec2Callbacks.length > 1) return // only want one caller at a time
cb = function(err, credentials) {
ec2Callbacks.forEach(function(cb) { cb(err, credentials) })
ec2Callbacks = []
}
if (options.timeout == null) options.timeout = 5000
options.host = '169.254.169.254'
options.path = '/latest/meta-data/iam/security-credentials/'
options.resolvePath = function(options, cb) {
options.path = '/latest/meta-data/iam/security-credentials/'
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))
options.path += data.split('\n')[0]
request(options, function(err, res, data) {
if (err) return cb(err)
try { data = JSON.parse(data) } catch (e) { }
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 || data.Code != 'Success')
return cb(new Error('Failed to fetch IAM credentials: ' + res.statusCode + ' ' + data))
if (res.statusCode != 200)
return cb(new Error('Failed to fetch IAM role: ' + res.statusCode + ' ' + data))
cb(null, {
accessKeyId: data.AccessKeyId,
secretAccessKey: data.SecretAccessKey,
sessionToken: data.Token,
expiration: new Date(data.Expiration),
})
cb(null, options.path + data.split('\n')[0])
})
})
}
requestCredentials(options, cb)
}

@@ -199,28 +180,45 @@

ecsCallbacks.push(cb)
if (ecsCallbacks.length > 1) return // only want one caller at a time
options.host = '169.254.170.2'
options.resolvePath = function(options, cb) {
cb(null, process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)
}
requestCredentials(options, cb)
}
function requestCredentials(options, cb) {
httpCallbacks.push(cb)
if (httpCallbacks.length > 1) return // only want one caller at a time
cb = function(err, credentials) {
ecsCallbacks.forEach(function(cb) { cb(err, credentials) })
ecsCallbacks = []
httpCallbacks.forEach(function(cb) { cb(err, credentials) })
httpCallbacks = []
}
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) {
options.resolvePath(options, function(err, path) {
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 credentials: ' + res.statusCode + ' ' + data))
options.path = path
try { data = JSON.parse(data) } catch (e) { }
request(options, function(err, res, data) {
if (err && ~TIMEOUT_CODES.indexOf(err.code)) return cb(null, {})
if (err) return cb(err)
cb(null, {
accessKeyId: data.AccessKeyId,
secretAccessKey: data.SecretAccessKey,
sessionToken: data.Token,
expiration: new Date(data.Expiration),
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)
return cb(new Error('Failed to fetch IAM credentials: ' + JSON.stringify(data)))
cb(null, {
accessKeyId: data.AccessKeyId,
secretAccessKey: data.SecretAccessKey,
sessionToken: data.Token,
expiration: new Date(data.Expiration),
})
})

@@ -227,0 +225,0 @@ })

{
"name": "awscred",
"version": "1.4.0",
"version": "1.4.1",
"description": "Resolves AWS credentials (and region) using env, file and IAM strategies",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc