From 5e27dd7bbbf2a928d2303ad7298b35248cdecb69 Mon Sep 17 00:00:00 2001 From: Jim Ehrismann Date: Thu, 3 Feb 2022 18:15:23 -0500 Subject: [PATCH] shell env modifiers now take a CatalogEntity in ShellEnvContext param Signed-off-by: Jim Ehrismann --- .../local-shell-session.injectable.ts | 4 +++- .../node-shell-session/node-shell-session.ts | 2 +- .../shell-env-modifier-registration.ts | 8 ++++---- src/main/shell-session/shell-session.ts | 9 +++++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/shell-session/local-shell-session/local-shell-session.injectable.ts b/src/main/shell-session/local-shell-session/local-shell-session.injectable.ts index ea693c4496..352fa53a64 100644 --- a/src/main/shell-session/local-shell-session/local-shell-session.injectable.ts +++ b/src/main/shell-session/local-shell-session/local-shell-session.injectable.ts @@ -8,6 +8,7 @@ import type { Cluster } from "../../../common/cluster/cluster"; import type WebSocket from "ws"; import createKubectlInjectable from "../../kubectl/create-kubectl.injectable"; import shellEnvModifiersInjectable from "../shell-env-modifier/shell-env-modifier.injectable"; +import { catalogEntityRegistry } from "../../catalog"; interface InstantiationParameter { webSocket: WebSocket; @@ -21,8 +22,9 @@ const localShellSessionInjectable = getInjectable({ const shellEnvModifiers = di.inject(shellEnvModifiersInjectable); const kubectl = createKubectl(cluster.version); + const entity = catalogEntityRegistry.getById(cluster.id); - return new LocalShellSession(kubectl, shellEnvModifiers.get(), webSocket, cluster, tabId); + return new LocalShellSession(kubectl, shellEnvModifiers.get(), entity, webSocket, cluster, tabId); }, lifecycle: lifecycleEnum.transient, diff --git a/src/main/shell-session/node-shell-session/node-shell-session.ts b/src/main/shell-session/node-shell-session/node-shell-session.ts index 45bc291ee3..0f85afa3e3 100644 --- a/src/main/shell-session/node-shell-session/node-shell-session.ts +++ b/src/main/shell-session/node-shell-session/node-shell-session.ts @@ -25,7 +25,7 @@ export class NodeShellSession extends ShellSession { protected readonly cwd: string | undefined = undefined; constructor(protected nodeName: string, kubectl: Kubectl, socket: WebSocket, cluster: Cluster, terminalId: string) { - super(kubectl, [], socket, cluster, terminalId); + super(kubectl, [], undefined, socket, cluster, terminalId); } public async open() { diff --git a/src/main/shell-session/shell-env-modifier/shell-env-modifier-registration.ts b/src/main/shell-session/shell-env-modifier/shell-env-modifier-registration.ts index e7ae9b0a88..de08a51b3b 100644 --- a/src/main/shell-session/shell-env-modifier/shell-env-modifier-registration.ts +++ b/src/main/shell-session/shell-env-modifier/shell-env-modifier-registration.ts @@ -3,10 +3,10 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ +import type { CatalogEntity } from "../../../common/catalog"; + export interface ShellEnvContext { - context: string; - kubeconfigPath: string; - id: string; + catalogEntity: CatalogEntity; } -export type ShellEnvModifier = (cluster: ShellEnvContext, env: Record) => Record; +export type ShellEnvModifier = (ctx: ShellEnvContext, env: Record) => Record; diff --git a/src/main/shell-session/shell-session.ts b/src/main/shell-session/shell-session.ts index a5594e749a..2fb30d5071 100644 --- a/src/main/shell-session/shell-session.ts +++ b/src/main/shell-session/shell-session.ts @@ -20,6 +20,7 @@ import { TerminalChannels, TerminalMessage } from "../../renderer/api/terminal-a import { deserialize, serialize } from "v8"; import { stat } from "fs/promises"; import type { ShellEnvModifier } from "./shell-env-modifier/shell-env-modifier-registration"; +import type { CatalogEntity } from "../../common/catalog"; export class ShellOpenError extends Error { constructor(message: string, public cause: Error) { @@ -156,7 +157,7 @@ export abstract class ShellSession { return { shellProcess, resume }; } - constructor(protected kubectl: Kubectl, protected shellEnvModifiers: ShellEnvModifier[], protected websocket: WebSocket, protected cluster: Cluster, terminalId: string) { + constructor(protected kubectl: Kubectl, protected shellEnvModifiers: ShellEnvModifier[], protected entity: CatalogEntity, protected websocket: WebSocket, protected cluster: Cluster, terminalId: string) { this.kubeconfigPathP = this.cluster.getProxyKubeconfigPath(); this.kubectlBinDirP = this.kubectl.binDir(); this.terminalId = `${cluster.id}:${terminalId}`; @@ -361,8 +362,12 @@ export abstract class ShellSession { .filter(Boolean) .join(); - const ctx = { context: this.cluster.contextName, kubeconfigPath, id: this.cluster.id }; + console.log("entity in shell-session", this.entity); + console.log(this.entity.spec.kubeconfigPath); + console.log(this.entity.spec.kubeconfigContext); + console.log(this.entity.getId()); + const ctx = { catalogEntity: this.entity }; const modifiedEnv = this.shellEnvModifiers.reduce((env, modifier) => modifier(ctx, env), env); return modifiedEnv;