Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/core/src/amazonqGumby/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,14 @@ export class GumbyController {
return
}
const fileContents = await fs.readFileText(fileUri[0].fsPath)
const isValidFile = await validateCustomVersionsFile(fileContents)
const missingKey = await validateCustomVersionsFile(fileContents)

if (!isValidFile) {
this.messenger.sendUnrecoverableErrorResponse('invalid-custom-versions-file', message.tabID)
if (missingKey) {
this.messenger.sendMessage(
CodeWhispererConstants.invalidCustomVersionsFileMessage(missingKey),
message.tabID,
'ai-prompt'
)
return
}
this.messenger.sendMessage(CodeWhispererConstants.receivedValidConfigFileMessage, message.tabID, 'ai-prompt')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export type UnrecoverableErrorType =
| 'job-start-failed'
| 'unsupported-source-db'
| 'unsupported-target-db'
| 'invalid-custom-versions-file'
| 'error-parsing-sct-file'
| 'invalid-zip-no-sct-file'
| 'invalid-from-to-jdk'
Expand Down Expand Up @@ -453,9 +452,6 @@ export class Messenger {
case 'unsupported-target-db':
message = CodeWhispererConstants.invalidMetadataFileUnsupportedTargetDB
break
case 'invalid-custom-versions-file':
message = CodeWhispererConstants.invalidCustomVersionsFileMessage
break
case 'error-parsing-sct-file':
message = CodeWhispererConstants.invalidMetadataFileErrorParsing
break
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ export const invalidMetadataFileUnsupportedSourceDB =
export const invalidMetadataFileUnsupportedTargetDB =
'I can only convert SQL for migrations to Aurora PostgreSQL or Amazon RDS for PostgreSQL target databases. The provided .sct file indicates another target database for this migration.'

export const invalidCustomVersionsFileMessage =
"I wasn't able to parse the dependency upgrade file. Check that it's configured properly and try again. For an example of the required dependency upgrade file format, see the [documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-transformation.html#dependency-upgrade-file)."
export const invalidCustomVersionsFileMessage = (missingKey: string) =>
`The dependency upgrade file provided is missing required field \`${missingKey}\`. Check that it is configured properly and try again. For an example of the required dependency upgrade file format, see the [documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-transformation.html#dependency-upgrade-file).`

export const invalidMetadataFileErrorParsing =
"It looks like the .sct file you provided isn't valid. Make sure that you've uploaded the .zip file you retrieved from your schema conversion in AWS DMS."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ export async function parseBuildFile() {
return undefined
}

// return the first missing key in the custom versions file, or undefined if all required keys are present
export async function validateCustomVersionsFile(fileContents: string) {
const requiredKeys = ['dependencyManagement:', 'identifier:', 'targetVersion:']
const requiredKeys = ['dependencyManagement', 'identifier', 'targetVersion', 'originType']
for (const key of requiredKeys) {
if (!fileContents.includes(key)) {
getLogger().info(`CodeTransformation: .YAML file is missing required key: ${key}`)
return false
return key
}
}
return true
return undefined
}

export async function validateSQLMetadataFile(fileContents: string, message: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,14 @@ dependencyManagement:
})

it(`WHEN validateCustomVersionsFile on fully valid .yaml file THEN passes validation`, async function () {
const isValidFile = await validateCustomVersionsFile(validCustomVersionsFile)
assert.strictEqual(isValidFile, true)
const missingKey = await validateCustomVersionsFile(validCustomVersionsFile)
assert.strictEqual(missingKey, undefined)
})

it(`WHEN validateCustomVersionsFile on invalid .yaml file THEN fails validation`, async function () {
const invalidFile = validCustomVersionsFile.replace('dependencyManagement', 'invalidKey')
const isValidFile = await validateCustomVersionsFile(invalidFile)
assert.strictEqual(isValidFile, false)
const missingKey = await validateCustomVersionsFile(invalidFile)
assert.strictEqual(missingKey, 'dependencyManagement')
})

it(`WHEN validateMetadataFile on fully valid .sct file THEN passes validation`, async function () {
Expand Down
Loading