Skip to content

Commit 6fcfc3e

Browse files
committed
feat: Add menu option to update Aqua plugin
When Aqua platform integration is enabled we want to provide a mechanism for updating the aqua plugin. When the platform is enabled, a menu item is available to update the plugin, it will open the output window and run `trivy plugin upgrade aqua`
1 parent b76ef91 commit 6fcfc3e

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 1.8.6
4+
5+
- Add a menu option to update the version of the Aqua plugin
6+
37
## 1.8.5
48

59
- Add support for detecting cursor to enable MCP menu

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"publisher": "AquaSecurityOfficial",
55
"description": "Find vulnerabilities, misconfigurations and exposed secrets in your code",
66
"icon": "images/icon.png",
7-
"version": "1.8.5",
7+
"version": "1.8.6",
88
"engines": {
99
"vscode": "^1.56.0"
1010
},
@@ -327,6 +327,10 @@
327327
"command": "trivy.useAquaPlatform",
328328
"title": "Use Aqua Platform"
329329
},
330+
{
331+
"command": "trivy.updateAquaPlugin",
332+
"title": "Update Aqua Platform Plugin"
333+
},
330334
{
331335
"command": "trivy.disableUseAquaPlatform",
332336
"title": "✓ Use Aqua Platform"
@@ -514,6 +518,11 @@
514518
"when": "view == trivyIssueViewer && trivy.sastScanning && trivy.useAquaPlatform",
515519
"group": "4_aquaPlatform@7"
516520
},
521+
{
522+
"command": "trivy.updateAquaPlugin",
523+
"when": "view == trivyIssueViewer && trivy.useAquaPlatform",
524+
"group": "4_aquaPlatform@8"
525+
},
517526
{
518527
"command": "trivy.setupCommercial",
519528
"when": "view == trivyIssueViewer",

src/activate_commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ export function registerCommands(
177177
() => trivyWrapper.showCurrentTrivyVersion(),
178178
'Failed to get Trivy version'
179179
);
180+
registerCommand(
181+
context,
182+
'trivy.updateAquaPlugin',
183+
() => trivyWrapper.updateAquaPlugin(),
184+
'Failed to update aqua plugin'
185+
);
180186
registerCommand(context, 'trivy.refresh', () => {
181187
misconfigProvider.refresh();
182188
assuranceProvider.refresh();

src/command/command.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ export class TrivyWrapper {
218218
}
219219
}
220220

221+
/**
222+
* Update the Aqua Platform plugin
223+
*/
224+
async updateAquaPlugin(): Promise<void> {
225+
try {
226+
await this.updateAquaPluginVersion();
227+
} catch (error) {
228+
const errorMessage =
229+
error instanceof Error ? error.message : String(error);
230+
showErrorMessage(`Failed to update aqua plugin: ${errorMessage}`);
231+
}
232+
}
233+
221234
/**
222235
* Scan a specific workspace folder
223236
* @param workspaceFolder The workspace folder to scan
@@ -402,6 +415,52 @@ export class TrivyWrapper {
402415
});
403416
}
404417

418+
/**
419+
* Get the installed Trivy version
420+
* @returns Promise resolving to version string of the installed Trivy binary
421+
*/
422+
async updateAquaPluginVersion() {
423+
if (!this.checkTrivyInstalled()) {
424+
showErrorMessage('Trivy could not be found, check Output window');
425+
return;
426+
}
427+
428+
const binary = this.getBinaryPath();
429+
430+
return new Promise<string>((resolve, reject) => {
431+
this.outputChannel.getOutputChannel().show(true);
432+
try {
433+
const process = child.exec(`"${binary}" plugin upgrade aqua`);
434+
435+
process.stdout?.on('data', (data) => {
436+
this.outputChannel.appendLine(`${data.toString()}`);
437+
});
438+
439+
process.stderr?.on('data', (data) => {
440+
this.outputChannel.appendLine(`${data.toString()}`);
441+
const result = data.toString();
442+
if (result.includes('Plugin upgraded')) {
443+
showInformationMessage(
444+
'Aqua Platform plugin upgraded successfully'
445+
);
446+
resolve('');
447+
} else if (result.includes('The plugin is up-to-date')) {
448+
showInformationMessage(
449+
'Aqua Platform plugin is already up-to-date'
450+
);
451+
resolve('');
452+
}
453+
});
454+
455+
process.on('error', (error) => {
456+
reject(error);
457+
});
458+
} catch (error) {
459+
reject(error);
460+
}
461+
});
462+
}
463+
405464
/**
406465
* Build the Trivy command
407466
* @param workingPath Path to scan

0 commit comments

Comments
 (0)