Skip to content

Commit ca6f73e

Browse files
committed
feat(amazonq): support SAS findings
1 parent 997b3b7 commit ca6f73e

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

packages/core/src/codewhisperer/commands/basicCommands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ export const generateFix = Commands.declare(
673673
if (!targetIssue) {
674674
return
675675
}
676+
if (targetIssue.ruleId === CodeWhispererConstants.sasRuleId) {
677+
getLogger().warn('GenerateFix is not available for SAS findings.')
678+
return
679+
}
676680
await telemetry.codewhisperer_codeScanIssueGenerateFix.run(async () => {
677681
try {
678682
await vscode.commands

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,13 @@ export const securityScanLanguageIds = [
334334
'sh',
335335
'shell',
336336
'shellscript',
337+
'brazilPackageConfig',
337338
] as const
338339

339340
export type SecurityScanLanguageId = (typeof securityScanLanguageIds)[number]
340341

342+
export const sasRuleId = 'sbom-software-assurance-services'
343+
341344
// wait time for editor to update editor.selection.active (in milliseconds)
342345
export const vsCodeCursorUpdateDelay = 10
343346

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ export async function listScanResults(
7575
// Project path example: /Users/username/project
7676
// Key example: project/src/main/java/com/example/App.java
7777
for (const projectPath of projectPaths) {
78-
// We need to remove the project path from the key to get the absolute path to the file
79-
// Do not use .. in between because there could be multiple project paths in the same parent dir.
80-
const filePath = path.join(projectPath, key.split('/').slice(1).join('/'))
78+
// There could be multiple projectPaths with the same parent dir
79+
// In that case, make sure to break out of this loop after a filePath is found
80+
// or else it might result in duplicate findings.
81+
const filePath = path.join(projectPath, '..', key)
8182
if (existsSync(filePath) && statSync(filePath).isFile()) {
8283
const document = await vscode.workspace.openTextDocument(filePath)
8384
const aggregatedCodeScanIssue: AggregatedCodeScanIssue = {
8485
filePath: filePath,
8586
issues: issues.map((issue) => mapRawToCodeScanIssue(issue, document, jobId, scope)),
8687
}
8788
aggregatedCodeScanIssueList.push(aggregatedCodeScanIssue)
89+
break
8890
}
8991
}
9092
const maybeAbsolutePath = `/${key}`

packages/core/src/codewhisperer/util/securityScanLanguageContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class SecurityScanLanguageContext {
4747
sh: 'shell',
4848
shell: 'shell',
4949
shellscript: 'shell',
50+
brazilPackageConfig: 'plaintext',
5051
})
5152
}
5253

packages/core/src/codewhisperer/views/securityIssue/vue/root.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,19 @@
8080
v-if="!isFixAvailable"
8181
@click="generateFix"
8282
class="mr-8 button-theme-primary"
83-
:disabled="isGenerateFixLoading"
83+
:disabled="isGenerateFixLoading || isGenerateFixDisabled"
8484
>
8585
Generate Fix
8686
</button>
8787
<button v-if="isFixAvailable" @click="applyFix" class="mr-8 button-theme-primary">Accept Fix</button>
88-
<button v-if="isFixAvailable" @click="regenerateFix" class="mr-8 button-theme-secondary">Regenerate Fix</button>
88+
<button
89+
v-if="isFixAvailable"
90+
@click="regenerateFix"
91+
class="mr-8 button-theme-secondary"
92+
:disabled="isGenerateFixDisabled"
93+
>
94+
Regenerate Fix
95+
</button>
8996
<button @click="explainWithQ" class="mr-8 button-theme-secondary">Explain</button>
9097
<button @click="ignoreIssue" class="mr-8 button-theme-secondary">Ignore</button>
9198
<button @click="ignoreAllIssues" class="mr-8 button-theme-secondary">Ignore All</button>
@@ -105,6 +112,7 @@ import markdownIt from 'markdown-it'
105112
import hljs from 'highlight.js'
106113
import { parsePatch } from 'diff'
107114
import { CodeScanIssue } from '../../../models/model'
115+
import { sasRuleId } from '../../../models/constants'
108116
109117
const client = WebviewClientFactory.create<SecurityIssueWebview>()
110118
const severityImages: Record<string, string> = {
@@ -198,6 +206,7 @@ export default defineComponent({
198206
fixedCode: '',
199207
referenceText: '',
200208
referenceSpan: [0, 0],
209+
isGenerateFixDisabled: false,
201210
}
202211
},
203212
created() {
@@ -278,6 +287,7 @@ export default defineComponent({
278287
this.endLine = issue.endLine
279288
this.isFixAvailable = false
280289
this.isFixDescriptionAvailable = false
290+
this.isGenerateFixDisabled = issue.ruleId === sasRuleId
281291
if (suggestedFix) {
282292
this.isFixAvailable = !!suggestedFix.code && suggestedFix.code?.trim() !== ''
283293
this.suggestedFix = suggestedFix.code ?? ''

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const languageCommentConfig: Record<SecurityScanLanguageId, CommentConfig | unde
4747
sh: { lineComment: '#', blockComment: [": '", "'"] },
4848
shell: { lineComment: '#', blockComment: [": '", "'"] },
4949
shellscript: { lineComment: '#', blockComment: [": '", "'"] },
50+
brazilPackageConfig: { lineComment: '#' },
5051
}
5152

5253
export function getLanguageCommentConfig(languageId: string): CommentConfig {

0 commit comments

Comments
 (0)