From c8f859d7cc0f8a5fb28c24d939a5836e150c7b22 Mon Sep 17 00:00:00 2001 From: Chris Bush Date: Tue, 30 Jul 2024 21:13:10 -0500 Subject: [PATCH] #72 Fixes command line arguments for --scanners to be backwards compatible with previous version of trivy --- trivy-task/index.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/trivy-task/index.ts b/trivy-task/index.ts index 84a28b8..18c0944 100644 --- a/trivy-task/index.ts +++ b/trivy-task/index.ts @@ -95,10 +95,7 @@ function getAquaAccount(): aquaCredentials { } async function createRunner(docker: boolean, loginDockerConfig: boolean): Promise { - const version: string | undefined = task.getInput('version', true); - if (version === undefined) { - throw new Error("version is not defined") - } + const version = getVersion(); if (!docker) { console.log("Run requested using local Trivy binary...") @@ -152,12 +149,30 @@ function configureScan(runner: ToolRunner, type: string, target: string, outputP if (options.length) { runner.line(options) } else { - runner.arg(["--scanners", "vuln,misconfig,secret"]) + const version = stripV(getVersion()); + if(version < "0.40.0") { + runner.arg(["--security-checks", "vuln,config,secret"]) + } else if(version < "0.48.0") { + runner.arg(["--scanners", "vuln,config,secret"]) + } else { + runner.arg(["--scanners", "vuln,misconfig,secret"]) + } } runner.arg(target) } +function getVersion() { + const version: string | undefined = task.getInput('version', true); + if (version === undefined) { + throw new Error("version is not defined") + } + if (version === "latest") { + version = latestTrivyVersion + } + return version; +} + async function installTrivy(version: string): Promise { console.log("Finding correct Trivy version to install...") @@ -196,9 +211,6 @@ function stripV(version: string): string { } async function getArtifactURL(version: string): Promise { - if(version === "latest") { - version = latestTrivyVersion - } console.log("Required Trivy version is " + version) let arch = "" switch (os.arch()) {