Skip to content

Commit

Permalink
Pass screen variable for the mfa modal. Make tokenFn anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
mansurpasha committed May 12, 2020
1 parent 85dd0ea commit 7bac9d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/CLIMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class Main {
}

init() {
const creds = getAWSCredentials(this.program.profile);
const creds = getAWSCredentials(this.program.profile, this.screen);

return creds
.getPromise()
Expand Down
12 changes: 3 additions & 9 deletions src/services/awsCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
});
Expand All @@ -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);
}
},
});
Expand Down

0 comments on commit 7bac9d1

Please sign in to comment.