Skip to content

Commit

Permalink
bugfixes + readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuss committed Nov 30, 2023
1 parent 6bbcb52 commit 1388b26
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Binary file added resources/marketplace/assume-role.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions src/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
}),
Expand Down Expand Up @@ -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}`
);
}
}
};
};
Expand Down
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 1388b26

Please sign in to comment.