mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
/**
|
|
* 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 { KubeAuthProxy, KubeAuthProxyDependencies } from "./kube-auth-proxy";
|
|
import type { Cluster } from "../../common/cluster/cluster";
|
|
import path from "path";
|
|
import selfsigned from "selfsigned";
|
|
import { getBinaryName } from "../../common/vars";
|
|
import directoryForBundledBinariesInjectable from "../../common/app-paths/directory-for-bundled-binaries/directory-for-bundled-binaries.injectable";
|
|
import spawnInjectable from "../child-process/spawn.injectable";
|
|
import { getKubeAuthProxyCertificate } from "./get-kube-auth-proxy-certificate";
|
|
|
|
export type CreateKubeAuthProxy = (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) => KubeAuthProxy;
|
|
|
|
const createKubeAuthProxyInjectable = getInjectable({
|
|
id: "create-kube-auth-proxy",
|
|
|
|
instantiate: (di): CreateKubeAuthProxy => {
|
|
const binaryName = getBinaryName("lens-k8s-proxy");
|
|
|
|
return (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) => {
|
|
const clusterUrl = new URL(cluster.apiUrl);
|
|
const dependencies: KubeAuthProxyDependencies = {
|
|
proxyBinPath: path.join(di.inject(directoryForBundledBinariesInjectable), binaryName),
|
|
proxyCert: getKubeAuthProxyCertificate(clusterUrl.hostname, selfsigned.generate),
|
|
spawn: di.inject(spawnInjectable),
|
|
};
|
|
|
|
return new KubeAuthProxy(dependencies, cluster, environmentVariables);
|
|
};
|
|
},
|
|
});
|
|
|
|
export default createKubeAuthProxyInjectable;
|