mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
modified shell env api to work as a transformer (WIP)
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
1ac3d0a36b
commit
4b51c22610
@ -11,3 +11,4 @@ export type { PageRegistration, RegisteredPage, PageParams, PageComponentProps,
|
|||||||
export type { ClusterPageMenuRegistration, ClusterPageMenuComponents } from "../registries/page-menu-registry";
|
export type { ClusterPageMenuRegistration, ClusterPageMenuComponents } from "../registries/page-menu-registry";
|
||||||
export type { ProtocolHandlerRegistration, RouteParams as ProtocolRouteParams, RouteHandler as ProtocolRouteHandler } from "../registries/protocol-handler";
|
export type { ProtocolHandlerRegistration, RouteParams as ProtocolRouteParams, RouteHandler as ProtocolRouteHandler } from "../registries/protocol-handler";
|
||||||
export type { CustomCategoryViewProps, CustomCategoryViewComponents, CustomCategoryViewRegistration } from "../../renderer/components/+catalog/custom-views";
|
export type { CustomCategoryViewProps, CustomCategoryViewComponents, CustomCategoryViewRegistration } from "../../renderer/components/+catalog/custom-views";
|
||||||
|
export type { ShellEnvModifier, ShellEnvClusterData } from "../../main/shell-session/shell-env-modifier/shell-env-modifier-registration";
|
||||||
|
|||||||
@ -10,11 +10,14 @@ import type { CatalogEntity } from "../common/catalog";
|
|||||||
import type { IObservableArray } from "mobx";
|
import type { IObservableArray } from "mobx";
|
||||||
import type { MenuRegistration } from "../main/menu/menu-registration";
|
import type { MenuRegistration } from "../main/menu/menu-registration";
|
||||||
import type { TrayMenuRegistration } from "../main/tray/tray-menu-registration";
|
import type { TrayMenuRegistration } from "../main/tray/tray-menu-registration";
|
||||||
import type { ShellEnvVarRegistration } from "../main/shell-session/env-var/env-var-registration";
|
import type { ShellEnvModifier } from "../main/shell-session/shell-env-modifier/shell-env-modifier-registration";
|
||||||
|
import { noop } from "../common/utils";
|
||||||
|
|
||||||
export class LensMainExtension extends LensExtension {
|
export class LensMainExtension extends LensExtension {
|
||||||
appMenus: MenuRegistration[] = [];
|
appMenus: MenuRegistration[] = [];
|
||||||
trayMenus: TrayMenuRegistration[] = [];
|
trayMenus: TrayMenuRegistration[] = [];
|
||||||
shellEnvVars: ShellEnvVarRegistration[] = [];
|
|
||||||
|
shellEnvModifier: ShellEnvModifier = noop;
|
||||||
|
|
||||||
async navigate(pageId?: string, params?: Record<string, any>, frameId?: number) {
|
async navigate(pageId?: string, params?: Record<string, any>, frameId?: number) {
|
||||||
return WindowManager.getInstance().navigateExtension(this.id, pageId, params, frameId);
|
return WindowManager.getInstance().navigateExtension(this.id, pageId, params, frameId);
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface ShellEnvVarRegistration {
|
|
||||||
title: string;
|
|
||||||
env: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -7,6 +7,7 @@ import { LocalShellSession } from "./local-shell-session";
|
|||||||
import type { Cluster } from "../../../common/cluster/cluster";
|
import type { Cluster } from "../../../common/cluster/cluster";
|
||||||
import type WebSocket from "ws";
|
import type WebSocket from "ws";
|
||||||
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
|
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
|
||||||
|
import shellEnvModifiersInjectable from "../shell-env-modifier/shell-env-modifier.injectable";
|
||||||
|
|
||||||
interface InstantiationParameter {
|
interface InstantiationParameter {
|
||||||
webSocket: WebSocket;
|
webSocket: WebSocket;
|
||||||
@ -17,10 +18,11 @@ interface InstantiationParameter {
|
|||||||
const localShellSessionInjectable = getInjectable({
|
const localShellSessionInjectable = getInjectable({
|
||||||
instantiate: (di, { cluster, tabId, webSocket }: InstantiationParameter) => {
|
instantiate: (di, { cluster, tabId, webSocket }: InstantiationParameter) => {
|
||||||
const createKubectl = di.inject(createKubectlInjectable);
|
const createKubectl = di.inject(createKubectlInjectable);
|
||||||
|
const shellEnvModifiers = di.inject(shellEnvModifiersInjectable);
|
||||||
|
|
||||||
const kubectl = createKubectl(cluster.version);
|
const kubectl = createKubectl(cluster.version);
|
||||||
|
|
||||||
return new LocalShellSession(kubectl, webSocket, cluster, tabId);
|
return new LocalShellSession(kubectl, shellEnvModifiers.get(), webSocket, cluster, tabId);
|
||||||
},
|
},
|
||||||
|
|
||||||
lifecycle: lifecycleEnum.transient,
|
lifecycle: lifecycleEnum.transient,
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export class NodeShellSession extends ShellSession {
|
|||||||
protected readonly cwd: string | undefined = undefined;
|
protected readonly cwd: string | undefined = undefined;
|
||||||
|
|
||||||
constructor(protected nodeName: string, kubectl: Kubectl, socket: WebSocket, cluster: Cluster, terminalId: string) {
|
constructor(protected nodeName: string, kubectl: Kubectl, socket: WebSocket, cluster: Cluster, terminalId: string) {
|
||||||
super(kubectl, socket, cluster, terminalId);
|
super(kubectl, [], socket, cluster, terminalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async open() {
|
public async open() {
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { noop } from "../../../common/utils";
|
||||||
|
|
||||||
|
export interface ShellEnvClusterData {
|
||||||
|
context: string;
|
||||||
|
kubeconfigPath: string;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ShellEnvModifier = ((cluster: ShellEnvClusterData, env: Record<string, string | undefined>) => Record<string, string | undefined>) | typeof noop;
|
||||||
@ -5,15 +5,15 @@
|
|||||||
|
|
||||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||||
import mainExtensionsInjectable from "../../../extensions/main-extensions.injectable";
|
import mainExtensionsInjectable from "../../../extensions/main-extensions.injectable";
|
||||||
import { getShellEnvVars } from "./get-shell-env-vars";
|
import { shellEnvModifiers } from "./shell-env-modifiers";
|
||||||
|
|
||||||
const shellEnvVarInjectable = getInjectable({
|
const shellEnvModifiersInjectable = getInjectable({
|
||||||
instantiate: (di) =>
|
instantiate: (di) =>
|
||||||
getShellEnvVars({
|
shellEnvModifiers({
|
||||||
extensions: di.inject(mainExtensionsInjectable),
|
extensions: di.inject(mainExtensionsInjectable),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
lifecycle: lifecycleEnum.singleton,
|
lifecycle: lifecycleEnum.singleton,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default shellEnvVarInjectable;
|
export default shellEnvModifiersInjectable;
|
||||||
@ -10,9 +10,9 @@ interface Dependencies {
|
|||||||
extensions: IComputedValue<LensMainExtension[]>;
|
extensions: IComputedValue<LensMainExtension[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getShellEnvVars = ({ extensions }: Dependencies) => {
|
export const shellEnvModifiers = ({ extensions }: Dependencies) => {
|
||||||
return computed(() => (
|
return computed(() => (
|
||||||
extensions.get()
|
extensions.get()
|
||||||
.flatMap((extension) => extension.shellEnvVars)
|
.flatMap((extension) => extension.shellEnvModifier)
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
@ -19,6 +19,7 @@ import logger from "../logger";
|
|||||||
import { TerminalChannels, TerminalMessage } from "../../renderer/api/terminal-api";
|
import { TerminalChannels, TerminalMessage } from "../../renderer/api/terminal-api";
|
||||||
import { deserialize, serialize } from "v8";
|
import { deserialize, serialize } from "v8";
|
||||||
import { stat } from "fs/promises";
|
import { stat } from "fs/promises";
|
||||||
|
import type { ShellEnvModifier } from "./shell-env-modifier/shell-env-modifier-registration";
|
||||||
|
|
||||||
export class ShellOpenError extends Error {
|
export class ShellOpenError extends Error {
|
||||||
constructor(message: string, public cause: Error) {
|
constructor(message: string, public cause: Error) {
|
||||||
@ -155,7 +156,7 @@ export abstract class ShellSession {
|
|||||||
return { shellProcess, resume };
|
return { shellProcess, resume };
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(protected kubectl: Kubectl, protected websocket: WebSocket, protected cluster: Cluster, terminalId: string) {
|
constructor(protected kubectl: Kubectl, protected shellEnvModifiers: ShellEnvModifier[], protected websocket: WebSocket, protected cluster: Cluster, terminalId: string) {
|
||||||
this.kubeconfigPathP = this.cluster.getProxyKubeconfigPath();
|
this.kubeconfigPathP = this.cluster.getProxyKubeconfigPath();
|
||||||
this.kubectlBinDirP = this.kubectl.binDir();
|
this.kubectlBinDirP = this.kubectl.binDir();
|
||||||
this.terminalId = `${cluster.id}:${terminalId}`;
|
this.terminalId = `${cluster.id}:${terminalId}`;
|
||||||
@ -311,7 +312,7 @@ export abstract class ShellSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async getShellEnv() {
|
protected async getShellEnv() {
|
||||||
const env = clearKubeconfigEnvVars(JSON.parse(JSON.stringify(await shellEnv())));
|
let env = clearKubeconfigEnvVars(JSON.parse(JSON.stringify(await shellEnv())));
|
||||||
const pathStr = [...this.getPathEntries(), await this.kubectlBinDirP, process.env.PATH].join(path.delimiter);
|
const pathStr = [...this.getPathEntries(), await this.kubectlBinDirP, process.env.PATH].join(path.delimiter);
|
||||||
const shell = UserStore.getInstance().resolvedShell;
|
const shell = UserStore.getInstance().resolvedShell;
|
||||||
|
|
||||||
@ -341,8 +342,10 @@ export abstract class ShellSession {
|
|||||||
env.DISABLE_AUTO_UPDATE = "true";
|
env.DISABLE_AUTO_UPDATE = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kubeconfigPath = await this.kubeconfigPathP;
|
||||||
|
|
||||||
env.PTYPID = process.pid.toString();
|
env.PTYPID = process.pid.toString();
|
||||||
env.KUBECONFIG = await this.kubeconfigPathP;
|
env.KUBECONFIG = kubeconfigPath;
|
||||||
env.TERM_PROGRAM = app.getName();
|
env.TERM_PROGRAM = app.getName();
|
||||||
env.TERM_PROGRAM_VERSION = app.getVersion();
|
env.TERM_PROGRAM_VERSION = app.getVersion();
|
||||||
|
|
||||||
@ -358,6 +361,8 @@ export abstract class ShellSession {
|
|||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join();
|
.join();
|
||||||
|
|
||||||
|
this.shellEnvModifiers.map(modifier => env = { ...env, ...modifier({ context: this.cluster.contextName, kubeconfigPath, id: this.cluster.id }, env) });
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user