Skip to content

Commit

Permalink
fix missing tokenCodeFn
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory committed Mar 10, 2019
1 parent 7dea659 commit 9d4d5a9
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@ const minimist = require('minimist'),
default: { 'source': process.cwd() }
});
},
tokenCodeFn = function (mfaSerial, callback) {
'use strict';
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});

readline.question(`Please enter the code for MFA device ${mfaSerial}:`, (code) => {
readline.close();
callback(null, code);
});
},
main = function () {
'use strict';
const args = readArgs(),
commands = readCommands(),
command = args._ && args._.length && args._[0],
logger = (!args.quiet) && new ConsoleLogger();
logger = (!args.quiet) && new ConsoleLogger(),
RoleArn = process.env.AWS_ROLE_ARN || args['sts-role-arn'],
SerialNumber = process.env.AWS_MFA_SERIAL || args['mfa-serial'],
TemporaryCredentialsParams = { params: {RoleArn}};
if (args.version && !command) {
console.log(require(path.join(__dirname, '..', 'package.json')).version);
return;
Expand Down Expand Up @@ -50,10 +65,28 @@ const minimist = require('minimist'),
AWS.config.httpOptions = AWS.config.httpOptions || {};
AWS.config.httpOptions.timeout = args['aws-client-timeout'];
}

if (args.proxy) {
AWS.config.httpOptions = AWS.config.httpOptions || {};
AWS.config.httpOptions.agent = new HttpsProxyAgent(args.proxy);
}

if (SerialNumber) {
Object.assign(TemporaryCredentialsParams.params, {
SerialNumber,
DurationSeconds: process.env.AWS_MFA_DURATION || args['mfa-duration'] || 3600
});
Object.assign(TemporaryCredentialsParams, {tokenCodeFn});
}

if (RoleArn) {
console.log(`Assuming Role ${RoleArn}`);
Object.assign(TemporaryCredentialsParams.params, {RoleArn});
}

if (SerialNumber || RoleArn) {
AWS.config.credentials = new AWS.ChainableTemporaryCredentials(TemporaryCredentialsParams);
}
commands[command](args, logger).then(result => {
if (result && !args.quiet) {
console.log(JSON.stringify(result, null, 2));
Expand Down

0 comments on commit 9d4d5a9

Please sign in to comment.