@@ -46,6 +46,7 @@ const core_1 = require("@octokit/core");
46
46
const github = __importStar ( require ( "@actions/github" ) ) ;
47
47
const zlib_1 = require ( "zlib" ) ;
48
48
const util_1 = require ( "util" ) ;
49
+ const YAML = __importStar ( require ( "yaml" ) ) ;
49
50
class Utils {
50
51
/**
51
52
* Retrieves server credentials for accessing JFrog's server
@@ -74,8 +75,9 @@ class Utils {
74
75
catch ( error ) {
75
76
throw new Error ( `Getting openID Connect JSON web token failed: ${ error . message } ` ) ;
76
77
}
78
+ const applicationKey = yield this . getApplicationKey ( ) ;
77
79
try {
78
- jfrogCredentials = yield this . getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName ) ;
80
+ jfrogCredentials = yield this . getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName , applicationKey ) ;
79
81
// Set environment variable to track OIDC logins in the usage report.
80
82
core . exportVariable ( 'JFROG_CLI_USAGE_CONFIG_OIDC' , 'TRUE' ) ;
81
83
return jfrogCredentials ;
@@ -85,6 +87,34 @@ class Utils {
85
87
}
86
88
} ) ;
87
89
}
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
+ }
88
118
/**
89
119
* Gathers JFrog's credentials from environment variables and delivers them in a JfrogCredentials structure
90
120
* @returns JfrogCredentials struct with all credentials found in environment variables
@@ -117,9 +147,10 @@ class Utils {
117
147
* @param jfrogCredentials existing JFrog credentials - url, access token, username + password
118
148
* @param jsonWebToken JWT achieved from GitHub JWT provider
119
149
* @param oidcProviderName OIDC provider name
150
+ * @param applicationKey
120
151
* @returns an access token for the requested Artifactory server
121
152
*/
122
- static getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName ) {
153
+ static getJfrogAccessTokenThroughOidcProtocol ( jfrogCredentials , jsonWebToken , oidcProviderName , applicationKey ) {
123
154
return __awaiter ( this , void 0 , void 0 , function * ( ) {
124
155
// If we've reached this stage, the jfrogCredentials.jfrogUrl field should hold a non-empty value obtained from process.env.JF_URL
125
156
const exchangeUrl = jfrogCredentials . jfrogUrl . replace ( / \/ $ / , '' ) + '/access/api/v1/oidc/token' ;
@@ -135,7 +166,8 @@ class Utils {
135
166
"provider_name": "${ oidcProviderName } ",
136
167
"project_key": "${ projectKey } ",
137
168
"gh_job_id": "${ jobId } ",
138
- "gh_run_id": "${ runId } "
169
+ "gh_run_id": "${ runId } ",
170
+ "application_key": "${ applicationKey } "
139
171
}` ;
140
172
const additionalHeaders = {
141
173
'Content-Type' : 'application/json' ,
@@ -613,6 +645,17 @@ class Utils {
613
645
return yield this . compressAndEncodeSarif ( sarif ) ;
614
646
} ) ;
615
647
}
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
+ }
616
659
static readMarkdownContent ( ) {
617
660
return __awaiter ( this , void 0 , void 0 , function * ( ) {
618
661
const markdownFilePath = path . join ( Utils . getJobOutputDirectoryPath ( ) , 'markdown.md' ) ;
@@ -749,6 +792,12 @@ Utils.CLI_REMOTE_ARG = 'download-repository';
749
792
Utils . OIDC_AUDIENCE_ARG = 'oidc-audience' ;
750
793
// OpenID Connect provider_name input
751
794
Utils . 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' ;
752
801
// Disable Job Summaries feature flag
753
802
Utils . JOB_SUMMARY_DISABLE = 'disable-job-summary' ;
754
803
// Disable auto build info publish feature flag
0 commit comments