Turn on strict mode in tsconfig.json

- Add route, clusterRoute, and payloadValidatedClusterRoute helper
  functions to improve types with backend routes

- Turn on the following new lints:
  - react/jsx-first-prop-new-line
  - react/jsx-wrap-multilines
  - react/jsx-one-expression-per-line
  - react/jsx-max-props-per-line
  - react/jsx-indent
  - react/jsx-indent-props

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-05-04 08:45:50 -04:00
1 parent e532b90b72
commit f594bf03f3
689 files changed
+14529 -11302

No files matched your search

+44 -16
View File
@@ -32,8 +32,20 @@ interface Dependencies {
authProxyCa: string;
}
export class ContextHandler {
public clusterUrl: UrlWithStringQuery;
export interface ClusterContextHandler {
readonly clusterUrl: UrlWithStringQuery;
setupPrometheus(preferences?: ClusterPrometheusPreferences): void;
getPrometheusDetails(): Promise<PrometheusDetails>;
resolveAuthProxyUrl(): Promise<string>;
resolveAuthProxyCa(): string;
getApiTarget(isLongRunningRequest?: boolean): Promise<httpProxy.ServerOptions>;
restartServer(): Promise<void>;
ensureServer(): Promise<void>;
stopServer(): void;
}
export class ContextHandler implements ClusterContextHandler {
public readonly clusterUrl: UrlWithStringQuery;
protected kubeAuthProxy?: KubeAuthProxy;
protected apiTarget?: httpProxy.ServerOptions;
protected prometheusProvider?: string;
@@ -46,7 +58,7 @@ export class ContextHandler {
public setupPrometheus(preferences: ClusterPrometheusPreferences = {}) {
this.prometheusProvider = preferences.prometheusProvider?.type;
this.prometheus = preferences.prometheus || null;
this.prometheus = preferences.prometheus;
}
public async getPrometheusDetails(): Promise<PrometheusDetails> {
@@ -82,7 +94,7 @@ export class ContextHandler {
}
protected async getPrometheusService(): Promise<PrometheusService> {
if (this.prometheus !== null && this.prometheusProvider !== null) {
if (this.prometheus && this.prometheusProvider) {
return {
id: this.prometheusProvider,
namespace: this.prometheus.namespace,
@@ -117,11 +129,11 @@ export class ContextHandler {
throw Object.assign(new Error("No Prometheus service found"), { cause: errors });
}
async resolveAuthProxyUrl() {
await this.ensureServer();
async resolveAuthProxyUrl(): Promise<string> {
const kubeAuthProxy = await this.ensureServerHelper();
const path = this.clusterUrl.path !== "/" ? this.clusterUrl.path : "";
return `https://127.0.0.1:${this.kubeAuthProxy.port}${this.kubeAuthProxy.apiPrefix}${path}`;
return `https://127.0.0.1:${kubeAuthProxy.port}${kubeAuthProxy.apiPrefix}${path}`;
}
resolveAuthProxyCa() {
@@ -139,30 +151,32 @@ export class ContextHandler {
}
protected async newApiTarget(timeout: number): Promise<httpProxy.ServerOptions> {
await this.ensureServer();
const ca = this.dependencies.authProxyCa;
const kubeAuthProxy = await this.ensureServerHelper();
const ca = this.resolveAuthProxyCa();
const clusterPath = this.clusterUrl.path !== "/" ? this.clusterUrl.path : "";
const apiPrefix = `${this.kubeAuthProxy.apiPrefix}${clusterPath}`;
const apiPrefix = `${kubeAuthProxy.apiPrefix}${clusterPath}`;
const headers: Record<string, string> = {};
if (this.clusterUrl.hostname) {
headers.Host = this.clusterUrl.hostname;
}
return {
target: {
protocol: "https:",
host: "127.0.0.1",
port: this.kubeAuthProxy.port,
port: kubeAuthProxy.port,
path: apiPrefix,
ca,
},
changeOrigin: true,
timeout,
secure: true,
headers: {
"Host": this.clusterUrl.hostname,
},
headers,
};
}
async ensureServer() {
protected async ensureServerHelper(): Promise<KubeAuthProxy> {
if (!this.kubeAuthProxy) {
const proxyEnv = Object.assign({}, process.env);
@@ -171,9 +185,23 @@ export class ContextHandler {
}
this.kubeAuthProxy = this.dependencies.createKubeAuthProxy(this.cluster, proxyEnv);
await this.kubeAuthProxy.run();
return this.kubeAuthProxy;
}
await this.kubeAuthProxy.whenReady;
return this.kubeAuthProxy;
}
async ensureServer(): Promise<void> {
await this.ensureServerHelper();
}
async restartServer(): Promise<void> {
this.stopServer();
await this.ensureServerHelper();
}
stopServer() {
@@ -5,6 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import selfsigned from "selfsigned";
import type { Cluster } from "../../common/cluster/cluster";
import type { ClusterContextHandler } from "./context-handler";
import { ContextHandler } from "./context-handler";
import createKubeAuthProxyInjectable from "../kube-auth-proxy/create-kube-auth-proxy.injectable";
import { getKubeAuthProxyCertificate } from "../kube-auth-proxy/get-kube-auth-proxy-certificate";
@@ -14,15 +15,18 @@ const createContextHandlerInjectable = getInjectable({
id: "create-context-handler",
instantiate: (di) => {
return (cluster: Cluster) => {
const createKubeAuthProxy = di.inject(createKubeAuthProxyInjectable);
return (cluster: Cluster): ClusterContextHandler => {
const clusterUrl = new URLParse(cluster.apiUrl);
const dependencies = {
createKubeAuthProxy: di.inject(createKubeAuthProxyInjectable),
authProxyCa: getKubeAuthProxyCertificate(clusterUrl.hostname, selfsigned.generate).cert,
};
return new ContextHandler(dependencies, cluster);
return new ContextHandler(
{
createKubeAuthProxy,
authProxyCa: getKubeAuthProxyCertificate(clusterUrl.hostname, selfsigned.generate).cert,
},
cluster,
);
};
},
});