1
0
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:
Janne Savolainen 2022-06-03 15:40:10 +03:00
parent 0d83d6b6ee
commit 5032301ecb
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
3 changed files with 93 additions and 0 deletions

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 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;

View 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;

View 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;