From aa6e2e3f0c6daa7149a0a6b78a61a41e6e4b3ed4 Mon Sep 17 00:00:00 2001 From: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:17:38 -0700 Subject: [PATCH 1/6] Don't concatenate the string arguments. Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/gcp_auth.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/gcp_auth.ts b/src/gcp_auth.ts index a8277d84eee..7684912c8e7 100644 --- a/src/gcp_auth.ts +++ b/src/gcp_auth.ts @@ -66,17 +66,13 @@ export class GoogleCloudPlatformAuth implements Authenticator { if (!cmd) { throw new Error('Token is expired!'); } - // Wrap cmd in quotes to make it cope with spaces in path - cmd = `"${cmd}"`; - const args = config['cmd-args']; - if (args) { - cmd = cmd + ' ' + args; - } + const cmdPath = config['cmd-path']; + const args = config['cmd-args'] ? config['cmd-args'].split(' ') : []; // TODO: Cache to file? // TODO: do this asynchronously let output: any; try { - output = proc.execSync(cmd); + output = proc.execFileSync(cmdPath, args); } catch (err) { throw new Error('Failed to refresh token: ' + (err as Error).message); } From b71235e59d8204b2eec19721917730998aa4c690 Mon Sep 17 00:00:00 2001 From: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:25:54 +0000 Subject: [PATCH 2/6] Fix up generated code. --- src/gcp_auth.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gcp_auth.ts b/src/gcp_auth.ts index 7684912c8e7..3183eaaa1c4 100644 --- a/src/gcp_auth.ts +++ b/src/gcp_auth.ts @@ -66,13 +66,12 @@ export class GoogleCloudPlatformAuth implements Authenticator { if (!cmd) { throw new Error('Token is expired!'); } - const cmdPath = config['cmd-path']; const args = config['cmd-args'] ? config['cmd-args'].split(' ') : []; // TODO: Cache to file? // TODO: do this asynchronously let output: any; try { - output = proc.execFileSync(cmdPath, args); + output = proc.execFileSync(cmd, args); } catch (err) { throw new Error('Failed to refresh token: ' + (err as Error).message); } From 5bd0d923e5a95247efcac1aea87f0e7c65d8ef7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Fri, 25 Oct 2024 08:52:43 +0000 Subject: [PATCH 3/6] fix : test --- src/gcp_auth.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gcp_auth.ts b/src/gcp_auth.ts index 3183eaaa1c4..719a49d9f94 100644 --- a/src/gcp_auth.ts +++ b/src/gcp_auth.ts @@ -76,6 +76,10 @@ export class GoogleCloudPlatformAuth implements Authenticator { throw new Error('Failed to refresh token: ' + (err as Error).message); } + // remove leading and trailing `'` from the output + output = output.toString(); + output = output.replace(/'/g, ''); + output = output.replace(/\'$/, ''); const resultObj = JSON.parse(output); const tokenPathKeyInConfig = config['token-key']; From c018ad82d79dd45dd6e625d78937181531ce6891 Mon Sep 17 00:00:00 2001 From: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:24:12 +0000 Subject: [PATCH 4/6] Fix up generated code. --- src/gcp_auth.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gcp_auth.ts b/src/gcp_auth.ts index 719a49d9f94..40ab1b1f746 100644 --- a/src/gcp_auth.ts +++ b/src/gcp_auth.ts @@ -66,7 +66,14 @@ export class GoogleCloudPlatformAuth implements Authenticator { if (!cmd) { throw new Error('Token is expired!'); } - const args = config['cmd-args'] ? config['cmd-args'].split(' ') : []; + const args = (config['cmd-args'] ? config['cmd-args'].split(' ') : []).map( + (arg: string): string => { + if (arg[0] == '\'' || arg[0] == '"') { + return arg.substring(1, arg.length-1); + } + return arg; + } + ); // TODO: Cache to file? // TODO: do this asynchronously let output: any; From 741ac4204bef9ca49d8ecbda00648be6fb31d579 Mon Sep 17 00:00:00 2001 From: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:26:01 +0000 Subject: [PATCH 5/6] Revert initial fix --- src/gcp_auth.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/gcp_auth.ts b/src/gcp_auth.ts index 40ab1b1f746..8d012d82426 100644 --- a/src/gcp_auth.ts +++ b/src/gcp_auth.ts @@ -83,10 +83,6 @@ export class GoogleCloudPlatformAuth implements Authenticator { throw new Error('Failed to refresh token: ' + (err as Error).message); } - // remove leading and trailing `'` from the output - output = output.toString(); - output = output.replace(/'/g, ''); - output = output.replace(/\'$/, ''); const resultObj = JSON.parse(output); const tokenPathKeyInConfig = config['token-key']; From bc4faeb62c17c18b2a09f9e24368a672fd535081 Mon Sep 17 00:00:00 2001 From: Brendan Burns <5751682+brendandburns@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:28:27 +0000 Subject: [PATCH 6/6] fix style --- src/gcp_auth.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/gcp_auth.ts b/src/gcp_auth.ts index 8d012d82426..3acf53bd9eb 100644 --- a/src/gcp_auth.ts +++ b/src/gcp_auth.ts @@ -62,18 +62,16 @@ export class GoogleCloudPlatformAuth implements Authenticator { } private updateAccessToken(config: Config): void { - let cmd = config['cmd-path']; + const cmd = config['cmd-path']; if (!cmd) { throw new Error('Token is expired!'); } - const args = (config['cmd-args'] ? config['cmd-args'].split(' ') : []).map( - (arg: string): string => { - if (arg[0] == '\'' || arg[0] == '"') { - return arg.substring(1, arg.length-1); - } - return arg; + const args = (config['cmd-args'] ? config['cmd-args'].split(' ') : []).map((arg: string): string => { + if (arg[0] === "'" || arg[0] === '"') { + return arg.substring(1, arg.length - 1); } - ); + return arg; + }); // TODO: Cache to file? // TODO: do this asynchronously let output: any;