Skip to content

Commit 70139d3

Browse files
committed
Add aws account config --dump option
1 parent 60f8955 commit 70139d3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/bdcli/commands/account/bdcli-account-config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
updateConfig,
1010
profile,
1111
combineOptsWithSettings,
12+
dumpConfigProfile,
1213
} from "../../utils/config_util.js";
1314
import prompts from "prompts";
1415
import { getEmail } from "../../utils/auth_util.js";
@@ -27,6 +28,16 @@ async function show(options: any, _command: cmd.Command): Promise<void> {
2728
return;
2829
}
2930

31+
if (options.dump) {
32+
updateSpinnerText(`Dumping profile in ${BDCONF}: ${options.dump}`);
33+
const profileName = options.dump === true ? "default" : options.dump;
34+
const profile = await dumpConfigProfile(profileName, logger);
35+
if (!profile) return spinnerError(`Profile not found: ${profileName}`);
36+
spinnerSuccess();
37+
console.log(JSON.stringify(profile));
38+
return;
39+
}
40+
3041
if (options.clear) {
3142
updateSpinnerText(`Deleting session tokens from ${BDCONF}`);
3243
await updateConfig({
@@ -90,6 +101,7 @@ const program = new cmd.Command("bdcli account config")
90101
.addOption(new cmd.Option("--clear", "delete all session tokens (for opt. selected profile)"))
91102
.addOption(new cmd.Option("--region <awsRegion>", "Sign-in AWS region").default("eu-west-1"))
92103
.addOption(new cmd.Option("--list", `List all config profiles (see ${BDCONF})`))
104+
.addOption(new cmd.Option("--dump [profile]", `Dump selected config profile (see ${BDCONF})`))
93105
.action(async (options, command) => await show(options, command));
94106

95107
(async () => {

src/bdcli/utils/config_util.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ export async function listConfigProfiles(logger?: ILogger): Promise<string[]> {
6666
}
6767
}
6868

69+
export async function dumpConfigProfile(profile: string, logger?: ILogger): Promise<any> {
70+
logger?.debug({ profile });
71+
const config = <any>yaml.load(await fs.readFile(configFile, "utf8"));
72+
const dump = config?.credentials ? config : config?.[profile != "true" ? profile : "default"];
73+
if (!dump) return;
74+
return dump;
75+
}
76+
6977
export async function updateConfig(updates: IConfig, logger?: ILogger): Promise<void> {
7078
let config: any = {};
7179
try {

0 commit comments

Comments
 (0)