Comparing version 0.2.1 to 0.3.1
@@ -13,3 +13,5 @@ /*jslint node: true */ | ||
AWS_SIGNIN_URL = 'https://signin.aws.amazon.com/federation', | ||
AWS_CONSOLE_URL = 'https://console.aws.amazon.com/'; | ||
AWS_CONSOLE_URL = 'https://console.aws.amazon.com/', | ||
SANITIZE_FIELDS = [ 'password' ], | ||
DEFAULT_UA = 'alks-node'; | ||
@@ -34,3 +36,18 @@ exports.getDurations = function(){ | ||
exports.createKey = function(account, password, duration, callback){ | ||
var log = function(section, msg, options){ | ||
if(options.debug){ | ||
console.error([ '[', section, ']: ', msg ].join('')); | ||
} | ||
} | ||
var sanitizeData = function(data){ | ||
var cleansed = {}; | ||
_.each(data, function(val, field){ | ||
cleansed[field] = _.contains(SANITIZE_FIELDS, field) ? '********' : val; | ||
}); | ||
return cleansed; | ||
} | ||
exports.createKey = function(account, password, duration, opts, callback){ | ||
var payload = _.extend({ | ||
@@ -41,8 +58,19 @@ password: password, | ||
role: account.alksRole | ||
}, account); | ||
}, account), | ||
options = _.extend({ | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts), | ||
endpoint = account.server + '/getKeys/'; | ||
log('api:createKey', 'creating key at endpoint: ' + endpoint, options); | ||
log('api:createKey', 'with data: ' + JSON.stringify(sanitizeData(payload), null, 4), options); | ||
request({ | ||
url: account.server + '/getKeys/', | ||
url: endpoint, | ||
method: 'POST', | ||
json: payload | ||
json: payload, | ||
headers: { | ||
'User-Agent': options.ua | ||
} | ||
}, function(err, results){ | ||
@@ -68,3 +96,3 @@ if(err){ | ||
exports.createIamKey = function(account, password, callback){ | ||
exports.createIamKey = function(account, password, opts, callback){ | ||
var payload = _.extend({ | ||
@@ -75,8 +103,19 @@ password: password, | ||
role: account.alksRole | ||
}, account); | ||
}, account), | ||
options = _.extend({ | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts), | ||
endpoint = account.server + '/getIAMKeys/'; | ||
log('api:createIamKey', 'creating IAM key at endpoint: ' + endpoint, options); | ||
log('api:createIamKey', 'with data: ' + JSON.stringify(sanitizeData(payload), null, 4), options); | ||
request({ | ||
url: account.server + '/getIAMKeys/', | ||
url: endpoint, | ||
method: 'POST', | ||
json: payload | ||
json: payload, | ||
headers: { | ||
'User-Agent': options.ua | ||
} | ||
}, function(err, results){ | ||
@@ -102,3 +141,3 @@ if(err){ | ||
exports.createIamRole = function(account, password, roleName, roleType, includeDefaultPolicies, callback){ | ||
exports.createIamRole = function(account, password, roleName, roleType, includeDefaultPolicies, opts, callback){ | ||
var payload = _.extend({ | ||
@@ -111,8 +150,19 @@ password: password, | ||
includeDefaultPolicy: includeDefaultPolicies ? '1' : '0' | ||
}, account); | ||
}, account), | ||
options = _.extend({ | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts), | ||
endpoint = account.server + '/createRole/'; | ||
log('api:createIamRole', 'creating IAM role at endpoint: ' + endpoint, options); | ||
log('api:createIamRole', 'with data: ' + JSON.stringify(sanitizeData(payload), null, 4), options); | ||
request({ | ||
url: account.server + '/createRole/', | ||
url: endpoint, | ||
method: 'POST', | ||
json: payload | ||
json: payload, | ||
headers: { | ||
'User-Agent': options.ua | ||
} | ||
}, function(err, results){ | ||
@@ -135,11 +185,21 @@ if(err){ | ||
exports.getAccounts = function(server, userid, password, options, callback){ | ||
var opts = _.extend({ | ||
filters: {} | ||
}, options); | ||
exports.getAccounts = function(server, userid, password, opts, callback){ | ||
var payload = { userid: userid, password: password }, | ||
options = _.extend({ | ||
filters: {}, | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts), | ||
endpoint = server + '/getAccounts/'; | ||
log('api:getAccounts', 'getting accounts at endpoint: ' + endpoint, options); | ||
log('api:getAccounts', 'with data: ' + JSON.stringify(sanitizeData(payload), null, 4), options); | ||
request({ | ||
url: server + '/getAccounts/', | ||
url: endpoint, | ||
method: 'POST', | ||
json: { userid: userid, password: password } | ||
json: payload, | ||
headers: { | ||
'User-Agent': options.ua | ||
} | ||
}, function(err, results){ | ||
@@ -159,4 +219,4 @@ if(err){ | ||
_.each(results.body.accountListRole, function(role, acct){ | ||
if((opts.filters.iamOnly && !role[0].iamKeyActive) | ||
|| (!opts.filters.iamOnly && role[0].iamKeyActive)){ | ||
if((options.filters.iamOnly && !role[0].iamKeyActive) | ||
|| (!options.filters.iamOnly && role[0].iamKeyActive)){ | ||
return; | ||
@@ -185,7 +245,20 @@ } | ||
exports.getIamRoleTypes = function(server, userid, password, callback){ | ||
exports.getIamRoleTypes = function(server, userid, password, opts, callback){ | ||
var payload = { userid: userid, password: password }, | ||
options = _.extend({ | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts), | ||
endpoint = server + '/getAWSRoleTypes/'; | ||
log('api:getIamRoleTypes', 'getting role types at endpoint: ' + endpoint, options); | ||
log('api:getIamRoleTypes', 'with data: ' + JSON.stringify(sanitizeData(payload), null, 4), options); | ||
request({ | ||
url: server + '/getAWSRoleTypes/', | ||
url: endpoint, | ||
method: 'POST', | ||
json: { userid: userid, password: password } | ||
json: payload, | ||
headers: { | ||
'User-Agent': options.ua | ||
} | ||
}, function(err, results){ | ||
@@ -203,3 +276,3 @@ if(err){ | ||
exports.generateConsoleUrl = function(key, callback){ | ||
exports.generateConsoleUrl = function(key, opts, callback){ | ||
var payload = { | ||
@@ -209,9 +282,20 @@ sessionId: key.accessKey, | ||
sessionToken: key.sessionToken | ||
}; | ||
}, | ||
options = _.extend({ | ||
debug: false, | ||
ua: DEFAULT_UA | ||
}, opts); | ||
var urlParms = '?Action=getSigninToken&SessionType=json&Session=' + encodeURIComponent(JSON.stringify(payload)); | ||
var urlParms = '?Action=getSigninToken&SessionType=json&Session=' + encodeURIComponent(JSON.stringify(payload)), | ||
endpoint = AWS_SIGNIN_URL + urlParms; | ||
log('api:generateConsoleUrl', 'generating console url at endpoint: ' + endpoint, options); | ||
log('api:generateConsoleUrl', 'with data: ' + JSON.stringify(sanitizeData(payload), null, 4), options); | ||
log('ua', options.ua, options) | ||
request({ | ||
url: AWS_SIGNIN_URL + urlParms, | ||
method: 'GET' | ||
url: endpoint, | ||
method: 'GET', | ||
headers: { | ||
'User-Agent': options.ua | ||
} | ||
}, function(err, results){ | ||
@@ -218,0 +302,0 @@ if(err){ |
{ | ||
"name": "alks-node", | ||
"version": "0.2.1", | ||
"version": "0.3.1", | ||
"description": "Node client for ALKS", | ||
@@ -5,0 +5,0 @@ "main": "lib/alks-api.js", |
15511
284