diff --git a/README.md b/README.md index 28595a8..ba92d75 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ This is the VSCode Extension for [SAML.to](https://saml.to). It allows for AWS role assumption within VSCode. +![Assume an AWS Role in VSCode](resources/marketplace/assume-role.gif) + ## Features - Assume AWS Roles in VSCode diff --git a/TODO.md b/TODO.md index e86b75f..9522137 100644 --- a/TODO.md +++ b/TODO.md @@ -3,3 +3,4 @@ - Write to env? - Test with AWS Extension - Onboarding experience for brand new user +- Set Provider/Org in assumeRole, save these to cache diff --git a/package.json b/package.json index 921d2c4..288e1d8 100644 --- a/package.json +++ b/package.json @@ -134,8 +134,9 @@ "dependencies": { "@aws-sdk/client-sts": "^3.458.0", "@octokit/rest": "^20.0.2", + "axios": "^1.6.2", "humanize-duration": "^3.31.0", "qrcode-svg": "^1.1.0", "which": "^4.0.0" } -} \ No newline at end of file +} diff --git a/resources/marketplace/assume-role.gif b/resources/marketplace/assume-role.gif new file mode 100644 index 0000000..8b0437e Binary files /dev/null and b/resources/marketplace/assume-role.gif differ diff --git a/src/aws.ts b/src/aws.ts index b78a192..03c7e87 100644 --- a/src/aws.ts +++ b/src/aws.ts @@ -5,6 +5,7 @@ import { AssumeRoleWithSAMLCommand, STSClient } from "@aws-sdk/client-sts"; import { exec } from "./exec"; import humanizeDuration from "humanize-duration"; import { Configuration, ProfileName } from "./config"; +import { isAxiosError } from "axios"; export const assumeAwsRole = ( configuration: Configuration, @@ -41,7 +42,7 @@ export const assumeAwsRole = ( return { label: r.role.split("/").pop() || r.role, description: r.org, - detail: r.role, + detail: `${r.role}`, roleArn: r.role, }; }), @@ -157,12 +158,22 @@ export const assumeAwsRole = ( } } } catch (e) { + // Clear State + configuration.assumeAws.lastRoleArn = null; + if (!(e instanceof Error)) { throw e; } - vscode.window.showWarningMessage( - `[SAML.to] Unable to assume AWS role: ${e.message}` - ); + + if (isAxiosError(e)) { + vscode.window.showWarningMessage( + `[SAML.to] Unable to assume AWS role: ${e.response?.data?.message}` + ); + } else { + vscode.window.showWarningMessage( + `[SAML.to] Unable to assume AWS role: ${e.message}` + ); + } } }; }; diff --git a/src/config.ts b/src/config.ts index a01581d..489f831 100644 --- a/src/config.ts +++ b/src/config.ts @@ -113,6 +113,16 @@ class AssumeAwsConfiguration { } set lastRoleArn(roleArn: string | null) { + if (roleArn === null) { + this.context.workspaceState + .update("assumeAws.lastRoleArn", null) + .then(() => {}); + this.context.globalState + .update("assumeAws.lastRoleArn", null) + .then(() => {}); + return; + } + let memento: vscode.Memento | undefined = undefined; if (this.rememberRole === "Global") {