@@ -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 YAML = __importStar ( require ( "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,34 @@ class Utils {
8587 }
8688 } ) ;
8789 }
90+ static getApplicationKey ( ) {
91+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
92+ const appKey = core . getInput ( Utils . APPLICATION_KEY ) ;
93+ if ( appKey ) {
94+ return appKey ;
95+ }
96+ const configFilePath = path . join ( this . FROGBOT_CONFIG_DIR_NAME , this . FROGBOT_CONFIG_FILE ) ;
97+ try {
98+ const config = yield this . readConfigFromFileSystem ( configFilePath ) ;
99+ if ( ! config ) {
100+ console . log ( 'Config file is empty or not found.' ) ;
101+ return '' ;
102+ }
103+ const configObj = YAML . parse ( config ) ;
104+ const applicationKey = configObj [ 'application-key' ] ;
105+ if ( ! applicationKey ) {
106+ console . log ( 'Application key is not found in the config file.' ) ;
107+ return '' ;
108+ }
109+ console . log ( 'Found application key: ' + applicationKey ) ;
110+ return applicationKey ;
111+ }
112+ catch ( error ) {
113+ console . log ( 'Error reading config:' , error ) ;
114+ return '' ;
115+ }
116+ } ) ;
117+ }
88118 /**
89119 * Gathers JFrog's credentials from environment variables and delivers them in a JfrogCredentials structure
90120 * @returns JfrogCredentials struct with all credentials found in environment variables
@@ -117,9 +147,10 @@ class Utils {
117147 * @param jfrogCredentials existing JFrog credentials - url, access token, username + password
118148 * @param jsonWebToken JWT achieved from GitHub JWT provider
119149 * @param oidcProviderName OIDC provider name
150+ * @param applicationKey
120151 * @returns an access token for the requested Artifactory server
121152 */
122- static getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName ) {
153+ static getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName , applicationKey ) {
123154 return __awaiter ( this , void 0 , void 0 , function * ( ) {
124155 // If we've reached this stage, the jfrogCredentials.jfrogUrl field should hold a non-empty value obtained from process.env.JF_URL
125156 const exchangeUrl = jfrogCredentials . jfrogUrl . replace ( / \/ $ / , '' ) + '/access/api/v1/oidc/token' ;
@@ -135,7 +166,8 @@ class Utils {
135166 "provider_name": "${ oidcProviderName } ",
136167 "project_key": "${ projectKey } ",
137168 "gh_job_id": "${ jobId } ",
138- "gh_run_id": "${ runId } "
169+ "gh_run_id": "${ runId } ",
170+ "application_key": "${ applicationKey } "
139171 }` ;
140172 const additionalHeaders = {
141173 'Content-Type' : 'application/json' ,
@@ -613,6 +645,17 @@ class Utils {
613645 return yield this . compressAndEncodeSarif ( sarif ) ;
614646 } ) ;
615647 }
648+ static readConfigFromFileSystem ( configRelativePath ) {
649+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
650+ core . debug ( `Reading config from file system. Looking for ${ configRelativePath } ` ) ;
651+ if ( ! ( 0 , fs_1 . existsSync ) ( configRelativePath ) ) {
652+ core . debug ( `cli-config.yml not found in ${ configRelativePath } ` ) ;
653+ return '' ;
654+ }
655+ core . debug ( `cli-config.yml found in ${ configRelativePath } ` ) ;
656+ return yield fs_1 . promises . readFile ( configRelativePath , 'utf-8' ) ;
657+ } ) ;
658+ }
616659 static readMarkdownContent ( ) {
617660 return __awaiter ( this , void 0 , void 0 , function * ( ) {
618661 const markdownFilePath = path . join ( Utils . getJobOutputDirectoryPath ( ) , 'markdown.md' ) ;
@@ -749,6 +792,12 @@ Utils.CLI_REMOTE_ARG = 'download-repository';
749792Utils . OIDC_AUDIENCE_ARG = 'oidc-audience' ;
750793// OpenID Connect provider_name input
751794Utils . OIDC_INTEGRATION_PROVIDER_NAME = 'oidc-provider-name' ;
795+ // Application id to associate entities
796+ Utils . APPLICATION_KEY = 'application-key' ;
797+ // Config file directory name
798+ Utils . FROGBOT_CONFIG_DIR_NAME = '.frogbot' ;
799+ // Config file name
800+ Utils . FROGBOT_CONFIG_FILE = 'frogbot-config.yml' ;
752801// Disable Job Summaries feature flag
753802Utils . JOB_SUMMARY_DISABLE = 'disable-job-summary' ;
754803// Disable auto build info publish feature flag
0 commit comments