Skip to content

Commit 60b199e

Browse files
committed
fix: switch from shelljs to execa to avoid issues in Electron
1 parent c884320 commit 60b199e

File tree

4 files changed

+139
-12
lines changed

4 files changed

+139
-12
lines changed

node-client/package-lock.json

Lines changed: 125 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-client/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"base-64": "^0.1.0",
4848
"bluebird": "^3.5.2",
4949
"byline": "^5.0.0",
50+
"execa": "^1.0.0",
5051
"js-yaml": "^3.12.0",
5152
"jsonpath": "^1.0.0",
5253
"request": "^2.88.0",
@@ -59,6 +60,7 @@
5960
"@types/base-64": "^0.1.2",
6061
"@types/bluebird": "^3.5.24",
6162
"@types/chai": "^4.1.6",
63+
"@types/execa": "^0.9.0",
6264
"@types/js-yaml": "^3.11.2",
6365
"@types/mocha": "^5.2.5",
6466
"@types/mock-fs": "^3.6.30",

node-client/src/config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import https = require('https');
33
import path = require('path');
44

55
import base64 = require('base-64');
6+
import execa = require('execa');
67
import yaml = require('js-yaml');
78
import jsonpath = require('jsonpath');
89
import request = require('request');
9-
import shelljs = require('shelljs');
1010

1111
import api = require('./api');
1212
import { Cluster, Context, newClusters, newContexts, newUsers, User } from './config_types';
@@ -273,15 +273,17 @@ export class KubeConfig {
273273
const expiration = Date.parse(expiry);
274274
if (expiration < Date.now()) {
275275
if (config['cmd-path']) {
276-
let cmd = '"' + config['cmd-path'] + '"';
277-
if (config['cmd-args']) {
278-
cmd = cmd + ' ' + config['cmd-args'];
279-
}
276+
const args = config['cmd-args'] ? [config['cmd-args']] : [];
280277
// TODO: Cache to file?
281-
const result = shelljs.exec(cmd, { silent: true });
282-
if (result.code !== 0) {
283-
throw new Error('Failed to refresh token: ' + result.stderr);
278+
// TODO: do this asynchronously
279+
let result: execa.ExecaReturns;
280+
281+
try {
282+
result = execa.sync(config['cmd-path'], args);
283+
} catch (err) {
284+
throw new Error('Failed to refresh token: ' + err.message);
284285
}
286+
285287
const output = result.stdout.toString();
286288
const resultObj = JSON.parse(output);
287289

node-client/src/config_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ describe('KubeConfig', () => {
536536
} as User);
537537
const opts = {} as requestlib.Options;
538538
expect(() => config.applyToRequest(opts)).to.throw(
539-
'Failed to refresh token: /bin/sh: 1: non-existent-command: not found');
539+
'Failed to refresh token: spawnSync non-existent-command ENOENT');
540540
});
541541

542542
it('should exec with expired token', () => {
@@ -550,7 +550,7 @@ describe('KubeConfig', () => {
550550
config: {
551551
'expiry': 'Aug 24 07:32:05 PDT 2017',
552552
'cmd-path': 'echo',
553-
'cmd-args': `'${responseStr}'`,
553+
'cmd-args': `${responseStr}`,
554554
'token-key': '{.token.accessToken}',
555555
},
556556
},

0 commit comments

Comments
 (0)