Skip to content

Commit 0187268

Browse files
author
Sahar Bracha
committed
Support application key
1 parent e7cc33a commit 0187268

File tree

240 files changed

+18804
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+18804
-9
lines changed

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ inputs:
2323
description: "By default, if the workflow completes with collected build-info that has not been published using the jf rt build-publish command, the build-info will be automatically published to Artifactory. Set this to true to disable the automatic publication of build-info at the end of the workflow."
2424
default: "false"
2525
required: false
26+
application-key:
27+
description: "Application key to associate packages with."
28+
required: false
2629
outputs:
2730
oidc-token:
2831
description: "JFrog OIDC token generated by the Setup JFrog CLI when setting oidc-provider-name."

lib/utils.js

+52-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const core_1 = require("@octokit/core");
4646
const github = __importStar(require("@actions/github"));
4747
const zlib_1 = require("zlib");
4848
const util_1 = require("util");
49+
const YAML = __importStar(require("yaml"));
4950
class 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';
749792
Utils.OIDC_AUDIENCE_ARG = 'oidc-audience';
750793
// OpenID Connect provider_name input
751794
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';
752801
// Disable Job Summaries feature flag
753802
Utils.JOB_SUMMARY_DISABLE = 'disable-job-summary';
754803
// Disable auto build info publish feature flag

node_modules/.bin/yaml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/yaml/LICENSE

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/yaml/README.md

+169
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/yaml/bin.mjs

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)