Skip to content

Commit 2e41855

Browse files
authored
feat(credentials): "Edit Credentials" button in error message #2880
Problem: When onboarding "from zero" (no ~/.aws, need credentials) or when running the "Create Credentials Profile" command, if the provided credentials are invalid, or if the user needs to edit ~/.aws/credentials to provide non-static credentials, there is no obvious way to open the ~/.aws/credentials file for new users. Solution: Show "Edit Credentials" in the error message if "Create Credentials Profile" fails.
1 parent 322ddac commit 2e41855

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "if \"Create Credentials Profile\" fails, error message now shows \"Edit Credentials\" button"
4+
}

src/credentials/credentialsUtilities.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { credentialHelpUrl } from '../shared/constants'
1212
import { Profile } from '../shared/credentials/credentialsFile'
1313
import globals from '../shared/extensionGlobals'
1414
import { isCloud9 } from '../shared/extensionUtilities'
15-
import { showMessageWithCancel, showViewLogsMessage } from '../shared/utilities/messages'
15+
import { messages, showMessageWithCancel, showViewLogsMessage } from '../shared/utilities/messages'
1616
import { Timeout, waitTimeout } from '../shared/utilities/timeoutUtils'
1717
import { fromExtensionManifest } from '../shared/settings'
1818

@@ -32,20 +32,24 @@ export function asEnvironmentVariables(credentials: Credentials): NodeJS.Process
3232
return environmentVariables
3333
}
3434

35-
export function notifyUserInvalidCredentials(credentialsId: string): void {
35+
export function showLoginFailedMessage(credentialsId: string, errMsg: string): void {
3636
const getHelp = localize('AWS.generic.message.getHelp', 'Get Help...')
37+
const editCreds = messages.editCredentials(false)
3738
// TODO: getHelp page for Cloud9.
38-
const buttons = isCloud9() ? [] : [getHelp]
39+
const buttons = isCloud9() ? [editCreds] : [editCreds, getHelp]
3940

4041
showViewLogsMessage(
41-
localize('AWS.message.credentials.invalid', 'Invalid credentials: {0}', credentialsId),
42+
localize('AWS.message.credentials.invalid', 'Credentials "{0}" failed to connect: {1}', credentialsId, errMsg),
4243
vscode.window,
4344
'error',
4445
buttons
4546
).then((selection: string | undefined) => {
4647
if (selection === getHelp) {
4748
vscode.env.openExternal(vscode.Uri.parse(credentialHelpUrl))
4849
}
50+
if (selection === editCreds) {
51+
vscode.commands.executeCommand('aws.credentials.edit')
52+
}
4953
})
5054
}
5155

src/credentials/loginManager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { AwsContext } from '../shared/awsContext'
1414
import { getLogger } from '../shared/logger'
1515
import { CredentialSourceId, CredentialType, Result } from '../shared/telemetry/telemetry'
1616
import { CredentialsStore } from './credentialsStore'
17-
import { CredentialsSettings, notifyUserInvalidCredentials } from './credentialsUtilities'
17+
import { CredentialsSettings, showLoginFailedMessage } from './credentialsUtilities'
1818
import {
1919
asString,
2020
CredentialsProvider,
@@ -86,9 +86,10 @@ export class LoginManager {
8686
} catch (err) {
8787
const credentialsId = asString(args.providerId)
8888
if (!CancellationError.isUserCancelled(err)) {
89-
const msg = `login: failed to connect with "${credentialsId}": ${(err as Error).message}`
89+
const errMsg = (err as Error).message
90+
const msg = `login: failed to connect with "${credentialsId}": ${errMsg}`
9091
if (!args.passive) {
91-
notifyUserInvalidCredentials(credentialsId)
92+
showLoginFailedMessage(credentialsId, errMsg)
9293
getLogger().error(msg)
9394
}
9495
} else {

src/credentials/wizards/createProfile.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DefaultStsClient } from '../../shared/clients/stsClient'
1515
import { ProfileKey } from './templates'
1616
import { createCommonButtons } from '../../shared/ui/buttons'
1717
import { credentialHelpUrl } from '../../shared/constants'
18-
import { showMessageWithUrl } from '../../shared/utilities/messages'
18+
import { showLoginFailedMessage } from '../credentialsUtilities'
1919

2020
function createProfileNamePrompter(profiles: ParsedIniData) {
2121
return createInputBox({
@@ -88,18 +88,7 @@ class ProfileChecker<T extends Profile> extends Prompter<string> {
8888

8989
return (await stsClient.getCallerIdentity()).Account
9090
} catch (err) {
91-
showMessageWithUrl(
92-
localize(
93-
'AWS.message.prompt.credentials.invalid',
94-
'Profile {0} is invalid: {1}',
95-
this.name,
96-
(err as any).message
97-
),
98-
credentialHelpUrl,
99-
undefined,
100-
'error'
101-
)
102-
91+
showLoginFailedMessage(this.name, (err as any).message ?? '?')
10392
return WIZARD_BACK
10493
} finally {
10594
loadingBar.dispose()

src/shared/credentials/defaultCredentialSelectionDataProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { getIdeProperties } from '../extensionUtilities'
2626
import { credentialHelpUrl } from '../constants'
2727
import { createHelpButton } from '../ui/buttons'
2828
import { recentlyUsed } from '../localizedText'
29-
import { getIcon, codicon } from '../icons'
29+
import { messages } from '../utilities/messages'
3030

3131
interface ProfileEntry {
3232
profileName: string
@@ -259,7 +259,7 @@ export async function credentialProfileSelector(
259259
) {
260260
const actions = [
261261
{
262-
label: localize('AWS.credentials.edit', '{0} Edit Credentials', codicon`${getIcon('vscode-edit')}`),
262+
label: messages.editCredentials(true),
263263
alwaysShow: true,
264264
description: localize('AWS.credentials.edit.desc', 'open ~/.aws/credentials'),
265265
},

src/shared/utilities/messages.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ import { sleep } from './timeoutUtils'
1414
import { Timeout } from './timeoutUtils'
1515
import { addCodiconToString } from './textUtilities'
1616
import * as localizedText from '../../shared/localizedText'
17+
import { getIcon, codicon } from '../icons'
18+
19+
export const messages = {
20+
editCredentials(icon: boolean) {
21+
// codicons are not supported in showInformationMessage. (vscode 1.71)
22+
const icon_ = icon ? codicon`${getIcon('vscode-edit')}` + ' ' : ''
23+
return localize('AWS.credentials.edit', '{0}Edit Credentials', icon_)
24+
},
25+
}
1726

1827
export function makeFailedWriteMessage(filename: string): string {
1928
const message = localize('AWS.failedToWrite', '{0}: Failed to write "{1}".', getIdeProperties().company, filename)

0 commit comments

Comments
 (0)