Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Jan 3, 2024
1 parent 6708971 commit 80c4341
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function main() {
try {
core.startGroup('Setup JFrog CLI');
utils_1.Utils.setCliEnv();
console.log("ERAN CHECK: ####################### 29 #######################"); // TODO del
let accessToken = yield utils_1.Utils.getJfrogAccessToken();
console.log("ERAN CHECK: ####################### 30 #######################"); // TODO del
let accessToken = yield utils_1.Utils.getJfrogAccessToken(); //TODO make it return a struct with: username, password and access_token, jfrog url
console.log(`ERAN CHECK: finished access token flow with access token: ${accessToken}`); // TODO del
yield utils_1.Utils.getAndAddCliToPath();
yield utils_1.Utils.configJFrogServers();
Expand Down
9 changes: 6 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ class Utils {
let jsonWebToken;
try {
console.log("Fetching JSON web token");
jsonWebToken = yield core.getIDToken();
jsonWebToken = yield core.getIDToken(audience); // print char 1-10 and 11-end and add them app (try to laavod on actions)
console.log("ERAN CHECK - token part 1: " + jsonWebToken.substring(0, 10));
console.log("ERAN CHECK - token part 2: " + jsonWebToken.substring(11));
}
catch (error) {
throw new Error(`getting openID Connect JSON web token failed: ${error.message}`);
}
// todo del
const decodedJwt2 = jwt_decode.jwtDecode(jsonWebToken);
console.log(`ERAN CHECK: JWT 2 content: \n aud: ${decodedJwt2.aud} | sub: ${decodedJwt2.sub} | iss: ${decodedJwt2.aud}`);
console.log(`ERAN CHECK: JWT 2 content: \n aud: ${decodedJwt2.aud} | sub: ${decodedJwt2.sub} | iss: ${decodedJwt2.iss}`);
// todo up to here
try {
return yield this.getAccessTokenFromJWT(basicUrl, jsonWebToken);
Expand Down Expand Up @@ -211,6 +213,7 @@ class Utils {
* @name user&password - JFrog Platform basic authentication
* @name accessToken - Jfrog Platform access token
*/
//TODO replace env vars with structs fields
let url = process.env.JF_URL;
let user = process.env.JF_USER;
let password = process.env.JF_PASSWORD;
Expand Down Expand Up @@ -320,7 +323,6 @@ class Utils {
if (repository === '') {
return Utils.DEFAULT_DOWNLOAD_DETAILS;
}
// TODO: we enter here if we have no internet connection..
let results = { repository: repository };
let serverObj = {};
for (let configToken of Utils.getConfigTokens()) {
Expand All @@ -336,6 +338,7 @@ class Utils {
`Hint - Ensure that the JFrog connection details environment variables are set: ` +
`either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)`);
}
//TODO instead of env vars use the struct
serverObj.artifactoryUrl = process.env.JF_URL.replace(/\/$/, '') + '/artifactory';
serverObj.user = process.env.JF_USER;
serverObj.password = process.env.JF_PASSWORD;
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ async function main() {
try {
core.startGroup('Setup JFrog CLI');
Utils.setCliEnv();
console.log("ERAN CHECK: ####################### 29 #######################") // TODO del
let accessToken :string = await Utils.getJfrogAccessToken()
console.log("ERAN CHECK: ####################### 30 #######################") // TODO del
let accessToken :string = await Utils.getJfrogAccessToken() //TODO make it return a struct with: username, password and access_token, jfrog url
console.log(`ERAN CHECK: finished access token flow with access token: ${accessToken}`) // TODO del
await Utils.getAndAddCliToPath();
await Utils.configJFrogServers();
Expand Down
13 changes: 8 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,29 @@ export class Utils {
*/
public static async getJfrogAccessToken(): Promise<string> {
if(!process.env.JF_URL) {
return ""
return "";
}

let basicUrl : string = process.env.JF_URL
console.log("Searching for JF_ACCESS_TOKEN or JF_USER + JF_PASSWORD in exising env variables")
if(process.env.JF_ACCESS_TOKEN || (process.env.JF_USER && process.env.JF_PASSWORD)) {
return ""
return "";
}
console.log("JF_ACCESS_TOKEN and JF_USER + JF_PASSWORD weren't found. Getting access token using OpenID Connect")
const audience: string = core.getInput(Utils.OIDC_AUDIENCE_ARG, { required: false });
let jsonWebToken: string | undefined
try {
console.log("Fetching JSON web token")
jsonWebToken = await core.getIDToken();
jsonWebToken = await core.getIDToken(audience); // print char 1-10 and 11-end and add them app (try to laavod on actions)
console.log("ERAN CHECK - token part 1: " + jsonWebToken.substring(0,10))
console.log("ERAN CHECK - token part 2: " + jsonWebToken.substring(11))
} catch (error: any){
throw new Error(`getting openID Connect JSON web token failed: ${error.message}`)
}

// todo del
const decodedJwt2 = jwt_decode.jwtDecode(jsonWebToken)
console.log(`ERAN CHECK: JWT 2 content: \n aud: ${decodedJwt2.aud} | sub: ${decodedJwt2.sub} | iss: ${decodedJwt2.aud}`)
console.log(`ERAN CHECK: JWT 2 content: \n aud: ${decodedJwt2.aud} | sub: ${decodedJwt2.sub} | iss: ${decodedJwt2.iss}`)
// todo up to here

try {
Expand Down Expand Up @@ -228,6 +230,7 @@ export class Utils {
* @name user&password - JFrog Platform basic authentication
* @name accessToken - Jfrog Platform access token
*/
//TODO replace env vars with structs fields
let url: string | undefined = process.env.JF_URL;
let user: string | undefined = process.env.JF_USER;
let password: string | undefined = process.env.JF_PASSWORD;
Expand Down Expand Up @@ -347,7 +350,6 @@ export class Utils {
if (repository === '') {
return Utils.DEFAULT_DOWNLOAD_DETAILS;
}
// TODO: we enter here if we have no internet connection..
let results: DownloadDetails = { repository: repository } as DownloadDetails;
let serverObj: any = {};

Expand All @@ -366,6 +368,7 @@ export class Utils {
`either a Config Token with a JF_ENV_ prefix or separate env config (JF_URL, JF_USER, JF_PASSWORD, JF_ACCESS_TOKEN)`,
);
}
//TODO instead of env vars use the struct
serverObj.artifactoryUrl = process.env.JF_URL.replace(/\/$/, '') + '/artifactory';
serverObj.user = process.env.JF_USER;
serverObj.password = process.env.JF_PASSWORD;
Expand Down

0 comments on commit 80c4341

Please sign in to comment.