Skip to content

Commit 0055a50

Browse files
committed
Use child_process to execute command set as a single string
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 5ea50fd commit 0055a50

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/cloud_auth.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as execa from 'execa';
1+
import * as proc from 'child_process';
22
import * as jsonpath from 'jsonpath-plus';
3-
import * as shelljs from 'shelljs';
43

54
import { Authenticator } from './auth';
65
import { User } from './config_types';
@@ -51,28 +50,23 @@ export class CloudAuth implements Authenticator {
5150
}
5251

5352
private updateAccessToken(config: Config) {
54-
if (!config['cmd-path']) {
53+
let cmd = config['cmd-path'];
54+
if (!cmd) {
5555
throw new Error('Token is expired!');
5656
}
57-
let args: string[] = [];
58-
const cmdargs = config['cmd-args'];
59-
if (cmdargs) {
60-
args = cmdargs.split(' ');
57+
const args = config['cmd-args'];
58+
if (args) {
59+
cmd = cmd + ' ' + args;
6160
}
6261
// TODO: Cache to file?
6362
// TODO: do this asynchronously
64-
let result: any;
63+
let output: any;
6564
try {
66-
const cmd = config['cmd-path'];
67-
result = execa.sync(cmd, args);
68-
if (result.code !== 0) {
69-
throw new Error(result.stderr);
70-
}
65+
output = proc.execSync(cmd);
7166
} catch (err) {
7267
throw new Error('Failed to refresh token: ' + err.message);
7368
}
7469

75-
const output = result.stdout.toString();
7670
const resultObj = JSON.parse(output);
7771

7872
const tokenPathKeyInConfig = config['token-key'];

src/config_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ describe('KubeConfig', () => {
720720
config: {
721721
expiry: 'Aug 24 07:32:05 PDT 2017',
722722
'cmd-path': 'echo',
723-
'cmd-args': `${responseStr}`,
723+
'cmd-args': `'${responseStr}'`,
724724
'token-key': '{.token.accessToken}',
725725
'expiry-key': '{.token.token_expiry}',
726726
},
@@ -745,7 +745,7 @@ describe('KubeConfig', () => {
745745
name: 'azure',
746746
config: {
747747
'cmd-path': 'echo',
748-
'cmd-args': `${responseStr}`,
748+
'cmd-args': `'${responseStr}'`,
749749
'token-key': '{.token.accessToken}',
750750
'expiry-key': '{.token.token_expiry}',
751751
},
@@ -770,7 +770,7 @@ describe('KubeConfig', () => {
770770
name: 'azure',
771771
config: {
772772
'cmd-path': 'echo',
773-
'cmd-args': `${responseStr}`,
773+
'cmd-args': `'${responseStr}'`,
774774
'token-key': '{.token.accessToken}',
775775
'expiry-key': '{.token.token_expiry}',
776776
},

0 commit comments

Comments
 (0)