Skip to content

Commit 00fe7e2

Browse files
committed
feat(amazonq): attach profileArn to API calls when available
1 parent 6937c7f commit 00fe7e2

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

server/aws-lsp-codewhisperer/src/language-server/amazonQServiceManager/AmazonQTokenServiceManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { BaseAmazonQServiceManager } from './BaseAmazonQServiceManager'
3030
import { Q_CONFIGURATION_SECTION } from '../configuration/qConfigurationServer'
3131
import { textUtils } from '@aws/lsp-core'
3232
import { CodeWhispererStreaming } from '@amzn/codewhisperer-streaming'
33-
import { MISSING_BEARER_TOKEN_ERROR } from '../constants'
3433
import { ConfiguredRetryStrategy } from '@aws-sdk/util-retry'
3534
import {
3635
AmazonQDeveloperProfile,

server/aws-lsp-codewhisperer/src/language-server/codeWhispererService.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,18 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
185185
return 'bearer'
186186
}
187187

188+
private withProfileArn<T extends object>(request: T): T {
189+
if (!this.profileArn) return request
190+
191+
return { ...request, profileArn: this.profileArn }
192+
}
193+
188194
async generateSuggestions(request: GenerateSuggestionsRequest): Promise<GenerateSuggestionsResponse> {
189195
// add cancellation check
190196
// add error check
191-
if (this.customizationArn) request = { ...request, customizationArn: this.customizationArn }
192-
if (this.profileArn) {
193-
request.profileArn = this.profileArn
194-
}
197+
if (this.customizationArn) request.customizationArn = this.customizationArn
195198

196-
const response = await this.client.generateCompletions(request).promise()
199+
const response = await this.client.generateCompletions(this.withProfileArn(request)).promise()
197200
const responseContext = {
198201
requestId: response?.$response?.requestId,
199202
codewhispererSessionId: response?.$response?.httpResponse?.headers['x-amzn-sessionid'],
@@ -212,7 +215,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
212215
public async codeModernizerCreateUploadUrl(
213216
request: CodeWhispererTokenClient.CreateUploadUrlRequest
214217
): Promise<CodeWhispererTokenClient.CreateUploadUrlResponse> {
215-
return this.client.createUploadUrl(request).promise()
218+
return this.client.createUploadUrl(this.withProfileArn(request)).promise()
216219
}
217220
/**
218221
* @description Use this function to start the transformation job.
@@ -223,7 +226,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
223226
public async codeModernizerStartCodeTransformation(
224227
request: CodeWhispererTokenClient.StartTransformationRequest
225228
): Promise<PromiseResult<CodeWhispererTokenClient.StartTransformationResponse, AWSError>> {
226-
return await this.client.startTransformation(request).promise()
229+
return await this.client.startTransformation(this.withProfileArn(request)).promise()
227230
}
228231

229232
/**
@@ -234,7 +237,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
234237
public async codeModernizerStopCodeTransformation(
235238
request: CodeWhispererTokenClient.StopTransformationRequest
236239
): Promise<PromiseResult<CodeWhispererTokenClient.StopTransformationResponse, AWSError>> {
237-
return await this.client.stopTransformation(request).promise()
240+
return await this.client.stopTransformation(this.withProfileArn(request)).promise()
238241
}
239242

240243
/**
@@ -245,7 +248,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
245248
public async codeModernizerGetCodeTransformation(
246249
request: CodeWhispererTokenClient.GetTransformationRequest
247250
): Promise<PromiseResult<CodeWhispererTokenClient.GetTransformationResponse, AWSError>> {
248-
return await this.client.getTransformation(request).promise()
251+
return await this.client.getTransformation(this.withProfileArn(request)).promise()
249252
}
250253

251254
/**
@@ -256,7 +259,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
256259
public async codeModernizerGetCodeTransformationPlan(
257260
request: CodeWhispererTokenClient.GetTransformationPlanRequest
258261
): Promise<PromiseResult<CodeWhispererTokenClient.GetTransformationPlanResponse, AWSError>> {
259-
return this.client.getTransformationPlan(request).promise()
262+
return this.client.getTransformationPlan(this.withProfileArn(request)).promise()
260263
}
261264

262265
/**
@@ -265,7 +268,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
265268
async createUploadUrl(
266269
request: CodeWhispererTokenClient.CreateUploadUrlRequest
267270
): Promise<PromiseResult<CodeWhispererTokenClient.CreateUploadUrlResponse, AWSError>> {
268-
return this.client.createUploadUrl(request).promise()
271+
return this.client.createUploadUrl(this.withProfileArn(request)).promise()
269272
}
270273

271274
/**
@@ -274,7 +277,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
274277
async startCodeAnalysis(
275278
request: CodeWhispererTokenClient.StartCodeAnalysisRequest
276279
): Promise<PromiseResult<CodeWhispererTokenClient.StartCodeAnalysisResponse, AWSError>> {
277-
return this.client.startCodeAnalysis(request).promise()
280+
return this.client.startCodeAnalysis(this.withProfileArn(request)).promise()
278281
}
279282

280283
/**
@@ -283,7 +286,7 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
283286
async getCodeAnalysis(
284287
request: CodeWhispererTokenClient.GetCodeAnalysisRequest
285288
): Promise<PromiseResult<CodeWhispererTokenClient.GetCodeAnalysisResponse, AWSError>> {
286-
return this.client.getCodeAnalysis(request).promise()
289+
return this.client.getCodeAnalysis(this.withProfileArn(request)).promise()
287290
}
288291

289292
/**
@@ -292,14 +295,14 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
292295
async listCodeAnalysisFindings(
293296
request: CodeWhispererTokenClient.ListCodeAnalysisFindingsRequest
294297
): Promise<PromiseResult<CodeWhispererTokenClient.ListCodeAnalysisFindingsResponse, AWSError>> {
295-
return this.client.listCodeAnalysisFindings(request).promise()
298+
return this.client.listCodeAnalysisFindings(this.withProfileArn(request)).promise()
296299
}
297300

298301
/**
299302
* @description Get list of available customizations
300303
*/
301304
async listAvailableCustomizations(request: CodeWhispererTokenClient.ListAvailableCustomizationsRequest) {
302-
return this.client.listAvailableCustomizations(request).promise()
305+
return this.client.listAvailableCustomizations(this.withProfileArn(request)).promise()
303306
}
304307

305308
/**
@@ -313,6 +316,6 @@ export class CodeWhispererServiceToken extends CodeWhispererServiceBase {
313316
* @description send telemetry event to code whisperer data warehouse
314317
*/
315318
async sendTelemetryEvent(request: CodeWhispererTokenClient.SendTelemetryEventRequest) {
316-
return this.client.sendTelemetryEvent(request).promise()
319+
return this.client.sendTelemetryEvent(this.withProfileArn(request)).promise()
317320
}
318321
}

0 commit comments

Comments
 (0)