Skip to content

Commit

Permalink
Add aws account config --dump option
Browse files Browse the repository at this point in the history
  • Loading branch information
dforsber committed Apr 5, 2024
1 parent 60f8955 commit 70139d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bdcli/commands/account/bdcli-account-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
updateConfig,
profile,
combineOptsWithSettings,
dumpConfigProfile,
} from "../../utils/config_util.js";
import prompts from "prompts";
import { getEmail } from "../../utils/auth_util.js";
Expand All @@ -27,6 +28,16 @@ async function show(options: any, _command: cmd.Command): Promise<void> {
return;
}

if (options.dump) {
updateSpinnerText(`Dumping profile in ${BDCONF}: ${options.dump}`);
const profileName = options.dump === true ? "default" : options.dump;
const profile = await dumpConfigProfile(profileName, logger);
if (!profile) return spinnerError(`Profile not found: ${profileName}`);
spinnerSuccess();
console.log(JSON.stringify(profile));
return;
}

if (options.clear) {
updateSpinnerText(`Deleting session tokens from ${BDCONF}`);
await updateConfig({
Expand Down Expand Up @@ -90,6 +101,7 @@ const program = new cmd.Command("bdcli account config")
.addOption(new cmd.Option("--clear", "delete all session tokens (for opt. selected profile)"))
.addOption(new cmd.Option("--region <awsRegion>", "Sign-in AWS region").default("eu-west-1"))
.addOption(new cmd.Option("--list", `List all config profiles (see ${BDCONF})`))
.addOption(new cmd.Option("--dump [profile]", `Dump selected config profile (see ${BDCONF})`))
.action(async (options, command) => await show(options, command));

(async () => {
Expand Down
8 changes: 8 additions & 0 deletions src/bdcli/utils/config_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export async function listConfigProfiles(logger?: ILogger): Promise<string[]> {
}
}

export async function dumpConfigProfile(profile: string, logger?: ILogger): Promise<any> {
logger?.debug({ profile });
const config = <any>yaml.load(await fs.readFile(configFile, "utf8"));
const dump = config?.credentials ? config : config?.[profile != "true" ? profile : "default"];
if (!dump) return;
return dump;
}

export async function updateConfig(updates: IConfig, logger?: ILogger): Promise<void> {
let config: any = {};
try {
Expand Down

0 comments on commit 70139d3

Please sign in to comment.