From f74a7b6d86ac1b9295f10e0bc9ee684b47bf572f Mon Sep 17 00:00:00 2001 From: Sela Lerer Date: Wed, 13 Aug 2025 13:39:11 +0300 Subject: [PATCH] RTDEB-61940 - Support debug mode and improve logging --- lib/evidence-collection.js | 28 +++++++++++++++++++++------- lib/utils.js | 4 ++++ src/evidence-collection.ts | 23 ++++++++++++++++++++--- src/utils.ts | 4 ++++ 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/lib/evidence-collection.js b/lib/evidence-collection.js index 0b909de7d..2476f09dd 100644 --- a/lib/evidence-collection.js +++ b/lib/evidence-collection.js @@ -47,7 +47,7 @@ function collectEvidences() { return __awaiter(this, void 0, void 0, function* () { var _a; try { - core.startGroup('Collecting evidences'); + core.startGroup('Collecting evidence'); // Check authentication method first - evidence collection requires access token or OIDC const credentials = utils_1.Utils.collectJfrogCredentialsFromEnvVars(); if (!credentials.accessToken && !credentials.oidcProviderName && (credentials.username || credentials.password)) { @@ -62,7 +62,6 @@ function collectEvidences() { // Check if evidence collection is supported by the server const evidenceConfig = yield getEvidenceConfiguration(); if (!evidenceConfig.external_evidence_collection_supported) { - core.info("Evidence collection is not supported by Artifactory's license type. Skipping evidence collection."); return; } // Use a default limit if the server doesn't provide one @@ -116,19 +115,30 @@ function getEvidenceConfiguration() { } catch (error) { core.warning(`Failed to get evidence configuration (network error or server unavailable): ${error}`); - return {external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0}; + return { external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0 }; } + // 200 OK if (response.message.statusCode !== 200) { - core.warning(`Failed to get evidence configuration. Status: ${response.message.statusCode}, Response: ${body}`); - return {external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0}; + // 401 Unauthorized + if (response.message.statusCode === 401) { + core.warning(`Failed to get evidence configuration. Given credentials are not sufficient` + + ` to create evidence in the JFrog platform, Response: ${body}`); + } + else { + core.warning(`Failed to get evidence configuration. Status: ${response.message.statusCode}, Response: ${body}`); + } + return { external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0 }; } try { const config = JSON.parse(body); + if (!config.external_evidence_collection_supported) { + core.info("Evidence collection is not supported by Artifactory's license type. Skipping evidence collection."); + } return config; } catch (error) { core.warning(`Failed to parse evidence config response: ${error}`); - return {external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0}; + return { external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0 }; } }); } @@ -161,10 +171,14 @@ function getSigstoreBundlePaths() { return []; } core.info(`Found ${filePaths.length} sigstore bundle file(s) to process.`); + if (core.isDebug()) { + filePaths.forEach((filePath) => { + core.debug(`Sigstore bundle file found: ${filePath}`); + }); + } return filePaths; }); } - /** * Creates evidence for sigstore bundle files. * @param maxFileSizeMB Maximum allowed file size in MB diff --git a/lib/utils.js b/lib/utils.js index c50d103c8..9785caca0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -246,6 +246,9 @@ class Utils { } static setCliEnv() { var _a, _b, _c, _d, _e; + if (core.isDebug()) { + Utils.exportVariableIfNotSet('JFROG_CLI_LOG_LEVEL', 'DEBUG'); + } Utils.exportVariableIfNotSet('JFROG_CLI_ENV_EXCLUDE', '*password*;*secret*;*key*;*token*;*auth*;JF_ARTIFACTORY_*;JF_ENV_*;JF_URL;JF_USER;JF_PASSWORD;JF_ACCESS_TOKEN'); Utils.exportVariableIfNotSet('JFROG_CLI_OFFER_CONFIG', 'false'); Utils.exportVariableIfNotSet('CI', 'true'); @@ -377,6 +380,7 @@ class Utils { */ static runCliAndGetOutput(args, options) { return __awaiter(this, void 0, void 0, function* () { + core.debug(`jf ${args.join(' ')}`); let output; output = yield (0, exec_1.getExecOutput)('jf', args, Object.assign(Object.assign({}, options), { ignoreReturnCode: true })); if (output.exitCode !== core.ExitCode.Success) { diff --git a/src/evidence-collection.ts b/src/evidence-collection.ts index cb6f8634a..bf94c6cc3 100644 --- a/src/evidence-collection.ts +++ b/src/evidence-collection.ts @@ -17,7 +17,7 @@ interface EvidenceConfigResponse { */ export async function collectEvidences() { try { - core.startGroup('Collecting evidences'); + core.startGroup('Collecting evidence'); // Check authentication method first - evidence collection requires access token or OIDC const credentials = Utils.collectJfrogCredentialsFromEnvVars(); @@ -35,7 +35,6 @@ export async function collectEvidences() { // Check if evidence collection is supported by the server const evidenceConfig = await getEvidenceConfiguration(); if (!evidenceConfig.external_evidence_collection_supported) { - core.info("Evidence collection is not supported by Artifactory's license type. Skipping evidence collection."); return; } @@ -96,13 +95,26 @@ async function getEvidenceConfiguration(): Promise { return { external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0 }; } + // 200 OK if (response.message.statusCode !== 200) { - core.warning(`Failed to get evidence configuration. Status: ${response.message.statusCode}, Response: ${body}`); + // 401 Unauthorized + if (response.message.statusCode === 401) { + core.warning( + `Failed to get evidence configuration. Given credentials are not sufficient` + + ` to create evidence in the JFrog platform, Response: ${body}`, + ); + } else { + core.warning(`Failed to get evidence configuration. Status: ${response.message.statusCode}, Response: ${body}`); + } + return { external_evidence_collection_supported: false, evidence_file_size_limit_mb: 0 }; } try { const config: EvidenceConfigResponse = JSON.parse(body); + if (!config.external_evidence_collection_supported) { + core.info("Evidence collection is not supported by Artifactory's license type. Skipping evidence collection."); + } return config; } catch (error) { core.warning(`Failed to parse evidence config response: ${error}`); @@ -142,6 +154,11 @@ export async function getSigstoreBundlePaths(): Promise { } core.info(`Found ${filePaths.length} sigstore bundle file(s) to process.`); + if (core.isDebug()) { + filePaths.forEach((filePath) => { + core.debug(`Sigstore bundle file found: ${filePath}`); + }); + } return filePaths; } diff --git a/src/utils.ts b/src/utils.ts index 54ff88dfe..e6e82bd6f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -273,6 +273,9 @@ export class Utils { } public static setCliEnv() { + if (core.isDebug()) { + Utils.exportVariableIfNotSet('JFROG_CLI_LOG_LEVEL', 'DEBUG'); + } Utils.exportVariableIfNotSet( 'JFROG_CLI_ENV_EXCLUDE', '*password*;*secret*;*key*;*token*;*auth*;JF_ARTIFACTORY_*;JF_ENV_*;JF_URL;JF_USER;JF_PASSWORD;JF_ACCESS_TOKEN', @@ -418,6 +421,7 @@ export class Utils { * @throws An error if the JFrog CLI command exits with a non-success code. */ public static async runCliAndGetOutput(args: string[], options?: ExecOptions): Promise { + core.debug(`jf ${args.join(' ')}`); let output: ExecOutput; output = await getExecOutput('jf', args, { ...options, ignoreReturnCode: true }); if (output.exitCode !== core.ExitCode.Success) {