From 7d14ba5e48e2b207118dd030f97b3687612863aa Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 16 Mar 2021 08:05:28 -0400 Subject: [PATCH] Move clearKubeconfigEnvVars to separate file (#2337) Signed-off-by: Sebastian Malton --- src/main/__test__/shell-session.test.ts | 2 +- src/main/shell-session.ts | 18 +----------------- src/main/utils/clear-kube-env-vars.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 src/main/utils/clear-kube-env-vars.ts diff --git a/src/main/__test__/shell-session.test.ts b/src/main/__test__/shell-session.test.ts index fe1b0c4288..d16b5453b9 100644 --- a/src/main/__test__/shell-session.test.ts +++ b/src/main/__test__/shell-session.test.ts @@ -2,7 +2,7 @@ * @jest-environment jsdom */ -import { clearKubeconfigEnvVars } from "../shell-session"; +import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars"; describe("clearKubeconfigEnvVars tests", () => { it("should not touch non kubeconfig keys", () => { diff --git a/src/main/shell-session.ts b/src/main/shell-session.ts index a8661bd635..40b3981d07 100644 --- a/src/main/shell-session.ts +++ b/src/main/shell-session.ts @@ -11,23 +11,7 @@ import { helmCli } from "./helm/helm-cli"; import { isWindows } from "../common/vars"; import { appEventBus } from "../common/event-bus"; import { userStore } from "../common/user-store"; - -const anyKubeconfig = /^kubeconfig$/i; - -/** - * This function deletes all keys of the form /^kubeconfig$/i, returning a new - * object. - * - * This is needed because `kubectl` checks for other version of kubeconfig - * before KUBECONFIG and we only set KUBECONFIG. - * @param env The current copy of env - */ -export function clearKubeconfigEnvVars(env: Record): Record { - return Object.fromEntries( - Object.entries(env) - .filter(([key]) => anyKubeconfig.exec(key) === null) - ); -} +import { clearKubeconfigEnvVars } from "./utils/clear-kube-env-vars"; export class ShellSession extends EventEmitter { static shellEnvs: Map = new Map(); diff --git a/src/main/utils/clear-kube-env-vars.ts b/src/main/utils/clear-kube-env-vars.ts new file mode 100644 index 0000000000..ef14b1a331 --- /dev/null +++ b/src/main/utils/clear-kube-env-vars.ts @@ -0,0 +1,16 @@ +const anyKubeconfig = /^kubeconfig$/i; + +/** + * This function deletes all keys of the form /^kubeconfig$/i, returning a new + * object. + * + * This is needed because `kubectl` checks for other version of kubeconfig + * before KUBECONFIG and we only set KUBECONFIG. + * @param env The current copy of env + */ +export function clearKubeconfigEnvVars(env: Record): Record { + return Object.fromEntries( + Object.entries(env) + .filter(([key]) => anyKubeconfig.exec(key) === null) + ); +}