mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce way to get Helm environment values
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
0d83d6b6ee
commit
5032301ecb
20
src/main/helm/exec-helm/exec-helm.injectable.ts
Normal file
20
src/main/helm/exec-helm/exec-helm.injectable.ts
Normal 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 execFileInjectable from "../../../common/fs/exec-file.injectable";
|
||||||
|
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
|
||||||
|
|
||||||
|
const execHelmInjectable = getInjectable({
|
||||||
|
id: "exec-helm",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const execFile = di.inject(execFileInjectable);
|
||||||
|
const helmBinaryPath = di.inject(helmBinaryPathInjectable);
|
||||||
|
|
||||||
|
return (...args: string[]) => execFile(helmBinaryPath, args);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default execHelmInjectable;
|
||||||
38
src/main/helm/get-helm-env/get-helm-env.injectable.ts
Normal file
38
src/main/helm/get-helm-env/get-helm-env.injectable.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* 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 execHelmInjectable from "../exec-helm/exec-helm.injectable";
|
||||||
|
|
||||||
|
export type HelmEnv = Record<string, string> & {
|
||||||
|
HELM_REPOSITORY_CACHE?: string;
|
||||||
|
HELM_REPOSITORY_CONFIG?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getHelmEnvInjectable = getInjectable({
|
||||||
|
id: "get-helm-env",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const execHelm = di.inject(execHelmInjectable);
|
||||||
|
|
||||||
|
return async () => {
|
||||||
|
const output = await execHelm("env");
|
||||||
|
|
||||||
|
const lines = output.split(/\r?\n/); // split by new line feed
|
||||||
|
const env: HelmEnv = {};
|
||||||
|
|
||||||
|
lines.forEach((line: string) => {
|
||||||
|
const [key, value] = line.split("=");
|
||||||
|
|
||||||
|
if (key && value) {
|
||||||
|
env[key] = value.replace(/"/g, ""); // strip quotas
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return env;
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default getHelmEnvInjectable;
|
||||||
35
src/main/helm/helm-binary-path.injectable.ts
Normal file
35
src/main/helm/helm-binary-path.injectable.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* 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 { getBinaryName } from "../../common/vars";
|
||||||
|
import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable";
|
||||||
|
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||||
|
import normalizedPlatformInjectable from "../../common/vars/normalized-platform.injectable";
|
||||||
|
import isProductionInjectable from "../../common/vars/is-production.injectable";
|
||||||
|
import normalizedPlatformArchitectureInjectable from "../../common/vars/normalized-platform-architecture.injectable";
|
||||||
|
|
||||||
|
const helmBinaryPathInjectable = getInjectable({
|
||||||
|
id: "helm-binary-path",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
||||||
|
const lensResourcesDir = di.inject(lensResourcesDirInjectable);
|
||||||
|
const normalizedPlatform = di.inject(normalizedPlatformInjectable);
|
||||||
|
const normalizedPlatformArchitecture = di.inject(normalizedPlatformArchitectureInjectable);
|
||||||
|
const isProduction = di.inject(isProductionInjectable);
|
||||||
|
|
||||||
|
const resourcesDir = isProduction
|
||||||
|
? lensResourcesDir
|
||||||
|
: getAbsolutePath(lensResourcesDir, "binaries", "client", normalizedPlatform);
|
||||||
|
|
||||||
|
const baseBinariesDir = getAbsolutePath(resourcesDir, normalizedPlatformArchitecture);
|
||||||
|
|
||||||
|
const helmBinaryName = getBinaryName("helm", { forPlatform: normalizedPlatform });
|
||||||
|
|
||||||
|
return getAbsolutePath(baseBinariesDir, helmBinaryName);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default helmBinaryPathInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user