mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move clearKubeconfigEnvVars to separate file (#2337)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
6c872c1aad
commit
7d14ba5e48
@ -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", () => {
|
||||
|
||||
@ -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<string, any>): Record<string, any> {
|
||||
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<string, any> = new Map();
|
||||
|
||||
16
src/main/utils/clear-kube-env-vars.ts
Normal file
16
src/main/utils/clear-kube-env-vars.ts
Normal 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)
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user