From 7bac9d1cae698f4c6103ce8f70ff3f1857aa02bc Mon Sep 17 00:00:00 2001 From: mansurpasha Date: Tue, 12 May 2020 12:57:16 +0100 Subject: [PATCH] Pass screen variable for the mfa modal. Make tokenFn anonymous --- src/CLIMain.js | 2 +- src/services/awsCredentials.js | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/CLIMain.js b/src/CLIMain.js index d6b9994a..8e632964 100644 --- a/src/CLIMain.js +++ b/src/CLIMain.js @@ -188,7 +188,7 @@ class Main { } init() { - const creds = getAWSCredentials(this.program.profile); + const creds = getAWSCredentials(this.program.profile, this.screen); return creds .getPromise() diff --git a/src/services/awsCredentials.js b/src/services/awsCredentials.js index 4b6699e0..a3db138c 100644 --- a/src/services/awsCredentials.js +++ b/src/services/awsCredentials.js @@ -2,20 +2,15 @@ import AWS from "aws-sdk"; import { promptMfaModal } from "../modals"; -function getMfaToken(serial, callback) { - promptMfaModal(callback, this.screen); -} - -function getAWSCredentials(profile) { +function getAWSCredentials(profile, screen) { if (profile) { process.env.AWS_SDK_LOAD_CONFIG = 1; return new AWS.SharedIniFileCredentials({ profile, - tokenCodeFn: getMfaToken, + tokenCodeFn: (serial, callback) => promptMfaModal(callback, screen), callback: (err) => { if (err) { console.error(`SharedIniFileCreds Error: ${err}`); - process.exit(0); } }, }); @@ -30,11 +25,10 @@ function getAWSCredentials(profile) { if (process.env.AWS_PROFILE) { return new AWS.SharedIniFileCredentials({ profile: process.env.AWS_PROFILE, - tokenCodeFn: getMfaToken, + tokenCodeFn: (serial, callback) => promptMfaModal(callback, screen), callback: (err) => { if (err) { console.error(`SharedIniFileCreds Error: ${err}`); - process.exit(0); } }, });