diff --git a/README.md b/README.md index b62b626..41af0fc 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,13 @@ Add the `--help` flag to any command for available options. ## Extension Settings -- `github.token`: Provide a GitHub Token instead of using VSCode Authentication. This token requires the `user:email` scope. (Ignores the `GITHUB_TOKEN` environment variable and/or VSCode Authentication if set.) +- `github.token`: Provide a GitHub Token instead of using VSCode Authentication. This token requires the `user:email` scope. (Or by the `GITHUB_TOKEN` environment variable.) - `assumeAws.assumeRoleAtStartup`: Automatically attempt to assume a role at startup. If `assumeAws.role` or `assumeAws.rememberRole` is set, the role prompt will be skipped. - `assumeAws.autoRefresh`: Automatically refresh the credentials before they expire. -- `assumeAws.region`: The AWS Default Region to set after assuming a role. (Overridden by the `AWS_DEFAULT_REGION` environment variable.) -- `assumeAws.role`: Skip role selection input and assume this role. (Overridden by the `AWS_ROLE_ARN` environment variable.) +- `assumeAws.region`: The AWS Default Region to set after assuming a role. (Or by the `AWS_DEFAULT_REGION` environment variable.) +- `assumeAws.role`: Skip role selection input and assume this role. (Or by the `AWS_ROLE_ARN` environment variable.) - `assumeAws.rememberRole`: Skip role selection input and assume the last role used. This is ignored when the `assumeAws.role` setting is set. -- `assumeAws.profile.name`: Save AWS Credentials to a named profile in `~/.aws/config`. (Overridden by the `AWS_PROFILE` environment variable.) +- `assumeAws.profile.name`: Save AWS Credentials to a named profile in `~/.aws/config`. (Or by the `AWS_PROFILE` environment variable.) ## Initial Setup diff --git a/TODO.md b/TODO.md index eab20e5..bf90b5c 100644 --- a/TODO.md +++ b/TODO.md @@ -6,3 +6,8 @@ - Try to invoke AWS Select Connection afterwards - Onboarding experience for brand new user / org - Loading progress indicator between inputs +- Prompt for Profile Name after Role Selection +- Devcontainer + - Set Role ARN + - Set Default Profile +- Get Help Action diff --git a/package.json b/package.json index 9f999fc..568f53d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "saml-to.github.token": { "type": "string", "default": null, - "markdownDescription": "Provide a GitHub Token instead of using VSCode Authentication. This token requires the `user:email` scope. (Ignores the `GITHUB_TOKEN` environment variable and/or VSCode Authentication if set.)" + "markdownDescription": "Provide a GitHub Token instead of using VSCode Authentication. This token requires the `user:email` scope. (Or by the `GITHUB_TOKEN` environment variable.)" }, "saml-to.assumeAws.assumeRoleAtStartup": { "type": "boolean", @@ -58,12 +58,12 @@ "saml-to.assumeAws.region": { "type": "string", "default": "us-east-1", - "markdownDescription": "The AWS Default Region to set after assuming a role. (Overridden by the `AWS_DEFAULT_REGION` environment variable.)" + "markdownDescription": "The AWS Default Region to set after assuming a role. (Or by the `AWS_DEFAULT_REGION` environment variable.)" }, "saml-to.assumeAws.role": { "type": "string", "default": null, - "markdownDescription": "Skip role selection input and assume this role. (Overridden by the `AWS_ROLE_ARN` environment variable.)" + "markdownDescription": "Skip role selection input and assume this role. (Or by the `AWS_ROLE_ARN` environment variable.)" }, "saml-to.assumeAws.rememberRole": { "type": "string", @@ -92,7 +92,7 @@ "Use the Account ID as the profile name.", "Do not save the credentials to a profile." ], - "markdownDescription": "Save AWS Credentials to a named profile in `~/.aws/config`. (Overridden by the `AWS_PROFILE` environment variable.)" + "markdownDescription": "Save AWS Credentials to a named profile in `~/.aws/config`. (Or by the `AWS_PROFILE` environment variable.)" } } } diff --git a/src/config.ts b/src/config.ts index 0f892b2..dc49286 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,7 +6,7 @@ export type Options = { }; export type GithubOptions = { - token: string | null; + token?: string; }; export type AssumeAwsOptions = { @@ -14,7 +14,7 @@ export type AssumeAwsOptions = { autoRefresh: boolean; rememberRole: RememberRole; region: string; - role: string | null; + role?: string; profile: AssumeAwsProfileOptions; }; @@ -38,11 +38,10 @@ export type AwsRoleSelection = { class GitHubConfiguration { constructor(private configuration: vscode.WorkspaceConfiguration) {} - get token(): string | null { - return this.configuration.get( - "token", - process.env.GITHUB_TOKEN || null - ); + get token(): string | undefined { + const fromConfig = this.configuration.get("token"); + const fromEnv = process.env.GITHUB_TOKEN; + return fromConfig || fromEnv; } } @@ -50,7 +49,9 @@ class AssumeAwsProfileConfiguration { constructor(private configuration: vscode.WorkspaceConfiguration) {} get name(): ProfileName { - return this.configuration.get("name", "Role ARN"); + const fromConfig = this.configuration.get("name"); + const fromEnv: ProfileName | undefined = process.env.AWS_PROFILE; + return fromConfig || fromEnv || "Role ARN"; } } @@ -89,39 +90,41 @@ class AssumeAwsConfiguration { } get region(): string { - return this.configuration.get("region", "us-east-1"); + const fromConfig = this.configuration.get("region"); + const fromEnv = process.env.AWS_DEFAULT_REGION; + return fromConfig || fromEnv || "us-east-1"; } - get role(): string | null { - return this.configuration.get("role", null); + get role(): string | undefined { + const fromConfig = this.configuration.get("role"); + const fromEnv = process.env.AWS_ROLE_ARN; + return fromConfig || fromEnv; } get profile(): AssumeAwsProfileConfiguration { return this.#profile; } - get lastRoleSelection(): AwsRoleSelection | null { + get lastRoleSelection(): AwsRoleSelection | undefined { if (this.rememberRole === "Global") { - let roleSelection = this.context.globalState.get( - "assumeAws.lastRoleSelection", - null + let roleSelection = this.context.globalState.get( + "assumeAws.lastRoleSelection" ); - return roleSelection ? JSON.parse(roleSelection) : null; + return roleSelection ? JSON.parse(roleSelection) : undefined; } if (this.rememberRole === "Workspace") { - let roleSelection = this.context.workspaceState.get( - "assumeAws.lastRoleSelection", - null + let roleSelection = this.context.workspaceState.get( + "assumeAws.lastRoleSelection" ); - return roleSelection ? JSON.parse(roleSelection) : null; + return roleSelection ? JSON.parse(roleSelection) : undefined; } - return null; + return undefined; } set lastRoleSelection(roleSelection: AwsRoleSelection | null) { - if (roleSelection === null) { + if (!roleSelection) { this.context.workspaceState .update("assumeAws.lastRoleSelection", null) .then(() => {});