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

more dependencies

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2022-03-10 15:59:47 +02:00
parent dcd58a7cbc
commit 5176970438
4 changed files with 14 additions and 8 deletions

View File

@ -4,6 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { KubeAuthProxy, KubeAuthProxyDependencies } from "./kube-auth-proxy";
import { spawn } from "child_process";
import type { Cluster } from "../../common/cluster/cluster";
import path from "path";
import { getBinaryName } from "../../common/vars";
@ -18,6 +19,7 @@ const createKubeAuthProxyInjectable = getInjectable({
const dependencies: KubeAuthProxyDependencies = {
proxyBinPath: path.join(di.inject(directoryForBundledBinariesInjectable), binaryName),
proxyCertPath: di.inject(getKubeAuthProxyCertDirInjectable),
spawn,
};
return (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) => (

View File

@ -5,6 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
import { createKubeAuthProxyCertificateFiles, getKubeAuthProxyCertificatePath } from "./kube-auth-proxy-cert";
import * as selfsigned from "selfsigned";
const getKubeAuthProxyCertDirInjectable = getInjectable({
id: "get-kube-auth-proxy-cert-dir",
@ -13,7 +14,7 @@ const getKubeAuthProxyCertDirInjectable = getInjectable({
const userData = await di.inject(directoryForUserDataInjectable);
const certPath = getKubeAuthProxyCertificatePath(userData);
await createKubeAuthProxyCertificateFiles(certPath);
await createKubeAuthProxyCertificateFiles(certPath, selfsigned.generate);
},
instantiate: (di) => getKubeAuthProxyCertificatePath(di.inject(directoryForUserDataInjectable)),

View File

@ -5,15 +5,17 @@
import { access, mkdir, writeFile } from "fs/promises";
import path from "path";
import * as selfsigned from "selfsigned";
import type * as selfsigned from "selfsigned";
export function getKubeAuthProxyCertificate(): selfsigned.SelfSignedCert {
type SelfSignedGenerate = typeof selfsigned.generate;
export function getKubeAuthProxyCertificate(generate: SelfSignedGenerate): selfsigned.SelfSignedCert {
const opts = [
{ name: "commonName", value: "Lens Certificate Authority" },
{ name: "organizationName", value: "Lens" },
];
return selfsigned.generate(opts, {
return generate(opts, {
keySize: 2048,
algorithm: "sha256",
days: 365,
@ -31,8 +33,8 @@ export function getKubeAuthProxyCertificatePath(baseDir: string) {
return path.join(baseDir, "kube-auth-proxy");
}
export async function createKubeAuthProxyCertificateFiles(dir: string): Promise<string> {
const cert = getKubeAuthProxyCertificate();
export async function createKubeAuthProxyCertificateFiles(dir: string, generateFunc: SelfSignedGenerate): Promise<string> {
const cert = getKubeAuthProxyCertificate(generateFunc);
try {
await access(dir);

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { ChildProcess, spawn } from "child_process";
import type { ChildProcess, spawn } from "child_process";
import { waitUntilUsed } from "tcp-port-used";
import { randomBytes } from "crypto";
import type { Cluster } from "../../common/cluster/cluster";
@ -16,6 +16,7 @@ const startingServeRegex = /starting to serve on (?<address>.+)/i;
export interface KubeAuthProxyDependencies {
proxyBinPath: string;
proxyCertPath: string;
spawn: typeof spawn;
}
export class KubeAuthProxy {
@ -45,7 +46,7 @@ export class KubeAuthProxy {
const proxyBin = this.dependencies.proxyBinPath;
const certPath = await this.dependencies.proxyCertPath;
this.proxyProcess = spawn(proxyBin, [], {
this.proxyProcess = this.dependencies.spawn(proxyBin, [], {
env: {
...this.env,
KUBECONFIG: this.cluster.kubeConfigPath,