From bac2d6e2ac84a931a0dd0d4d80548cb70ab5f725 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 13 Sep 2021 11:14:27 -0400 Subject: [PATCH] switch to using npm's which package Signed-off-by: Sebastian Malton --- package.json | 2 ++ src/common/kube-helpers.ts | 9 ++------- yarn.lock | 5 +++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 0cad8dc9c6..cbd725e314 100644 --- a/package.json +++ b/package.json @@ -185,6 +185,7 @@ "@kubernetes/client-node": "^0.15.1", "@sentry/electron": "^2.5.0", "@sentry/integrations": "^6.10.0", + "@types/which": "^2.0.1", "abort-controller": "^3.0.0", "array-move": "^3.0.1", "auto-bind": "^4.0.0", @@ -245,6 +246,7 @@ "tempy": "^0.5.0", "url-parse": "^1.5.1", "uuid": "^8.3.2", + "which": "^2.0.2", "win-ca": "^3.2.0", "winston": "^3.3.3", "winston-console-format": "^1.0.8", diff --git a/src/common/kube-helpers.ts b/src/common/kube-helpers.ts index 34a9c924dd..4bd420e7b2 100644 --- a/src/common/kube-helpers.ts +++ b/src/common/kube-helpers.ts @@ -29,7 +29,7 @@ import { ExecValidationNotFoundError } from "./custom-errors"; import { Cluster, Context, newClusters, newContexts, newUsers, User } from "@kubernetes/client-node/dist/config_types"; import { resolvePath } from "./utils"; import Joi from "joi"; -import { execFileSync } from "child_process"; +import which from "which"; export type KubeConfigValidationOpts = { validateCluster?: boolean; @@ -296,17 +296,12 @@ export function validateKubeConfig(config: KubeConfig, contextName: string, vali // Validate exec command if present if (validateExec && user?.exec) { try { - execFileSync(user.exec.command, { timeout: 1 }); + which.sync(user.exec.command); // If this doesn't throw an error it also means that it has found the executable. } catch (error) { switch (error?.code) { - case "ETIMEDOUT": - // ignore this error code. It means that the exec can be found. - break; case "ENOENT": - case "EACCES": - case "EPERM": return new ExecValidationNotFoundError(user.exec.command); default: return error; diff --git a/yarn.lock b/yarn.lock index abdfd4c5d9..836c40456d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2152,6 +2152,11 @@ anymatch "^3.0.0" source-map "^0.6.0" +"@types/which@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@types/which/-/which-2.0.1.tgz#27ecd67f915b7c3d6ba552135bb1eecd66e63501" + integrity sha512-Jjakcv8Roqtio6w1gr0D7y6twbhx6gGgFGF5BLwajPpnOIOxFkakFhCq+LmyyeAz7BX6ULrjBOxdKaCDy+4+dQ== + "@types/ws@^6.0.1": version "6.0.4" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-6.0.4.tgz#7797707c8acce8f76d8c34b370d4645b70421ff1"