@@ -33,28 +33,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3333} ;
3434Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3535exports . collectEvidences = collectEvidences ;
36+ exports . getSigstoreBundlePaths = getSigstoreBundlePaths ;
3637const core = __importStar ( require ( "@actions/core" ) ) ;
3738const utils_1 = require ( "./utils" ) ;
3839const http_client_1 = require ( "@actions/http-client" ) ;
3940const fs_1 = require ( "fs" ) ;
4041const path = __importStar ( require ( "path" ) ) ;
4142/**
4243 * Collects evidences from the current workflow.
43- * This function first checks if evidence collection is supported by the Artifactory server.
44+ * This function first checks if attestation files exist, then checks if evidence collection is supported by the Artifactory server.
4445 */
4546function collectEvidences ( ) {
4647 return __awaiter ( this , void 0 , void 0 , function * ( ) {
48+ var _a ;
4749 try {
4850 core . startGroup ( 'Collecting evidences' ) ;
51+ // Check authentication method first - evidence collection requires access token or OIDC
52+ const credentials = utils_1 . Utils . collectJfrogCredentialsFromEnvVars ( ) ;
53+ if ( ! credentials . accessToken && ! credentials . oidcProviderName && ( credentials . username || credentials . password ) ) {
54+ core . info ( 'Evidence collection does not support authentication with username and password. Skipping evidence collection.' ) ;
55+ return ;
56+ }
57+ // Check if attestation files exist first to fail fast
58+ const filePaths = yield getSigstoreBundlePaths ( ) ;
59+ if ( filePaths . length === 0 ) {
60+ return ;
61+ }
4962 // Check if evidence collection is supported by the server
5063 const evidenceConfig = yield getEvidenceConfiguration ( ) ;
5164 if ( ! evidenceConfig . external_evidence_collection_supported ) {
52- core . info ( ' Evidence collection is not supported by this Artifactory server . Skipping evidence collection.' ) ;
65+ core . info ( " Evidence collection is not supported by Artifactory's license type . Skipping evidence collection." ) ;
5366 return ;
5467 }
55- core . info ( `Evidence collection is supported. Maximum file size: ${ evidenceConfig . max_evidence_file_size_mb } MB` ) ;
56- // Read sigstore bundle file paths and create evidence for each
57- yield createEvidenceFromSigstoreBundles ( evidenceConfig . max_evidence_file_size_mb ) ;
68+ // Use a default limit if the server doesn't provide one
69+ const maxFileSizeMB = ( _a = evidenceConfig . evidence_file_size_limit_mb ) !== null && _a !== void 0 ? _a : 16 ;
70+ core . info ( `Evidence collection is supported. Maximum file size: ${ maxFileSizeMB } MB` ) ;
71+ // Create evidence for each sigstore bundle file
72+ yield createEvidenceFromSigstoreBundles ( maxFileSizeMB , filePaths ) ;
5873 }
5974 catch ( error ) {
6075 core . warning ( 'Failed while attempting to collect evidences: ' + error ) ;
@@ -76,19 +91,21 @@ function getEvidenceConfiguration() {
7691 }
7792 // Get access token for authentication
7893 let accessToken = credentials . accessToken ;
94+ // Try to get access token if not available
7995 if ( ! accessToken && credentials . oidcProviderName ) {
8096 // Import OidcUtils dynamically to avoid circular dependency
8197 const { OidcUtils } = yield Promise . resolve ( ) . then ( ( ) => __importStar ( require ( './oidc-utils' ) ) ) ;
8298 accessToken = yield OidcUtils . exchangeOidcToken ( credentials ) ;
8399 }
100+ // Check if we have access token available
84101 if ( ! accessToken ) {
85- throw new Error ( 'No access token available for authentication' ) ;
102+ throw new Error ( 'No access token available for authentication. Evidence collection requires access token authentication. ' ) ;
86103 }
87104 // Remove trailing slash from jfrogUrl to avoid double slashes when appending the API path
88105 const url = `${ credentials . jfrogUrl . replace ( / \/ $ / , '' ) } /evidence/api/v1/config/` ;
89106 const httpClient = new http_client_1 . HttpClient ( ) ;
90107 const headers = {
91- ' Authorization' : `Bearer ${ accessToken } ` ,
108+ Authorization : `Bearer ${ accessToken } ` ,
92109 } ;
93110 core . debug ( `Getting evidence configuration at: ${ url } ` ) ;
94111 let response ;
@@ -99,33 +116,32 @@ function getEvidenceConfiguration() {
99116 }
100117 catch ( error ) {
101118 core . warning ( `Failed to get evidence configuration (network error or server unavailable): ${ error } ` ) ;
102- return { external_evidence_collection_supported : false , max_evidence_file_size_mb : 0 } ;
119+ return { external_evidence_collection_supported : false , evidence_file_size_limit_mb : 0 } ;
103120 }
104121 if ( response . message . statusCode !== 200 ) {
105122 core . warning ( `Failed to get evidence configuration. Status: ${ response . message . statusCode } , Response: ${ body } ` ) ;
106- return { external_evidence_collection_supported : false , max_evidence_file_size_mb : 0 } ;
123+ return { external_evidence_collection_supported : false , evidence_file_size_limit_mb : 0 } ;
107124 }
108125 try {
109126 const config = JSON . parse ( body ) ;
110127 return config ;
111128 }
112129 catch ( error ) {
113130 core . warning ( `Failed to parse evidence config response: ${ error } ` ) ;
114- return { external_evidence_collection_supported : false , max_evidence_file_size_mb : 0 } ;
131+ return { external_evidence_collection_supported : false , evidence_file_size_limit_mb : 0 } ;
115132 }
116133 } ) ;
117134}
118135/**
119- * Reads sigstore bundle file paths and creates evidence for each file.
120- * Reads from ${RUNNER_TEMP}/created_attestation_paths.txt
121- * @param maxFileSizeMB Maximum allowed file size in MB
136+ * Read and parse sigstore bundle file paths from the attestation paths file
137+ * @returns Array of file paths, or empty array if file doesn't exist or is empty
122138 */
123- function createEvidenceFromSigstoreBundles ( maxFileSizeMB ) {
139+ function getSigstoreBundlePaths ( ) {
124140 return __awaiter ( this , void 0 , void 0 , function * ( ) {
125141 const runnerTemp = process . env . RUNNER_TEMP ;
126142 if ( ! runnerTemp ) {
127143 core . warning ( 'RUNNER_TEMP environment variable is not set. Skipping evidence creation.' ) ;
128- return ;
144+ return [ ] ;
129145 }
130146 const attestationPathsFile = path . join ( runnerTemp , 'created_attestation_paths.txt' ) ;
131147 try {
@@ -134,17 +150,28 @@ function createEvidenceFromSigstoreBundles(maxFileSizeMB) {
134150 }
135151 catch ( error ) {
136152 core . info ( `No attestation paths file found. Skipping evidence creation. Searched for: ${ attestationPathsFile } . Error: ${ error } ` ) ;
137- return ;
153+ return [ ] ;
138154 }
139155 // Read the file content
140156 core . info ( `Reading attestation paths file: ${ attestationPathsFile } ` ) ;
141157 const fileContent = yield fs_1 . promises . readFile ( attestationPathsFile , 'utf8' ) ;
142- const filePaths = fileContent . split ( '\n' ) . filter ( line => line . trim ( ) !== '' ) ;
158+ const filePaths = fileContent . split ( '\n' ) . filter ( ( line ) => line . trim ( ) !== '' ) ;
143159 if ( filePaths . length === 0 ) {
144160 core . info ( 'No sigstore bundle files found in attestation paths file.' ) ;
145- return ;
161+ return [ ] ;
146162 }
147163 core . info ( `Found ${ filePaths . length } sigstore bundle file(s) to process.` ) ;
164+ return filePaths ;
165+ } ) ;
166+ }
167+
168+ /**
169+ * Creates evidence for sigstore bundle files.
170+ * @param maxFileSizeMB Maximum allowed file size in MB
171+ * @param filePaths Array of file paths to process
172+ */
173+ function createEvidenceFromSigstoreBundles ( maxFileSizeMB , filePaths ) {
174+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
148175 for ( const filePath of filePaths ) {
149176 try {
150177 const fileStats = yield fs_1 . promises . stat ( filePath ) ;
@@ -154,7 +181,7 @@ function createEvidenceFromSigstoreBundles(maxFileSizeMB) {
154181 continue ;
155182 }
156183 core . info ( `Creating evidence for: ${ filePath } ` ) ;
157- const output = yield utils_1 . Utils . runCliAndGetOutput ( [ 'evd' , 'create' , '--sigstore-bundle' , filePath ] ) ;
184+ const output = yield utils_1 . Utils . runCliAndGetOutput ( [ 'evd' , 'create' , '--sigstore-bundle' , filePath , '--provider-id' , 'github' ] ) ;
158185 core . info ( `Evidence created successfully for ${ filePath } : ${ output } ` ) ;
159186 }
160187 catch ( error ) {
0 commit comments