From f19a2d84a244ec2a919ece2747babb8b19a4278c Mon Sep 17 00:00:00 2001 From: gregory Date: Mon, 11 Mar 2019 12:55:06 -0700 Subject: [PATCH] address PR feedback --- bin/cmd.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 5f95125e..fef6b83d 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -15,17 +15,24 @@ const minimist = require('minimist'), default: { 'source': process.cwd() } }); }, - tokenCodeFn = function (mfaSerial, callback) { + tokenCodeFn = function (code) { 'use strict'; - const readline = require('readline').createInterface({ - input: process.stdin, - output: process.stdout - }); + return function (mfaSerial, callback) { - readline.question(`Please enter the code for MFA device ${mfaSerial}:`, (code) => { - readline.close(); - callback(null, code); - }); + if (code) { + return callback(null, String(code)); + } + const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout + }); + + readline.question(`Please enter the code for MFA device ${mfaSerial}:`, (value) => { + readline.close(); + return callback(null, String(value)); + }); + + }; }, main = function () { 'use strict'; @@ -76,7 +83,7 @@ const minimist = require('minimist'), SerialNumber, DurationSeconds: process.env.AWS_MFA_DURATION || args['mfa-duration'] || 3600 }); - Object.assign(TemporaryCredentialsParams, {tokenCodeFn}); + Object.assign(TemporaryCredentialsParams, {tokenCodeFn: tokenCodeFn(args['mfa-token'])}); } if (RoleArn) {