Move clearKubeconfigEnvVars to separate file (#2337)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and Jari Kolehmainen committed 2021-03-25 12:54:48 +02:00
1 parent 844b43f435
commit 8ce487b999
3 files changed
+18 -18

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
* @jest-environment jsdom * @jest-environment jsdom
*/ */
import { clearKubeconfigEnvVars } from "../shell-session"; import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars";
describe("clearKubeconfigEnvVars tests", () => { describe("clearKubeconfigEnvVars tests", () => {
it("should not touch non kubeconfig keys", () => { it("should not touch non kubeconfig keys", () => {
+1 -17
View File
@@ -11,23 +11,7 @@ import { helmCli } from "./helm/helm-cli";
import { isWindows } from "../common/vars"; import { isWindows } from "../common/vars";
import { appEventBus } from "../common/event-bus"; import { appEventBus } from "../common/event-bus";
import { userStore } from "../common/user-store"; import { userStore } from "../common/user-store";
import { clearKubeconfigEnvVars } from "./utils/clear-kube-env-vars";
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<string, any>): Record<string, any> {
return Object.fromEntries(
Object.entries(env)
.filter(([key]) => anyKubeconfig.exec(key) === null)
);
}
export class ShellSession extends EventEmitter { export class ShellSession extends EventEmitter {
static shellEnvs: Map<string, any> = new Map(); static shellEnvs: Map<string, any> = new Map();
+16
View File
@@ -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<string, any>): Record<string, any> {
return Object.fromEntries(
Object.entries(env)
.filter(([key]) => anyKubeconfig.exec(key) === null)
);
}