Skip to content

Commit 55598d2

Browse files
committed
test
1 parent a48d696 commit 55598d2

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

lib/utils.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,7 @@ class Utils {
316316
core.info('calling EOT ! ');
317317
let output = yield (0, exec_1.getExecOutput)('jf', ['eot', oidcProviderName, oidcTokenId, '--url', url, '--oidc-audience', oidcAudience], { silent: true, ignoreReturnCode: true });
318318
let body;
319-
try {
320-
core.info('Attempting to decode JSON response...');
321-
core.info(output.stdout);
322-
body = JSON.parse(output.stdout);
323-
}
324-
catch (error) {
325-
throw new Error(`Failed to decode JSON response: ${error}`);
326-
}
319+
body = Utils.parseInvalidObject(output);
327320
// Sets the OIDC token as access token to be used in config.
328321
core.info('setting as secret');
329322
core.setSecret('oidc-token');
@@ -345,6 +338,18 @@ class Utils {
345338
return configCmd;
346339
});
347340
}
341+
static parseInvalidObject(input) {
342+
// Add double quotes around keys and string values
343+
const validJson = input
344+
.replace(/(\w+)\s*:/g, '"$1":') // Add quotes around keys
345+
.replace(/:\s*([\w]+)/g, ': "$1"'); // Add quotes around string values
346+
try {
347+
return JSON.parse(validJson);
348+
}
349+
catch (error) {
350+
throw new Error(`Failed to parse object: ${error}`);
351+
}
352+
}
348353
/**
349354
* Get server ID for JFrog CLI configuration. Save the server ID in the servers env var if it doesn't already exist.
350355
*/

src/utils.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,7 @@ export class Utils {
390390
{ silent: true, ignoreReturnCode: true },
391391
);
392392
let body: any;
393-
try {
394-
core.info('Attempting to decode JSON response...');
395-
core.info(output.stdout);
396-
body = JSON.parse(output.stdout);
397-
} catch (error) {
398-
throw new Error(`Failed to decode JSON response: ${error}`);
399-
}
393+
body = Utils.parseInvalidObject(output);
400394
// Sets the OIDC token as access token to be used in config.
401395
core.info('setting as secret');
402396
core.setSecret('oidc-token');
@@ -418,6 +412,19 @@ export class Utils {
418412
return configCmd;
419413
}
420414

415+
private static parseInvalidObject(input: any): any {
416+
// Add double quotes around keys and string values
417+
const validJson:string = input
418+
.replace(/(\w+)\s*:/g, '"$1":') // Add quotes around keys
419+
.replace(/:\s*([\w]+)/g, ': "$1"'); // Add quotes around string values
420+
421+
try {
422+
return JSON.parse(validJson);
423+
} catch (error) {
424+
throw new Error(`Failed to parse object: ${error}`);
425+
}
426+
}
427+
421428
/**
422429
* Get server ID for JFrog CLI configuration. Save the server ID in the servers env var if it doesn't already exist.
423430
*/

0 commit comments

Comments
 (0)