From e054e1fe444058129934fc5e110887f97bfb65bb Mon Sep 17 00:00:00 2001 From: Brett Fattori Date: Tue, 17 Dec 2024 11:26:53 -0500 Subject: [PATCH] Added method to change location for download if >= 10 --- dist/index.js | 46 +++++++++++++++++++++++----- src/detect/detect-tool-downloader.ts | 44 +++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 63559ec..ea8e337 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42893,10 +42893,6 @@ class DetectFacade { if (this.inputs.scanMode === constants_1.RAPID_SCAN) { hasPolicyViolations = await this.processRapidScanResult(failureConditionsMet, outputPath); } - if (this.isDiagnosticModeEnabled()) { - const diagnosticZip = await this.getDiagnosticFilesPaths(outputPath); - await (0, upload_artifacts_1.uploadArtifact)('Detect Diagnostic Zip', outputPath, diagnosticZip); - } return hasPolicyViolations; } async hasEnabledBlackDuckPolicy() { @@ -42931,6 +42927,11 @@ class DetectFacade { core.setOutput(outputs_1.Output.DETECT_EXIT_CODE, detectExitCode); core.setOutput(outputs_1.Output.DETECT_EXIT_CODE_NAME, exitCodeName); core.info(`${detect_tool_downloader_1.TOOL_NAME} exited with code ${detectExitCode} - ${exitCodeName}.`); + // always process diagnostics regardless of exit code + if (this.isDiagnosticModeEnabled()) { + const diagnosticZip = await this.getDiagnosticFilesPaths(outputPath); + await (0, upload_artifacts_1.uploadArtifact)('Detect Diagnostic Zip', outputPath, diagnosticZip); + } const isSuccessOrPolicyFailure = detectExitCode === exit_code_1.ExitCode.SUCCESS || detectExitCode === exit_code_1.ExitCode.FAILURE_POLICY_VIOLATION; if (isSuccessOrPolicyFailure) { @@ -42997,24 +42998,53 @@ const toolCache = __importStar(__nccwpck_require__(7784)); const path_1 = __importDefault(__nccwpck_require__(1017)); const HttpClient_1 = __nccwpck_require__(5538); const constants_1 = __nccwpck_require__(2706); -const DETECT_BINARY_REPO_URL = 'https://sig-repo.synopsys.com'; +// new location since split with Synopsys +const DETECT_BINARY_REPO_URL = 'https://repo.blackduck.com'; +// curate the correct URI for the version +const DETECT_URI_BASE = '/bds-integrations-release/com/'; +const DETECT_LOCATION_SYNOPSYS = `${DETECT_URI_BASE}synopsys/integration/synopsys-detect`; +const DETECT_LOCATION_BLACKDUCK = `${DETECT_URI_BASE}blackduck/integration/detect`; exports.TOOL_NAME = 'detect'; class DetectToolDownloader { + AUTH_URI; + DOWNLOAD_URI; + TOOL_NAME_LOCAL; + constructor() { + // assume properties for v9.x or earlier + this.AUTH_URI = `${DETECT_BINARY_REPO_URL}/api/storage/${DETECT_LOCATION_SYNOPSYS}`; + this.DOWNLOAD_URI = `${DETECT_BINARY_REPO_URL}${DETECT_LOCATION_SYNOPSYS}`; + this.TOOL_NAME_LOCAL = 'synopsys-detect-'; + } + setupUris(versionAsNum = 8) { + if (versionAsNum >= 10) { + // new location to download versions >= 10 + this.AUTH_URI = `${DETECT_BINARY_REPO_URL}/api/storage/${DETECT_LOCATION_BLACKDUCK}`; + this.DOWNLOAD_URI = `${DETECT_BINARY_REPO_URL}${DETECT_LOCATION_BLACKDUCK}`; + this.TOOL_NAME_LOCAL = 'detect-'; + } + } async getDetectVersions() { const authenticationClient = new HttpClient_1.HttpClient(constants_1.APPLICATION_NAME); const headers = { 'X-Result-Detail': 'info' }; - const httpClientResponse = await authenticationClient.get(`${DETECT_BINARY_REPO_URL}/api/storage/bds-integrations-release/com/synopsys/integration/synopsys-detect?properties`, headers); + const httpClientResponse = await authenticationClient.get(`${this.AUTH_URI}?properties`, headers); const responseBody = await httpClientResponse.readBody(); return JSON.parse(responseBody); } async findDetectVersion(version) { + // default to 8.x + let majorVersionAsNum = 8; + if (version?.match(/^[0-9]+/)) { + majorVersionAsNum = parseInt(version); + } + // URIs differ based on version used + this.setupUris(majorVersionAsNum); if (version?.match(/^[0-9]+.[0-9]+.[0-9]+$/)) { return { - url: `${DETECT_BINARY_REPO_URL}/bds-integrations-release/com/synopsys/integration/synopsys-detect/${version}/synopsys-detect-${version}.jar`, + url: `${this.DOWNLOAD_URI}/${version}/${this.TOOL_NAME_LOCAL}${version}.jar`, version, - jarName: `synopsys-detect-${version}.jar` + jarName: `${this.TOOL_NAME_LOCAL}${version}.jar` }; } let detectVersionKey = 'DETECT_LATEST_'; diff --git a/src/detect/detect-tool-downloader.ts b/src/detect/detect-tool-downloader.ts index 690aac8..757ae0f 100644 --- a/src/detect/detect-tool-downloader.ts +++ b/src/detect/detect-tool-downloader.ts @@ -7,10 +7,37 @@ import { IHeaders } from 'typed-rest-client/Interfaces' import { DetectToolsVersions } from './detect-tools-versions' import { DetectToolVersion } from './detect-tool-version' -const DETECT_BINARY_REPO_URL = 'https://sig-repo.synopsys.com' +// new location since split with Synopsys +const DETECT_BINARY_REPO_URL = 'https://repo.blackduck.com' + +// curate the correct URI for the version +const DETECT_URI_BASE = '/bds-integrations-release/com/' +const DETECT_LOCATION_SYNOPSYS = `${DETECT_URI_BASE}synopsys/integration/synopsys-detect` +const DETECT_LOCATION_BLACKDUCK = `${DETECT_URI_BASE}blackduck/integration/detect` + export const TOOL_NAME = 'detect' export class DetectToolDownloader implements ToolDownloader { + private AUTH_URI: string + private DOWNLOAD_URI: string + private TOOL_NAME_LOCAL: string + + constructor() { + // assume properties for v9.x or earlier + this.AUTH_URI = `${DETECT_BINARY_REPO_URL}/api/storage/${DETECT_LOCATION_SYNOPSYS}` + this.DOWNLOAD_URI = `${DETECT_BINARY_REPO_URL}${DETECT_LOCATION_SYNOPSYS}` + this.TOOL_NAME_LOCAL = 'synopsys-detect-' + } + + private setupUris(versionAsNum = 8): undefined { + if (versionAsNum >= 10) { + // new location to download versions >= 10 + this.AUTH_URI = `${DETECT_BINARY_REPO_URL}/api/storage/${DETECT_LOCATION_BLACKDUCK}` + this.DOWNLOAD_URI = `${DETECT_BINARY_REPO_URL}${DETECT_LOCATION_BLACKDUCK}` + this.TOOL_NAME_LOCAL = 'detect-' + } + } + private async getDetectVersions(): Promise { const authenticationClient = new HttpClient(APPLICATION_NAME) const headers: IHeaders = { @@ -18,7 +45,7 @@ export class DetectToolDownloader implements ToolDownloader { } const httpClientResponse = await authenticationClient.get( - `${DETECT_BINARY_REPO_URL}/api/storage/bds-integrations-release/com/synopsys/integration/synopsys-detect?properties`, + `${this.AUTH_URI}?properties`, headers ) const responseBody = await httpClientResponse.readBody() @@ -28,11 +55,20 @@ export class DetectToolDownloader implements ToolDownloader { private async findDetectVersion( version?: string ): Promise { + // default to 8.x + let majorVersionAsNum = 8 + if (version?.match(/^[0-9]+/)) { + majorVersionAsNum = parseInt(version) + } + + // URIs differ based on version used + this.setupUris(majorVersionAsNum) + if (version?.match(/^[0-9]+.[0-9]+.[0-9]+$/)) { return { - url: `${DETECT_BINARY_REPO_URL}/bds-integrations-release/com/synopsys/integration/synopsys-detect/${version}/synopsys-detect-${version}.jar`, + url: `${this.DOWNLOAD_URI}/${version}/${this.TOOL_NAME_LOCAL}${version}.jar`, version, - jarName: `synopsys-detect-${version}.jar` + jarName: `${this.TOOL_NAME_LOCAL}${version}.jar` } }