Skip to content

Commit d6d839a

Browse files
authored
fix(amazonq): validate customization on profile change #7049
## Problem - Before region expansion: customization is bound to a specific idc instance - After region expansion: customization is bound to a specific Q profile and an idc instance can have multi profiles - therefore each Q profile will have access to different sets of customization ## Solution We need to validate if the selected customization is accessible from the user's selected profile, otherwise will get ``` *An error occurred while processing your request.* This error is reported to the team automatically. We will attempt to fix it as soon as possible. Details: The provided profile ARN and customization ARN is mismatched. (Service: CodeWhispererRuntime, Status Code: 403, ```
1 parent 0288f4d commit d6d839a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Users might be bound to a customization which they dont have access with the selected profile and it causes service throwing 403 when using inline suggestion and chat features"
4+
}

packages/core/src/codewhisperer/activation.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ import { AuthUtil } from './util/authUtil'
7272
import { ImportAdderProvider } from './service/importAdderProvider'
7373
import { TelemetryHelper } from './util/telemetryHelper'
7474
import { openUrl } from '../shared/utilities/vsCodeUtils'
75-
import { notifyNewCustomizations } from './util/customizationUtil'
75+
import {
76+
getAvailableCustomizationsList,
77+
getSelectedCustomization,
78+
notifyNewCustomizations,
79+
switchToBaseCustomizationAndNotify,
80+
} from './util/customizationUtil'
7681
import { CodeWhispererCommandBackend, CodeWhispererCommandDeclarations } from './commands/gettingStartedPageCommands'
7782
import { SecurityIssueHoverProvider } from './service/securityIssueHoverProvider'
7883
import { SecurityIssueCodeActionProvider } from './service/securityIssueCodeActionProvider'
@@ -337,7 +342,27 @@ export async function activate(context: ExtContext): Promise<void> {
337342
[...CodeWhispererConstants.securityScanLanguageIds],
338343
SecurityIssueCodeActionProvider.instance
339344
),
340-
vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange)
345+
vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange),
346+
auth.regionProfileManager.onDidChangeRegionProfile(() => {
347+
// Validate user still has access to the selected customization.
348+
const selectedCustomization = getSelectedCustomization()
349+
// No need to validate base customization which has empty arn.
350+
if (selectedCustomization.arn.length > 0) {
351+
getAvailableCustomizationsList()
352+
.then(async (customizations) => {
353+
const r = customizations.find((it) => it.arn === selectedCustomization.arn)
354+
if (!r) {
355+
await switchToBaseCustomizationAndNotify()
356+
}
357+
})
358+
.catch((e) => {
359+
getLogger().error(
360+
`encounter error while validating selected customization on profile change: %s`,
361+
(e as Error).message
362+
)
363+
})
364+
}
365+
})
341366
)
342367

343368
// run the auth startup code with context for telemetry

packages/core/src/codewhisperer/region/regionProfileManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const defaultServiceConfig: CodeWhispererConfig = {
3636
}
3737

3838
// Hack until we have a single discovery endpoint. We will call each endpoint one by one to fetch profile before then.
39-
// TODO: update correct endpoint and region
4039
const endpoints = createConstantMap({
4140
'us-east-1': 'https://q.us-east-1.amazonaws.com/',
4241
'eu-central-1': 'https://q.eu-central-1.amazonaws.com/',

0 commit comments

Comments
 (0)