1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix not using the users configured shell for sync (#6589)

* Fix not using the users configured shell for sync

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix issue with use of userShellSetting in ShellSessions

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-17 07:15:56 -08:00 committed by GitHub
parent a89eb486d8
commit a91e3a7f8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 32 deletions

View File

@ -3,12 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { homedir } from "os"; import userInfoInjectable from "../user-store/user-info.injectable";
const homeDirectoryPathInjectable = getInjectable({ const homeDirectoryPathInjectable = getInjectable({
id: "home-directory-path", id: "home-directory-path",
instantiate: () => homedir(), instantiate: (di) => di.inject(userInfoInjectable).homedir,
causesSideEffects: true,
}); });
export default homeDirectoryPathInjectable; export default homeDirectoryPathInjectable;

View File

@ -1,13 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import userStoreInjectable from "./user-store.injectable";
const resolvedShellInjectable = getInjectable({
id: "resolved-shell",
instantiate: (di) => di.inject(userStoreInjectable).resolvedShell,
});
export default resolvedShellInjectable;

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import userInfoInjectable from "./user-info.injectable";
import userStoreInjectable from "./user-store.injectable";
const userShellSettingInjectable = getInjectable({
id: "user-shell-setting",
instantiate: (di) => {
const userStore = di.inject(userStoreInjectable);
const userInfo = di.inject(userInfoInjectable);
return computed(() => userStore.shell || userInfo.shell);
},
});
export default userShellSettingInjectable;

View File

@ -4,6 +4,12 @@
*/ */
import { getGlobalOverride } from "../test-utils/get-global-override"; import { getGlobalOverride } from "../test-utils/get-global-override";
import homeDirectoryPathInjectable from "./home-directory-path.injectable"; import userInfoInjectable from "./user-info.injectable";
export default getGlobalOverride(homeDirectoryPathInjectable, () => "/some-home-directory"); export default getGlobalOverride(userInfoInjectable, () => ({
gid: 1,
homedir: "/some-home-dir",
shell: "bash",
uid: 2,
username: "some-user-name",
}));

View File

@ -0,0 +1,14 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { userInfo } from "os";
const userInfoInjectable = getInjectable({
id: "user-info",
instantiate: () => userInfo(),
causesSideEffects: true,
});
export default userInfoInjectable;

View File

@ -4,7 +4,7 @@
*/ */
import { app } from "electron"; import { app } from "electron";
import { action, computed, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx"; import { action, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
import { BaseStore } from "../base-store"; import { BaseStore } from "../base-store";
import migrations from "../../migrations/user-store"; import migrations from "../../migrations/user-store";
import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils"; import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils";
@ -91,10 +91,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
*/ */
@observable syncKubeconfigEntries!: StoreType<typeof DESCRIPTORS["syncKubeconfigEntries"]>; @observable syncKubeconfigEntries!: StoreType<typeof DESCRIPTORS["syncKubeconfigEntries"]>;
@computed get resolvedShell(): string | undefined {
return this.shell || process.env.SHELL || process.env.PTYSHELL;
}
startMainReactions() { startMainReactions() {
// open at system start-up // open at system start-up
reaction(() => this.openAtLogin, openAtLogin => { reaction(() => this.openAtLogin, openAtLogin => {

View File

@ -19,7 +19,7 @@ import joinPathsInjectable from "../../../common/path/join-paths.injectable";
import getBasenameOfPathInjectable from "../../../common/path/get-basename.injectable"; import getBasenameOfPathInjectable from "../../../common/path/get-basename.injectable";
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable"; import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
import spawnPtyInjectable from "../spawn-pty.injectable"; import spawnPtyInjectable from "../spawn-pty.injectable";
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable"; import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
import appNameInjectable from "../../../common/vars/app-name.injectable"; import appNameInjectable from "../../../common/vars/app-name.injectable";
import buildVersionInjectable from "../../vars/build-version/build-version.injectable"; import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable"; import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
@ -44,7 +44,7 @@ const openLocalShellSessionInjectable = getInjectable({
isWindows: di.inject(isWindowsInjectable), isWindows: di.inject(isWindowsInjectable),
logger: di.inject(loggerInjectable), logger: di.inject(loggerInjectable),
userStore: di.inject(userStoreInjectable), userStore: di.inject(userStoreInjectable),
resolvedShell: di.inject(resolvedShellInjectable), userShellSetting: di.inject(userShellSettingInjectable),
appName: di.inject(appNameInjectable), appName: di.inject(appNameInjectable),
buildVersion: di.inject(buildVersionInjectable), buildVersion: di.inject(buildVersionInjectable),
modifyTerminalShellEnv: di.inject(modifyTerminalShellEnvInjectable), modifyTerminalShellEnv: di.inject(modifyTerminalShellEnvInjectable),

View File

@ -14,7 +14,7 @@ import loggerInjectable from "../../../common/logger.injectable";
import createKubeJsonApiForClusterInjectable from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable"; import createKubeJsonApiForClusterInjectable from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable";
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable"; import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
import spawnPtyInjectable from "../spawn-pty.injectable"; import spawnPtyInjectable from "../spawn-pty.injectable";
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable"; import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
import appNameInjectable from "../../../common/vars/app-name.injectable"; import appNameInjectable from "../../../common/vars/app-name.injectable";
import buildVersionInjectable from "../../vars/build-version/build-version.injectable"; import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable"; import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
@ -35,7 +35,7 @@ const openNodeShellSessionInjectable = getInjectable({
isMac: di.inject(isMacInjectable), isMac: di.inject(isMacInjectable),
isWindows: di.inject(isWindowsInjectable), isWindows: di.inject(isWindowsInjectable),
logger: di.inject(loggerInjectable), logger: di.inject(loggerInjectable),
resolvedShell: di.inject(resolvedShellInjectable), userShellSetting: di.inject(userShellSettingInjectable),
appName: di.inject(appNameInjectable), appName: di.inject(appNameInjectable),
buildVersion: di.inject(buildVersionInjectable), buildVersion: di.inject(buildVersionInjectable),
createKubeJsonApiForCluster: di.inject(createKubeJsonApiForClusterInjectable), createKubeJsonApiForCluster: di.inject(createKubeJsonApiForClusterInjectable),

View File

@ -8,7 +8,7 @@ import type { Kubectl } from "../kubectl/kubectl";
import type WebSocket from "ws"; import type WebSocket from "ws";
import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars"; import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars";
import path from "path"; import path from "path";
import os, { userInfo } from "os"; import os from "os";
import type * as pty from "node-pty"; import type * as pty from "node-pty";
import { getOrInsertWith } from "../../common/utils"; import { getOrInsertWith } from "../../common/utils";
import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels"; import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels";
@ -18,6 +18,7 @@ import type { SpawnPty } from "./spawn-pty.injectable";
import type { InitializableState } from "../../common/initializable-state/create"; import type { InitializableState } from "../../common/initializable-state/create";
import type { EmitAppEvent } from "../../common/app-event-bus/emit-event.injectable"; import type { EmitAppEvent } from "../../common/app-event-bus/emit-event.injectable";
import type { Stat } from "../../common/fs/stat/stat.injectable"; import type { Stat } from "../../common/fs/stat/stat.injectable";
import type { IComputedValue } from "mobx";
export class ShellOpenError extends Error { export class ShellOpenError extends Error {
constructor(message: string, options?: ErrorOptions) { constructor(message: string, options?: ErrorOptions) {
@ -107,7 +108,7 @@ export interface ShellSessionDependencies {
readonly isWindows: boolean; readonly isWindows: boolean;
readonly isMac: boolean; readonly isMac: boolean;
readonly logger: Logger; readonly logger: Logger;
readonly resolvedShell: string | undefined; readonly userShellSetting: IComputedValue<string>;
readonly appName: string; readonly appName: string;
readonly buildVersion: InitializableState<string>; readonly buildVersion: InitializableState<string>;
computeShellEnvironment: ComputeShellEnvironment; computeShellEnvironment: ComputeShellEnvironment;
@ -338,7 +339,7 @@ export abstract class ShellSession {
} }
protected async getShellEnv() { protected async getShellEnv() {
const shell = this.dependencies.resolvedShell || userInfo().shell; const shell = this.dependencies.userShellSetting.get();
const result = await this.dependencies.computeShellEnvironment(shell); const result = await this.dependencies.computeShellEnvironment(shell);
const rawEnv = (() => { const rawEnv = (() => {
if (result.callWasSuccessful) { if (result.callWasSuccessful) {

View File

@ -5,11 +5,11 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
import { onLoadOfApplicationInjectionToken } from "../runnable-tokens/on-load-of-application-injection-token"; import { onLoadOfApplicationInjectionToken } from "../runnable-tokens/on-load-of-application-injection-token";
import os from "os";
import { unionPATHs } from "../../../common/utils/union-env-path"; import { unionPATHs } from "../../../common/utils/union-env-path";
import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable"; import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable";
import electronAppInjectable from "../../electron-app/electron-app.injectable"; import electronAppInjectable from "../../electron-app/electron-app.injectable";
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable"; import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
const setupShellInjectable = getInjectable({ const setupShellInjectable = getInjectable({
id: "setup-shell", id: "setup-shell",
@ -18,6 +18,7 @@ const setupShellInjectable = getInjectable({
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const isSnapPackage = di.inject(isSnapPackageInjectable); const isSnapPackage = di.inject(isSnapPackageInjectable);
const electronApp = di.inject(electronAppInjectable); const electronApp = di.inject(electronAppInjectable);
const resolvedUserShellSetting = di.inject(userShellSettingInjectable);
const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable); const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable);
return { return {
@ -25,7 +26,7 @@ const setupShellInjectable = getInjectable({
run: async (): Promise<void> => { run: async (): Promise<void> => {
logger.info("🐚 Syncing shell environment"); logger.info("🐚 Syncing shell environment");
const result = await computeShellEnvironment(os.userInfo().shell); const result = await computeShellEnvironment(resolvedUserShellSetting.get());
if (!result.callWasSuccessful) { if (!result.callWasSuccessful) {
return void logger.error(`[SHELL-SYNC]: ${result.error}`); return void logger.error(`[SHELL-SYNC]: ${result.error}`);