Skip to content

Commit f1de7f2

Browse files
committed
Add comments to usage of tokenCodeFn for clarity
1 parent 0eee0e8 commit f1de7f2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/services/awsCredentials.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ import AWS from "aws-sdk";
33
import { promptMfaModal } from "../modals";
44

55
function getAWSCredentials(profile, program, screen) {
6-
let codeFn;
6+
// Define tokenCodeFn for SharedIniFileCredentials:
7+
// Arguments:
8+
// serial - mfa device serial, not used as code is supplied manually
9+
// callback - callback function which takes (err, token) as arguments. Here err isn't used as token is entered manually
10+
let mfaCodeFn;
711
if (program.mfa) {
8-
codeFn = (serial, callback) => callback(null, program.mfa);
12+
// If mfa token defined in cli options, supply to callback and run immediately
13+
mfaCodeFn = (serial, callback) => callback(null, program.mfa);
914
} else if (screen) {
10-
codeFn = (serial, callback) => promptMfaModal(callback, screen);
15+
// promptMfaModal allows user to enter token on screen, and runs callback on entry
16+
mfaCodeFn = (serial, callback) => promptMfaModal(callback, screen);
1117
} else {
12-
codeFn = () =>
18+
// If using Guardian and --mfa not supplied
19+
mfaCodeFn = () =>
1320
console.error(
1421
"In-tool mfa authentication isn't supported for guardian. Please provide your mfa token via the --mfa option"
1522
);
@@ -19,7 +26,7 @@ function getAWSCredentials(profile, program, screen) {
1926
process.env.AWS_SDK_LOAD_CONFIG = 1;
2027
return new AWS.SharedIniFileCredentials({
2128
profile,
22-
tokenCodeFn: codeFn,
29+
tokenCodeFn: mfaCodeFn,
2330
callback: (err) => {
2431
if (err) {
2532
console.error(`SharedIniFileCreds Error: ${err}`);
@@ -37,7 +44,7 @@ function getAWSCredentials(profile, program, screen) {
3744
if (process.env.AWS_PROFILE) {
3845
return new AWS.SharedIniFileCredentials({
3946
profile: process.env.AWS_PROFILE,
40-
tokenCodeFn: codeFn,
47+
tokenCodeFn: mfaCodeFn,
4148
callback: (err) => {
4249
if (err) {
4350
console.error(`SharedIniFileCreds Error: ${err}`);

0 commit comments

Comments
 (0)