diff --git a/lib/assume.mjs b/lib/assume.mjs index 670ad12..f2f4368 100644 --- a/lib/assume.mjs +++ b/lib/assume.mjs @@ -48,7 +48,7 @@ async function getCredentials(accountId, roleName) { } export async function getCredentialsAndWrite(account) { - const { session } = await getArgs(); + const { session, skipDefaultProfile } = await getArgs(); const credentials = await getCredentials(account.accountId, account.role); const { vt_default_region, sso_start_url, sso_region } = @@ -56,7 +56,9 @@ export async function getCredentialsAndWrite(account) { const name = account.shortId + "-" + account.role; - await writeCredentials("default", credentials); + if (!skipDefaultProfile) { + await writeCredentials("default", credentials); + } await writeCredentials(name, credentials); await writeProfile(name, { @@ -68,11 +70,19 @@ export async function getCredentialsAndWrite(account) { region: vt_default_region || "eu-central-1", }); - console.log( - chalk.green( - `AWS credentials set for account ${account.name}.\nYou can use credentials with your default profile or --profile ${name}\n`, - ), - ); + if (!skipDefaultProfile) { + console.log( + chalk.green( + `AWS credentials set for account ${account.name}.\nYou can use the credentials with your default profile or --profile ${name} in the aws cli.\n`, + ), + ); + } else { + console.log( + chalk.green( + `AWS credentials set for account ${account.name}.\nYou can use the credentials with --profile ${name} in the aws cli.\n`, + ), + ); + } } function getRandomColor() { diff --git a/lib/cli.mjs b/lib/cli.mjs index a50fd8f..7a8742b 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -24,13 +24,15 @@ export async function getArgs() { "-r, --role [value]", "The name of a role which can be assumed. For example VT-DevOps. Must be used in combination with -a.", ) - .option( "-a, --account [value]", "The account in which the role should be assumed. For example 015572128213.", - ); - - program.option("-l, --logout", "Logout the defined sso-session."); + ) + .option( + "-n, --skip-default-profile", + "Do not write credentials to the default profile.", + ) + .option("-l, --logout", "Logout the defined sso-session."); opts = await program.parse(process.argv).opts(); diff --git a/lib/config.mjs b/lib/config.mjs index da846fa..08be56a 100644 --- a/lib/config.mjs +++ b/lib/config.mjs @@ -135,7 +135,7 @@ export async function readCache(sessionName) { } try { - JSON.parse(await readFile(cacheFile, "utf8")); + return JSON.parse(await readFile(cacheFile, "utf8")); } catch (_) { return {}; }