mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
refactor
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
a3b7ebcfc1
commit
b05e87ef99
@ -5,14 +5,16 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import * as selfsigned from "selfsigned";
|
import * as selfsigned from "selfsigned";
|
||||||
import { createKubeAuthProxyCertFiles } from "./create-kube-auth-proxy-cert-files";
|
import { createKubeAuthProxyCertFiles } from "./create-kube-auth-proxy-cert-files";
|
||||||
import getKubeAuthProxyCertDirInjectable from "./kube-auth-proxy-cert.injectable";
|
|
||||||
import writeFileInjectable from "../../common/fs/write-file.injectable";
|
import writeFileInjectable from "../../common/fs/write-file.injectable";
|
||||||
|
import directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
const createKubeAuthProxyCertFilesInjectable = getInjectable({
|
const createKubeAuthProxyCertFilesInjectable = getInjectable({
|
||||||
id: "create-kube-auth-proxy-cert-files",
|
id: "create-kube-auth-proxy-cert-files",
|
||||||
|
|
||||||
instantiate: async (di) => {
|
instantiate: async (di) => {
|
||||||
const certPath = di.inject(getKubeAuthProxyCertDirInjectable);
|
const userData = di.inject(directoryForUserDataInjectable);
|
||||||
|
const certPath = path.join(userData, "kube-auth-proxy");
|
||||||
|
|
||||||
return createKubeAuthProxyCertFiles(certPath, {
|
return createKubeAuthProxyCertFiles(certPath, {
|
||||||
generate: selfsigned.generate,
|
generate: selfsigned.generate,
|
||||||
|
|||||||
@ -3,15 +3,16 @@
|
|||||||
* 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 getKubeAuthProxyCertDirInjectable from "../kube-auth-proxy/kube-auth-proxy-cert.injectable";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import readFileInjectable from "../../common/fs/read-file.injectable";
|
import readFileInjectable from "../../common/fs/read-file.injectable";
|
||||||
|
import createKubeAuthProxyCertFilesInjectable from "./create-kube-auth-proxy-cert-files.injectable";
|
||||||
|
|
||||||
const kubeAuthProxyCaInjectable = getInjectable({
|
const kubeAuthProxyCaInjectable = getInjectable({
|
||||||
id: "kube-auth-proxy-ca",
|
id: "kube-auth-proxy-ca",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: async (di) => {
|
||||||
const certPath = di.inject(getKubeAuthProxyCertDirInjectable);
|
const certPath = await di.inject(createKubeAuthProxyCertFilesInjectable);
|
||||||
|
|
||||||
const readFile = di.inject(readFileInjectable);
|
const readFile = di.inject(readFileInjectable);
|
||||||
|
|
||||||
return readFile(path.join(certPath, "proxy.crt"));
|
return readFile(path.join(certPath, "proxy.crt"));
|
||||||
|
|||||||
@ -1,15 +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 directoryForUserDataInjectable from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
||||||
import { getKubeAuthProxyCertificatePath } from "./kube-auth-proxy-cert";
|
|
||||||
|
|
||||||
const getKubeAuthProxyCertDirInjectable = getInjectable({
|
|
||||||
id: "get-kube-auth-proxy-cert-dir",
|
|
||||||
|
|
||||||
instantiate: (di) => getKubeAuthProxyCertificatePath(di.inject(directoryForUserDataInjectable)),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default getKubeAuthProxyCertDirInjectable;
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import path from "path";
|
|
||||||
import type * as selfsigned from "selfsigned";
|
|
||||||
|
|
||||||
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 generate(opts, {
|
|
||||||
keySize: 2048,
|
|
||||||
algorithm: "sha256",
|
|
||||||
days: 365,
|
|
||||||
extensions: [
|
|
||||||
{ name: "basicConstraints", cA: true },
|
|
||||||
{ name: "subjectAltName", altNames: [
|
|
||||||
{ type: 2, value: "localhost" },
|
|
||||||
{ type: 7, ip: "127.0.0.1" },
|
|
||||||
] },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getKubeAuthProxyCertificatePath(baseDir: string) {
|
|
||||||
return path.join(baseDir, "kube-auth-proxy");
|
|
||||||
}
|
|
||||||
@ -70,11 +70,15 @@ export class KubeAuthProxy {
|
|||||||
this.exit();
|
this.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.proxyProcess.stderr.on("data", (data) => {
|
this.proxyProcess.stderr.on("data", (data: Buffer) => {
|
||||||
|
if (data.includes("http: TLS handshake error")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.cluster.broadcastConnectUpdate(data.toString(), true);
|
this.cluster.broadcastConnectUpdate(data.toString(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.proxyProcess.stdout.on("data", (data: any) => {
|
this.proxyProcess.stdout.on("data", (data: Buffer) => {
|
||||||
if (typeof this._port === "number") {
|
if (typeof this._port === "number") {
|
||||||
this.cluster.broadcastConnectUpdate(data.toString());
|
this.cluster.broadcastConnectUpdate(data.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user