mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Release 6.1.12 Signed-off-by: Sebastian Malton <sebastian@malton.name> * Adding asc provider (#6302) * Fix windows shell not having all environment variables (#6402) * Fix windows shell not having all environment variables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix startup due to buildVersion dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * Call cleanup in computeShellEnvironment Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lints Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix build issue Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test invocation Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Billy Tobon <billy.tobon@gmail.com>
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import path from "path";
|
|
import type { UserStore } from "../../../common/user-store";
|
|
import type { ClusterId } from "../../../common/cluster-types";
|
|
import type { ShellSessionArgs, ShellSessionDependencies } from "../shell-session";
|
|
import { ShellSession } from "../shell-session";
|
|
import { baseBinariesDir } from "../../../common/vars";
|
|
|
|
interface LocalShellSessionDependencies extends ShellSessionDependencies {
|
|
readonly userStore: UserStore;
|
|
modifyTerminalShellEnv: (clusterId: ClusterId, env: Record<string, string | undefined>) => Record<string, string | undefined>;
|
|
}
|
|
|
|
export class LocalShellSession extends ShellSession {
|
|
ShellType = "shell";
|
|
|
|
constructor(protected readonly dependencies: LocalShellSessionDependencies, args: ShellSessionArgs) {
|
|
super(dependencies, args);
|
|
}
|
|
|
|
protected getPathEntries(): string[] {
|
|
return [baseBinariesDir.get()];
|
|
}
|
|
|
|
protected get cwd(): string | undefined {
|
|
return this.cluster.preferences?.terminalCWD;
|
|
}
|
|
|
|
public async open() {
|
|
// extensions can modify the env
|
|
const env = this.dependencies.modifyTerminalShellEnv(this.cluster.id, await this.getCachedShellEnv());
|
|
const shell = env.PTYSHELL;
|
|
|
|
if (!shell) {
|
|
throw new Error("PTYSHELL is not defined with the environment");
|
|
}
|
|
|
|
const args = await this.getShellArgs(shell);
|
|
|
|
await this.openShellProcess(shell, args, env);
|
|
}
|
|
|
|
protected async getShellArgs(shell: string): Promise<string[]> {
|
|
const pathFromPreferences = this.dependencies.userStore.kubectlBinariesPath || this.kubectl.getBundledPath();
|
|
const kubectlPathDir = this.dependencies.userStore.downloadKubectlBinaries ? await this.kubectlBinDirP : path.dirname(pathFromPreferences);
|
|
|
|
switch(path.basename(shell)) {
|
|
case "powershell.exe":
|
|
return ["-NoExit", "-command", `& {$Env:PATH="${kubectlPathDir};${baseBinariesDir.get()};$Env:PATH"}`];
|
|
case "bash":
|
|
return ["--init-file", path.join(await this.kubectlBinDirP, ".bash_set_path")];
|
|
case "fish":
|
|
return ["--login", "--init-command", `export PATH="${kubectlPathDir}:${baseBinariesDir.get()}:$PATH"; export KUBECONFIG="${await this.kubeconfigPathP}"`];
|
|
case "zsh":
|
|
return ["--login"];
|
|
default:
|
|
return [];
|
|
}
|
|
}
|
|
}
|