diff --git a/packages/amazonq/.changes/next-release/Bug Fix-a6e9ce99-842b-4d64-b9b0-967383d7acb9.json b/packages/amazonq/.changes/next-release/Bug Fix-a6e9ce99-842b-4d64-b9b0-967383d7acb9.json new file mode 100644 index 00000000000..214602ad834 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-a6e9ce99-842b-4d64-b9b0-967383d7acb9.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "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" +} diff --git a/packages/core/src/codewhisperer/activation.ts b/packages/core/src/codewhisperer/activation.ts index 70a7417f263..efebb01e179 100644 --- a/packages/core/src/codewhisperer/activation.ts +++ b/packages/core/src/codewhisperer/activation.ts @@ -72,7 +72,12 @@ import { AuthUtil } from './util/authUtil' import { ImportAdderProvider } from './service/importAdderProvider' import { TelemetryHelper } from './util/telemetryHelper' import { openUrl } from '../shared/utilities/vsCodeUtils' -import { notifyNewCustomizations } from './util/customizationUtil' +import { + getAvailableCustomizationsList, + getSelectedCustomization, + notifyNewCustomizations, + switchToBaseCustomizationAndNotify, +} from './util/customizationUtil' import { CodeWhispererCommandBackend, CodeWhispererCommandDeclarations } from './commands/gettingStartedPageCommands' import { SecurityIssueHoverProvider } from './service/securityIssueHoverProvider' import { SecurityIssueCodeActionProvider } from './service/securityIssueCodeActionProvider' @@ -337,7 +342,27 @@ export async function activate(context: ExtContext): Promise { [...CodeWhispererConstants.securityScanLanguageIds], SecurityIssueCodeActionProvider.instance ), - vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange) + vscode.commands.registerCommand('aws.amazonq.openEditorAtRange', openEditorAtRange), + auth.regionProfileManager.onDidChangeRegionProfile(() => { + // Validate user still has access to the selected customization. + const selectedCustomization = getSelectedCustomization() + // No need to validate base customization which has empty arn. + if (selectedCustomization.arn.length > 0) { + getAvailableCustomizationsList() + .then(async (customizations) => { + const r = customizations.find((it) => it.arn === selectedCustomization.arn) + if (!r) { + await switchToBaseCustomizationAndNotify() + } + }) + .catch((e) => { + getLogger().error( + `encounter error while validating selected customization on profile change: %s`, + (e as Error).message + ) + }) + } + }) ) // run the auth startup code with context for telemetry diff --git a/packages/core/src/codewhisperer/region/regionProfileManager.ts b/packages/core/src/codewhisperer/region/regionProfileManager.ts index 71f6338d82a..effb5e3a84b 100644 --- a/packages/core/src/codewhisperer/region/regionProfileManager.ts +++ b/packages/core/src/codewhisperer/region/regionProfileManager.ts @@ -36,7 +36,6 @@ export const defaultServiceConfig: CodeWhispererConfig = { } // Hack until we have a single discovery endpoint. We will call each endpoint one by one to fetch profile before then. -// TODO: update correct endpoint and region const endpoints = createConstantMap({ 'us-east-1': 'https://q.us-east-1.amazonaws.com/', 'eu-central-1': 'https://q.eu-central-1.amazonaws.com/',