From 10a35cbffdf612b4c38748722a0b87d81644d7fe Mon Sep 17 00:00:00 2001 From: Ilya Boyazitov Date: Tue, 16 Jul 2024 12:56:28 +0300 Subject: [PATCH] Add env variables NPM_URL, GO_PKG_URL, RUST_CRATES_URL, NUGET_URL (#1247) * Fixes #1245 Signed-off-by: Ilya Boyazitov * Fix linting issues Signed-off-by: Ilya Boyazitov --------- Signed-off-by: Ilya Boyazitov --- docs/ENV.md | 6 +++++- utils.js | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/ENV.md b/docs/ENV.md index ce16222b5..96b080a11 100644 --- a/docs/ENV.md +++ b/docs/ENV.md @@ -40,7 +40,11 @@ The following environment variables are available to configure the bom generatio | CDX_MAVEN_INCLUDE_TEST_SCOPE | Whether test scoped dependencies should be included from Maven projects, Default: true | | ASTGEN_IGNORE_DIRS | Comma separated list of directories to ignore while analyzing using babel. The environment variable is also used by atom and astgen. | | ASTGEN_IGNORE_FILE_PATTERN | Ignore regex to use | -| PYPI_URL | Override pypi url. Default: https://pypi.org/pypi/ | +| PYPI_URL | Override PyPi URL. Default: https://pypi.org/pypi/ | +| NPM_URL | Override NPM registry URL. Default: https://registry.npmjs.org/ | +| GO_PKG_URL | Override Go pkg URL. Default: https://pkg.go.dev/ | +| RUST_CRATES_URL | Override Rust Crates URL. Default: https://crates.io/api/v1/crates/ | +| NUGET_URL | Override NuGet URL. Default is URL from registration hive "RegistrationsBaseUrl/3.6.0" at NuGet V3 API (https://api.nuget.org/v3/index.json). See more at https://learn.microsoft.com/en-us/nuget/api/registration-base-url-resource/ | | DOCKER_CONFIG | Alternative path to $HOME/.docker | | DOCKER_AUTH_CONFIG | Perform docker login prior to invoking cdxgen. The file $HOME/.docker/config.json would be automatically read if available. Base64 encoded (json) with credentials: `{'username': string, 'password': string, 'email': string, 'serveraddress' : string}`. Alternatively, set the below 4 environment variables. | | DOCKER_USER | Docker username | diff --git a/utils.js b/utils.js index bcecd90ca..6e50d90c5 100644 --- a/utils.js +++ b/utils.js @@ -710,7 +710,7 @@ export async function getSwiftPackageMetadata(pkgList) { * @param {Array} pkgList Package list */ export async function getNpmMetadata(pkgList) { - const NPM_URL = "https://registry.npmjs.org/"; + const NPM_URL = process.env.NPM_URL || "https://registry.npmjs.org/"; const cdepList = []; for (const p of pkgList) { try { @@ -4246,7 +4246,7 @@ export async function getRepoLicense(repoUrl, repoMetadata) { export async function getGoPkgLicense(repoMetadata) { const group = repoMetadata.group; const name = repoMetadata.name; - let pkgUrlPrefix = "https://pkg.go.dev/"; + let pkgUrlPrefix = process.env.GO_PKG_URL || "https://pkg.go.dev/"; if (group && group !== "." && group !== name) { pkgUrlPrefix = `${pkgUrlPrefix + group}/`; } @@ -5152,7 +5152,8 @@ export async function parseGemfileLockData(gemLockData, lockFile) { * @param {Array} pkgList Package list */ export async function getCratesMetadata(pkgList) { - const CRATES_URL = "https://crates.io/api/v1/crates/"; + const CRATES_URL = + process.env.RUST_CRATES_URL || "https://crates.io/api/v1/crates/"; const cdepList = []; for (const p of pkgList) { try { @@ -10933,7 +10934,7 @@ async function queryNuget(p, NUGET_URL) { * @param {Array} pkgList Package list */ export async function getNugetMetadata(pkgList, dependencies = undefined) { - const NUGET_URL = await getNugetUrl(); + const NUGET_URL = process.env.NUGET_URL || (await getNugetUrl()); const cdepList = []; const depRepList = {}; for (const p of pkgList) {