Skip to content

Commit eeebd0b

Browse files
committed
Implement IAM setup function
1 parent ab47a46 commit eeebd0b

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

packages/core/src/auth/auth2.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
AuthorizationFlowKind,
2929
CancellationToken,
3030
CancellationTokenSource,
31+
iamCredentialsUpdateRequestType,
32+
iamCredentialsDeleteNotificationType,
3133
bearerCredentialsDeleteNotificationType,
3234
bearerCredentialsUpdateRequestType,
3335
SsoTokenChangedKind,
@@ -45,6 +47,10 @@ import { getCacheDir, getCacheFileWatcher, getFlareCacheFileName } from './sso/c
4547
import { VSCODE_EXTENSION_ID } from '../shared/extensions'
4648

4749
export const notificationTypes = {
50+
updateIamCredential: new RequestType<UpdateCredentialsParams, ResponseMessage, Error>(
51+
iamCredentialsUpdateRequestType.method
52+
),
53+
deleteIamCredential: new NotificationType(iamCredentialsDeleteNotificationType.method),
4854
updateBearerToken: new RequestType<UpdateCredentialsParams, ResponseMessage, Error>(
4955
bearerCredentialsUpdateRequestType.method
5056
),

packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import { debounce } from 'lodash'
1515
import { AuthError, AuthFlowState, userCancelled } from '../types'
1616
import { ToolkitError } from '../../../../shared/errors'
1717
import { withTelemetryContext } from '../../../../shared/telemetry/util'
18+
import { Commands } from '../../../../shared/vscode/commands2'
1819
import { builderIdStartUrl } from '../../../../auth/sso/constants'
19-
import { RegionProfile } from '../../../../codewhisperer/models/model'
20+
import { RegionProfile, vsCodeState } from '../../../../codewhisperer/models/model'
2021
import { randomUUID } from '../../../../shared/crypto'
2122
import globals from '../../../../shared/extensionGlobals'
2223
import { telemetry } from '../../../../shared/telemetry/telemetry'
@@ -196,12 +197,40 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
196197
return []
197198
}
198199

199-
override startIamCredentialSetup(
200+
async startIamCredentialSetup(
200201
profileName: string,
201202
accessKey: string,
202203
secretKey: string
203204
): Promise<AuthError | undefined> {
204-
throw new Error('Method not implemented.')
205+
getLogger().debug(`called startIamCredentialSetup()`)
206+
// Defining separate auth function to emit telemetry before returning from setup
207+
const runAuth = async (): Promise<AuthError | undefined> => {
208+
try {
209+
await AuthUtil.instance.login(accessKey, secretKey)
210+
// Add auth telemetry
211+
this.storeMetricMetadata(await AuthUtil.instance.getTelemetryMetadata())
212+
// Show sign-in message
213+
void vscode.window.showInformationMessage('AmazonQ: Successfully connected to AWS IAM Credentials')
214+
} catch (e) {
215+
getLogger().error('Failed submitting credentials %O', e)
216+
return { id: this.id, text: e as string }
217+
}
218+
// Enable code suggestions
219+
vsCodeState.isFreeTierLimitReached = false
220+
await Commands.tryExecute('aws.amazonq.enableCodeSuggestions')
221+
}
222+
223+
const result = await runAuth()
224+
225+
// Emit telemetry
226+
this.storeMetricMetadata({
227+
credentialSourceId: 'sharedCredentials',
228+
authEnabledFeatures: 'codewhisperer',
229+
...this.getResultForMetrics(result),
230+
})
231+
this.emitAuthMetric()
232+
233+
return result
205234
}
206235

207236
/** If users are unauthenticated in Q/CW, we should always display the auth screen. */

0 commit comments

Comments
 (0)