Skip to content

Commit 6bae9eb

Browse files
committed
fix downloadExportResultAcrchive api call not passed with profileArn and cause 400 error
1 parent ce3dd61 commit 6bae9eb

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

packages/core/src/codewhisperer/service/testGenHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { randomUUID } from '../../shared/crypto'
3636
import { sleep } from '../../shared/utilities/timeoutUtils'
3737
import { tempDirPath } from '../../shared/filesystemUtilities'
3838
import fs from '../../shared/fs/fs'
39+
import { AuthUtil } from '../util/authUtil'
3940

4041
// TODO: Get TestFileName and Framework and to error message
4142
export function throwIfCancelled() {
@@ -310,7 +311,8 @@ export async function downloadResultArchive(
310311
},
311312
},
312313
},
313-
pathToArchive
314+
pathToArchive,
315+
AuthUtil.instance.regionProfileManager.activeRegionProfile
314316
)
315317
} catch (e: any) {
316318
downloadErrorMessage = (e as Error).message

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { encodeHTML } from '../../../shared/utilities/textUtilities'
5151
import { convertToTimeString } from '../../../shared/datetime'
5252
import { getAuthType } from '../../../auth/utils'
5353
import { UserWrittenCodeTracker } from '../../tracker/userWrittenCodeTracker'
54+
import { AuthUtil } from '../../util/authUtil'
5455

5556
export function getSha256(buffer: Buffer) {
5657
const hasher = crypto.createHash('sha256')
@@ -759,7 +760,8 @@ export async function downloadResultArchive(
759760
exportId: jobId,
760761
exportIntent: ExportIntent.TRANSFORMATION,
761762
},
762-
pathToArchive
763+
pathToArchive,
764+
AuthUtil.instance.regionProfileManager.activeRegionProfile
763765
)
764766
} catch (e: any) {
765767
getLogger().error(`CodeTransformation: ExportResultArchive error = %O`, e)

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSess
2727
import { setContext } from '../../../shared/vscode/setContext'
2828
import * as codeWhisperer from '../../client/codewhisperer'
2929
import { UserWrittenCodeTracker } from '../../tracker/userWrittenCodeTracker'
30+
import { AuthUtil } from '../../util/authUtil'
3031

3132
export abstract class ProposedChangeNode {
3233
abstract readonly resourcePath: string
@@ -403,7 +404,8 @@ export class ProposedTransformationExplorer {
403404
exportId: transformByQState.getJobId(),
404405
exportIntent: ExportIntent.TRANSFORMATION,
405406
},
406-
pathToArchive
407+
pathToArchive,
408+
AuthUtil.instance.regionProfileManager.activeRegionProfile
407409
)
408410

409411
getLogger().info('CodeTransformation: downloaded results successfully')

packages/core/src/shared/utilities/download.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { CodeWhispererStreaming, ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming'
77
import { ToolkitError } from '../errors'
88
import fs from '../fs/fs'
9+
import { RegionProfile } from '../../codewhisperer/models/model'
910

1011
/**
1112
* This class represents the structure of the archive returned by the ExportResultArchive endpoint
@@ -21,9 +22,10 @@ export class ExportResultArchiveStructure {
2122
export async function downloadExportResultArchive(
2223
cwStreamingClient: CodeWhispererStreaming,
2324
exportResultArchiveArgs: ExportResultArchiveCommandInput,
24-
toPath: string
25+
toPath: string,
26+
profile: RegionProfile | undefined
2527
) {
26-
const result = await cwStreamingClient.exportResultArchive(exportResultArchiveArgs)
28+
const result = await cwStreamingClient.exportResultArchive({ ...exportResultArchiveArgs, profileArn: profile?.arn })
2729

2830
const buffer = []
2931

packages/core/src/testInteg/perf/downloadExportResultArchive.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import { fs, getRandomString } from '../../shared'
1111
import { createTestWorkspace } from '../../test/testUtil'
1212
import { getEqualOSTestOptions, performanceTest } from '../../shared/performance/performance'
1313
import { downloadExportResultArchive } from '../../shared/utilities/download'
14+
import { RegionProfile } from '../../codewhisperer'
1415

1516
interface SetupResult {
1617
workspace: WorkspaceFolder
1718
exportCommandInput: ExportResultArchiveCommandInput
1819
writeFileStub: sinon.SinonStub
1920
cwStreaming: any
21+
profile: RegionProfile
2022
}
2123

2224
interface FakeCommandOutput {
@@ -42,7 +44,8 @@ async function setup(pieces: number, pieceSize: number): Promise<SetupResult> {
4244
const cwStreaming = { exportResultArchive: () => generateCommandOutput(pieces, pieceSize) }
4345

4446
const writeFileStub = sinon.stub(fs, 'writeFile')
45-
return { workspace, exportCommandInput, writeFileStub, cwStreaming }
47+
const profile: RegionProfile = { name: 'foo', region: 'us-east-1', arn: 'foo-arn', description: '' }
48+
return { workspace, exportCommandInput, writeFileStub, cwStreaming, profile }
4649
}
4750

4851
function perfTest(pieces: number, pieceSize: number, label: string) {
@@ -56,11 +59,18 @@ function perfTest(pieces: number, pieceSize: number, label: string) {
5659
function () {
5760
return {
5861
setup: async () => await setup(pieces, pieceSize),
59-
execute: async ({ workspace, cwStreaming, exportCommandInput, writeFileStub }: SetupResult) => {
62+
execute: async ({
63+
workspace,
64+
cwStreaming,
65+
exportCommandInput,
66+
writeFileStub,
67+
profile,
68+
}: SetupResult) => {
6069
await downloadExportResultArchive(
6170
cwStreaming,
6271
exportCommandInput,
63-
path.join(workspace.uri.fsPath, 'result')
72+
path.join(workspace.uri.fsPath, 'result'),
73+
profile
6474
)
6575
},
6676
verify: async (setup: SetupResult) => {

0 commit comments

Comments
 (0)