@@ -33,28 +33,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
} ;
34
34
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
35
35
exports . collectEvidences = collectEvidences ;
36
+ exports . getSigstoreBundlePaths = getSigstoreBundlePaths ;
36
37
const core = __importStar ( require ( "@actions/core" ) ) ;
37
38
const utils_1 = require ( "./utils" ) ;
38
39
const http_client_1 = require ( "@actions/http-client" ) ;
39
40
const fs_1 = require ( "fs" ) ;
40
41
const path = __importStar ( require ( "path" ) ) ;
41
42
/**
42
43
* 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.
44
45
*/
45
46
function collectEvidences ( ) {
46
47
return __awaiter ( this , void 0 , void 0 , function * ( ) {
48
+ var _a ;
47
49
try {
48
50
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
+ }
49
62
// Check if evidence collection is supported by the server
50
63
const evidenceConfig = yield getEvidenceConfiguration ( ) ;
51
64
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." ) ;
53
66
return ;
54
67
}
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 ) ;
58
73
}
59
74
catch ( error ) {
60
75
core . warning ( 'Failed while attempting to collect evidences: ' + error ) ;
@@ -76,19 +91,21 @@ function getEvidenceConfiguration() {
76
91
}
77
92
// Get access token for authentication
78
93
let accessToken = credentials . accessToken ;
94
+ // Try to get access token if not available
79
95
if ( ! accessToken && credentials . oidcProviderName ) {
80
96
// Import OidcUtils dynamically to avoid circular dependency
81
97
const { OidcUtils } = yield Promise . resolve ( ) . then ( ( ) => __importStar ( require ( './oidc-utils' ) ) ) ;
82
98
accessToken = yield OidcUtils . exchangeOidcToken ( credentials ) ;
83
99
}
100
+ // Check if we have access token available
84
101
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. ' ) ;
86
103
}
87
104
// Remove trailing slash from jfrogUrl to avoid double slashes when appending the API path
88
105
const url = `${ credentials . jfrogUrl . replace ( / \/ $ / , '' ) } /evidence/api/v1/config/` ;
89
106
const httpClient = new http_client_1 . HttpClient ( ) ;
90
107
const headers = {
91
- ' Authorization' : `Bearer ${ accessToken } ` ,
108
+ Authorization : `Bearer ${ accessToken } ` ,
92
109
} ;
93
110
core . debug ( `Getting evidence configuration at: ${ url } ` ) ;
94
111
let response ;
@@ -99,33 +116,32 @@ function getEvidenceConfiguration() {
99
116
}
100
117
catch ( error ) {
101
118
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 } ;
103
120
}
104
121
if ( response . message . statusCode !== 200 ) {
105
122
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 } ;
107
124
}
108
125
try {
109
126
const config = JSON . parse ( body ) ;
110
127
return config ;
111
128
}
112
129
catch ( error ) {
113
130
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 } ;
115
132
}
116
133
} ) ;
117
134
}
118
135
/**
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
122
138
*/
123
- function createEvidenceFromSigstoreBundles ( maxFileSizeMB ) {
139
+ function getSigstoreBundlePaths ( ) {
124
140
return __awaiter ( this , void 0 , void 0 , function * ( ) {
125
141
const runnerTemp = process . env . RUNNER_TEMP ;
126
142
if ( ! runnerTemp ) {
127
143
core . warning ( 'RUNNER_TEMP environment variable is not set. Skipping evidence creation.' ) ;
128
- return ;
144
+ return [ ] ;
129
145
}
130
146
const attestationPathsFile = path . join ( runnerTemp , 'created_attestation_paths.txt' ) ;
131
147
try {
@@ -134,17 +150,28 @@ function createEvidenceFromSigstoreBundles(maxFileSizeMB) {
134
150
}
135
151
catch ( error ) {
136
152
core . info ( `No attestation paths file found. Skipping evidence creation. Searched for: ${ attestationPathsFile } . Error: ${ error } ` ) ;
137
- return ;
153
+ return [ ] ;
138
154
}
139
155
// Read the file content
140
156
core . info ( `Reading attestation paths file: ${ attestationPathsFile } ` ) ;
141
157
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 ( ) !== '' ) ;
143
159
if ( filePaths . length === 0 ) {
144
160
core . info ( 'No sigstore bundle files found in attestation paths file.' ) ;
145
- return ;
161
+ return [ ] ;
146
162
}
147
163
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 * ( ) {
148
175
for ( const filePath of filePaths ) {
149
176
try {
150
177
const fileStats = yield fs_1 . promises . stat ( filePath ) ;
@@ -154,7 +181,7 @@ function createEvidenceFromSigstoreBundles(maxFileSizeMB) {
154
181
continue ;
155
182
}
156
183
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' ] ) ;
158
185
core . info ( `Evidence created successfully for ${ filePath } : ${ output } ` ) ;
159
186
}
160
187
catch ( error ) {
0 commit comments