-
Notifications
You must be signed in to change notification settings - Fork 21
/
whoami.js
47 lines (37 loc) · 1.29 KB
/
whoami.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const _ = require("lodash");
const { Command } = require("@oclif/command");
const { getProfiles } = require("../lib/aws-profile-utils");
const { track } = require("../lib/analytics");
class WhoamiCommand extends Command {
async run() {
track("whoami", {});
const { sharedCred, config } = getProfiles();
if (!sharedCred.default) {
this.log("No default profile set.");
this.exit();
}
const sharedCredProfileNames = Object.keys(sharedCred).filter(
x => x !== "default"
);
const configProfileNames = Object.keys(config);
if (_.isEmpty(sharedCredProfileNames) && _.isEmpty(configProfileNames)) {
this.log("You don't have any named profiles set up");
this.log(
"Run 'aws configure --profile profile-name' to set up named profiles"
);
this.exit();
}
const currentProfile = _.uniq([
...sharedCredProfileNames,
...configProfileNames
]).find(name => _.isEqual(sharedCred[name] || config[name], sharedCred.default));
if (!currentProfile) {
this.log("It appears you are not using any of the named profiles");
this.log("Run 'lumigo-cli switch-profile' to switch to a named profile");
this.exit();
}
this.log(`You are logged in as [${currentProfile}]`);
}
}
WhoamiCommand.description = "See your current AWS profile name";
module.exports = WhoamiCommand;