Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ODC version CLI parameter to allow version pinning #21

Merged
merged 3 commits into from
Dec 30, 2023
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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ program
.allowUnknownOption()
.option('-o, --out <path>', 'the folder to write reports to', './dependency-check-reports')
.option('--bin <path>', 'directory to which the dependency-check CLI will be installed', './dependency-check-bin')
.option('--force-install', 'install the dependency-check CLI even if there already is one (will be overwritten)');
.option('--force-install', 'install the dependency-check CLI even if there already is one (will be overwritten)')
.option('--odc-version <version>', 'the version of the dependency-check CLI to install in format "v1.2.3" or "latest"', 'latest');

program.addHelpText('after', `
You can also use any arguments supported by the Owasp Dependency Check CLI tool, see: https://jeremylong.github.io/DependencyCheck/dependency-check-cli/arguments.html
Expand Down
9 changes: 6 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ const extract = require('extract-zip');

const IS_WIN = os.platform() === 'win32';
const NAME_RE = /^dependency\-check\-\d\.\d\.\d\-release\.zip$/;
const RELEASE_URL = 'https://api.github.com/repos/jeremylong/DependencyCheck/releases/latest';
const LATEST_RELEASE_URL = 'https://api.github.com/repos/jeremylong/DependencyCheck/releases/latest';
const TAG_RELEASE_URL = 'https://api.github.com/repos/jeremylong/DependencyCheck/releases/tags/';

function getBinDir() {
return path.resolve(process.cwd(), program.opts().bin);
return path.resolve(process.cwd(), program.opts().bin, program.opts().odcVersion);
}

function getCmdArguments() {
Expand Down Expand Up @@ -69,7 +70,9 @@ async function install() {

cleanDir(binDir);

const res = await fetch(RELEASE_URL);
// if odc version is latest use latest URL, otherwise use version URL
const url = program.opts().odcVersion === 'latest' ? LATEST_RELEASE_URL : TAG_RELEASE_URL + program.opts().odcVersion;
const res = await fetch(url);
const json = await res.json();

const asset = json.assets.find(a => NAME_RE.test(a.name));
Expand Down