Comparing version 0.8.0 to 0.9.0
@@ -12,8 +12,8 @@ /*jslint node: true */ | ||
var ALKS_DURATIONS = [ 2, 6, 12, 18 ], // reducing due to EB not honoring long sessions: , 24, 36 ], | ||
AWS_SIGNIN_URL = 'https://signin.aws.amazon.com/federation', | ||
AWS_CONSOLE_URL = 'https://console.aws.amazon.com/', | ||
SANITIZE_FIELDS = [ 'password', 'refreshToken', 'accessToken', 'accessKey', 'secretKey', 'sessionToken' ], | ||
DEFAULT_UA = 'alks-node', | ||
STATUS_SUCCESS = 'success'; | ||
var ALKS_MAX_DURATION = 18, // reducing due to EB not honoring long sessions: , 24, 36 ], | ||
AWS_SIGNIN_URL = 'https://signin.aws.amazon.com/federation', | ||
AWS_CONSOLE_URL = 'https://console.aws.amazon.com/', | ||
SANITIZE_FIELDS = [ 'password', 'refreshToken', 'accessToken', 'accessKey', 'secretKey', 'sessionToken' ], | ||
DEFAULT_UA = 'alks-node', | ||
STATUS_SUCCESS = 'success'; | ||
@@ -72,4 +72,39 @@ var getMessageFromBadResponse = function(results){ | ||
exports.getDurations = function(){ | ||
return ALKS_DURATIONS; | ||
exports.getDurations = function(account, auth, opts, callback){ | ||
if (arguments.length == 0) return [1]; // for legacy support | ||
var headers = { 'User-Agent': options.ua }; | ||
var options = _.extend({ | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts); | ||
var accountId = account.alksAccount.substring(0,12); | ||
var endpoint = account.server + '/loginRoles/id/' + accountId + '/' + account.alksRole; | ||
injectAuth(null, headers, auth, options, function(err){ | ||
if(err) return callback(err); | ||
log('api:getDurations', 'getting max key duration: ' + endpoint, options); | ||
request({ | ||
url: endpoint, | ||
method: 'GET', | ||
headers: headers | ||
}, function(err, results) { | ||
if(err){ | ||
return callback(err); | ||
} | ||
else if(results.statusCode !== 200){ | ||
return callback(new Error(getMessageFromBadResponse(results))); | ||
} | ||
else if(results.body.statusMessage.toLowerCase() !== STATUS_SUCCESS){ | ||
return callback(new Error(results.body.statusMessage)); | ||
} | ||
var maxKeyDuration = Math.min(ALKS_MAX_DURATION, results.body.loginRole.maxKeyDuration); | ||
var durations = []; | ||
for(var i=1; i<=maxKeyDuration; i++) durations.push(i); | ||
callback(null, durations); | ||
}); | ||
}); | ||
}; | ||
@@ -126,5 +161,10 @@ | ||
exports.createIamKey = function(account, auth, opts, callback){ | ||
exports.createIamKey = function(account, auth, duration, opts, callback){ | ||
if(arguments.length < 5){ // for legacy calls to createIamKey | ||
callback = opts; | ||
opts = duration; | ||
duration = 1; | ||
} | ||
var payload = _.extend({ | ||
sessionTime: 1, | ||
sessionTime: duration, | ||
account: account.alksAccount, | ||
@@ -131,0 +171,0 @@ role: account.alksRole |
{ | ||
"name": "alks-node", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Node client for ALKS", | ||
@@ -5,0 +5,0 @@ "main": "lib/alks-api.js", |
28182
556