@@ -46,6 +46,7 @@ const core_1 = require("@octokit/core");
4646const github = __importStar ( require ( "@actions/github" ) ) ;
4747const zlib_1 = require ( "zlib" ) ;
4848const util_1 = require ( "util" ) ;
49+ const js_yaml_1 = require ( "js-yaml" ) ;
4950class Utils {
5051 /**
5152 * Retrieves server credentials for accessing JFrog's server
@@ -74,8 +75,9 @@ class Utils {
7475 catch ( error ) {
7576 throw new Error ( `Getting openID Connect JSON web token failed: ${ error . message } ` ) ;
7677 }
78+ const applicationKey = yield this . getApplicationKey ( ) ;
7779 try {
78- jfrogCredentials = yield this . getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName ) ;
80+ jfrogCredentials = yield this . getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName , applicationKey ) ;
7981 // Set environment variable to track OIDC logins in the usage report.
8082 core . exportVariable ( 'JFROG_CLI_USAGE_CONFIG_OIDC' , 'TRUE' ) ;
8183 return jfrogCredentials ;
@@ -85,6 +87,66 @@ class Utils {
8587 }
8688 } ) ;
8789 }
90+ /**
91+ * Retrieves the application key from input or .jfrog configuration file.
92+ *
93+ * This method attempts to retrieve the application key from the GitHub Action input.
94+ * If the input is not provided, it reads .jfrog configuration file from the file system.
95+ * If the configuration file exists and contains the application key, it returns the key.
96+ * If the configuration file does not exist or does not contain the application key, it returns an empty string.
97+ *
98+ * @returns A promise that resolves to the application key as a string.
99+ */
100+ static getApplicationKey ( ) {
101+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
102+ const configFilePath = path . join ( this . JF_CONFIG_DIR_NAME , this . JF_CONFIG_FILE ) ;
103+ try {
104+ const config = yield this . readConfigFromFileSystem ( configFilePath ) ;
105+ if ( ! config ) {
106+ console . debug ( 'Config file is empty or not found.' ) ;
107+ return '' ;
108+ }
109+ const configObj = ( 0 , js_yaml_1 . load ) ( config ) ;
110+ const application = configObj [ this . APPLICATION_ROOT_YML ] ;
111+ if ( ! application ) {
112+ console . log ( 'Application root is not found in the config file.' ) ;
113+ return '' ;
114+ }
115+ const applicationKey = application [ this . KEY ] ;
116+ if ( ! applicationKey ) {
117+ console . log ( 'Application key is not found in the config file.' ) ;
118+ return '' ;
119+ }
120+ console . debug ( 'Found application key: ' + applicationKey ) ;
121+ return applicationKey ;
122+ }
123+ catch ( error ) {
124+ console . error ( 'Error reading config:' , error ) ;
125+ return '' ;
126+ }
127+ } ) ;
128+ }
129+ /**
130+ * Reads .jfrog configuration file from file system.
131+ *
132+ * This method attempts to read .jfrog configuration file from the specified relative path.
133+ * If the file exists, it reads the file content and returns it as a string.
134+ * If the file does not exist, it returns an empty string.
135+ *
136+ * @param configRelativePath - The relative path to the configuration file.
137+ * @returns A promise that resolves to the content of the configuration file as a string.
138+ */
139+ static readConfigFromFileSystem ( configRelativePath ) {
140+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
141+ core . debug ( `Reading config from file system. Looking for ${ configRelativePath } ` ) ;
142+ if ( ! ( 0 , fs_1 . existsSync ) ( configRelativePath ) ) {
143+ core . debug ( `config.yml not found in ${ configRelativePath } ` ) ;
144+ return '' ;
145+ }
146+ core . debug ( `config.yml found in ${ configRelativePath } ` ) ;
147+ return yield fs_1 . promises . readFile ( configRelativePath , 'utf-8' ) ;
148+ } ) ;
149+ }
88150 /**
89151 * Gathers JFrog's credentials from environment variables and delivers them in a JfrogCredentials structure
90152 * @returns JfrogCredentials struct with all credentials found in environment variables
@@ -117,9 +179,10 @@ class Utils {
117179 * @param jfrogCredentials existing JFrog credentials - url, access token, username + password
118180 * @param jsonWebToken JWT achieved from GitHub JWT provider
119181 * @param oidcProviderName OIDC provider name
182+ * @param applicationKey
120183 * @returns an access token for the requested Artifactory server
121184 */
122- static getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName ) {
185+ static getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName , applicationKey ) {
123186 return __awaiter ( this , void 0 , void 0 , function * ( ) {
124187 // If we've reached this stage, the jfrogCredentials.jfrogUrl field should hold a non-empty value obtained from process.env.JF_URL
125188 const exchangeUrl = jfrogCredentials . jfrogUrl . replace ( / \/ $ / , '' ) + '/access/api/v1/oidc/token' ;
@@ -135,7 +198,8 @@ class Utils {
135198 "provider_name": "${ oidcProviderName } ",
136199 "project_key": "${ projectKey } ",
137200 "gh_job_id": "${ jobId } ",
138- "gh_run_id": "${ runId } "
201+ "gh_run_id": "${ runId } ",
202+ "application_key": "${ applicationKey } "
139203 }` ;
140204 const additionalHeaders = {
141205 'Content-Type' : 'application/json' ,
@@ -798,6 +862,16 @@ Utils.CLI_REMOTE_ARG = 'download-repository';
798862Utils . OIDC_AUDIENCE_ARG = 'oidc-audience' ;
799863// OpenID Connect provider_name input
800864Utils . OIDC_INTEGRATION_PROVIDER_NAME = 'oidc-provider-name' ;
865+ // Application yaml root key
866+ Utils . APPLICATION_ROOT_YML = 'application' ;
867+ // Application Config file key, yaml should look like:
868+ // application:
869+ // key: <application key>
870+ Utils . KEY = 'key' ;
871+ // Config file directory name
872+ Utils . JF_CONFIG_DIR_NAME = '.jfrog' ;
873+ // Config file name
874+ Utils . JF_CONFIG_FILE = 'config.yml' ;
801875// Disable Job Summaries feature flag
802876Utils . JOB_SUMMARY_DISABLE = 'disable-job-summary' ;
803877// Disable auto build info publish feature flag
0 commit comments