Skip to content

Commit d7f7383

Browse files
JadenSimonjustinmk3
authored andcommitted
De-dupe codewhisperer add connection logic
1 parent 73f9786 commit d7f7383

File tree

2 files changed

+17
-42
lines changed

2 files changed

+17
-42
lines changed

src/codewhisperer/util/getStartUrl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const getStartUrl = async () => {
1616
const inputBox = await createStartUrlPrompter('IAM Identity Center', false)
1717
const userInput = await inputBox.prompt()
1818
if (!isValidResponse(userInput)) {
19+
telemetry.ui_click.emit({ elementId: 'connection_optionescapecancel' })
1920
throw new CancellationError('user')
2021
}
2122
telemetry.ui_click.emit({ elementId: 'connection_startUrl' })

src/codewhisperer/util/showSsoPrompt.ts

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import * as nls from 'vscode-nls'
7-
const localize = nls.loadMessageBundle()
8-
96
import * as vscode from 'vscode'
107
import { getLogger } from '../../shared/logger'
118
import { getStartUrl } from './getStartUrl'
@@ -14,13 +11,12 @@ import { AuthUtil, isUpgradeableConnection } from './authUtil'
1411
import { failedToConnectAwsBuilderId } from '../models/constants'
1512
import { isValidResponse } from '../../shared/wizards/wizard'
1613
import { CancellationError } from '../../shared/utilities/timeoutUtils'
17-
import { codicon, getIcon } from '../../shared/icons'
18-
import { DataQuickPickItem } from '../../shared/ui/pickerPrompter'
19-
import { getIdeProperties } from '../../shared/extensionUtilities'
2014
import { isUserCancelledError, ToolkitError } from '../../shared/errors'
2115
import { createCommonButtons } from '../../shared/ui/buttons'
2216
import { Auth } from '../../credentials/auth'
2317
import { showViewLogsMessage } from '../../shared/utilities/messages'
18+
import { createBuilderIdItem, createIamItem, createSsoItem } from '../../credentials/auth'
19+
import { telemetry } from '../../shared/telemetry/telemetry'
2420

2521
export const showConnectionPrompt = async () => {
2622
const currentConn = Auth.instance.activeConnection
@@ -39,15 +35,14 @@ export const showConnectionPrompt = async () => {
3935
}
4036
}
4137

42-
const resp = await showQuickPick(
43-
[createCodeWhispererBuilderIdItem(), createCodeWhispererSsoItem(), createCodeWhispererIamItem()],
44-
{
45-
title: 'CodeWhisperer: Add Connection to AWS',
46-
placeholder: 'Select a connection option to start using CodeWhisperer',
47-
buttons: createCommonButtons() as vscode.QuickInputButton[],
48-
}
49-
)
38+
const resp = await showQuickPick([createBuilderIdItem(), createSsoItem(), createCodeWhispererIamItem()], {
39+
title: 'CodeWhisperer: Add Connection to AWS',
40+
placeholder: 'Select a connection option to start using CodeWhisperer',
41+
buttons: createCommonButtons() as vscode.QuickInputButton[],
42+
})
43+
5044
if (!isValidResponse(resp)) {
45+
telemetry.ui_click.emit({ elementId: 'connection_optionescapecancel' })
5146
throw new CancellationError('user')
5247
}
5348
switch (resp) {
@@ -73,32 +68,11 @@ async function awsIdSignIn() {
7368
await vscode.commands.executeCommand('aws.codeWhisperer.enableCodeSuggestions')
7469
}
7570

76-
export const createCodeWhispererBuilderIdItem = () =>
77-
({
78-
label: codicon`${getIcon('vscode-person')} ${localize(
79-
'aws.auth.builderIdItem.label',
80-
'Use a personal email to sign up and sign in with AWS Builder ID'
81-
)}`,
82-
data: 'builderId',
83-
detail: 'Create or sign in with AWS Builder ID - a new, personal profile for builders.',
84-
} as DataQuickPickItem<'builderId'>)
71+
export const createCodeWhispererIamItem = () => {
72+
const item = createIamItem()
73+
item.detail = 'Not supported by CodeWhisperer.'
74+
item.description = 'not supported'
75+
item.invalidSelection = true
8576

86-
export const createCodeWhispererSsoItem = () =>
87-
({
88-
label: codicon`${getIcon('vscode-organization')} ${localize(
89-
'aws.auth.ssoItem.label',
90-
'Connect using {0} IAM Identity Center',
91-
getIdeProperties().company
92-
)}`,
93-
data: 'sso',
94-
detail: "Sign in to your company's IAM Identity Center access portal login page.",
95-
} as DataQuickPickItem<'sso'>)
96-
97-
export const createCodeWhispererIamItem = () =>
98-
({
99-
label: codicon`${getIcon('vscode-key')} ${localize('aws.auth.iamItem.label', 'Use IAM Credentials')}`,
100-
data: 'iam',
101-
detail: 'Not supported by CodeWhisperer.',
102-
description: 'not supported',
103-
invalidSelection: true,
104-
} as DataQuickPickItem<'iam'>)
77+
return item
78+
}

0 commit comments

Comments
 (0)