"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/kube-auth-proxy.ts" between
lens-5.1.2.tar.gz and lens-5.1.3.tar.gz

About: Lens is a Kubernetes IDE.

kube-auth-proxy.ts  (lens-5.1.2):kube-auth-proxy.ts  (lens-5.1.3)
skipping to change at line 30 skipping to change at line 30
*/ */
import { ChildProcess, spawn } from "child_process"; import { ChildProcess, spawn } from "child_process";
import { waitUntilUsed } from "tcp-port-used"; import { waitUntilUsed } from "tcp-port-used";
import { broadcastMessage } from "../common/ipc"; import { broadcastMessage } from "../common/ipc";
import type { Cluster } from "./cluster"; import type { Cluster } from "./cluster";
import { Kubectl } from "./kubectl"; import { Kubectl } from "./kubectl";
import logger from "./logger"; import logger from "./logger";
import * as url from "url"; import * as url from "url";
import { getPortFrom } from "./utils/get-port"; import { getPortFrom } from "./utils/get-port";
import { makeObservable, observable, when } from "mobx";
export interface KubeAuthProxyLog { export interface KubeAuthProxyLog {
data: string; data: string;
error?: boolean; // stream=stderr error?: boolean; // stream=stderr
} }
const startingServeRegex = /^starting to serve on (?<address>.+)/i; const startingServeRegex = /^starting to serve on (?<address>.+)/i;
export class KubeAuthProxy { export class KubeAuthProxy {
public lastError: string; public lastError: string;
public get port(): number { public get port(): number {
return this._port; return this._port;
} }
protected _port: number; protected _port: number;
protected cluster: Cluster; protected cluster: Cluster;
protected env: NodeJS.ProcessEnv = null; protected env: NodeJS.ProcessEnv = null;
protected proxyProcess: ChildProcess; protected proxyProcess: ChildProcess;
protected kubectl: Kubectl; protected kubectl: Kubectl;
@observable protected ready: boolean;
constructor(cluster: Cluster, env: NodeJS.ProcessEnv) { constructor(cluster: Cluster, env: NodeJS.ProcessEnv) {
makeObservable(this);
this.ready = false;
this.env = env; this.env = env;
this.cluster = cluster; this.cluster = cluster;
this.kubectl = Kubectl.bundled(); this.kubectl = Kubectl.bundled();
} }
get acceptHosts() { get acceptHosts() {
return url.parse(this.cluster.apiUrl).hostname; return url.parse(this.cluster.apiUrl).hostname;
} }
get whenReady() {
return when(() => this.ready);
}
public async run(): Promise<void> { public async run(): Promise<void> {
if (this.proxyProcess) { if (this.proxyProcess) {
return; return this.whenReady;
} }
const proxyBin = await this.kubectl.getPath(); const proxyBin = await this.kubectl.getPath();
const args = [ const args = [
"proxy", "proxy",
"-p", "0", "-p", "0",
"--kubeconfig", `${this.cluster.kubeConfigPath}`, "--kubeconfig", `${this.cluster.kubeConfigPath}`,
"--context", `${this.cluster.contextName}`, "--context", `${this.cluster.contextName}`,
"--accept-hosts", this.acceptHosts, "--accept-hosts", this.acceptHosts,
"--reject-paths", "^[^/]" "--reject-paths", "^[^/]"
skipping to change at line 106 skipping to change at line 114
this._port = await getPortFrom(this.proxyProcess.stdout, { this._port = await getPortFrom(this.proxyProcess.stdout, {
lineRegex: startingServeRegex, lineRegex: startingServeRegex,
onFind: () => this.sendIpcLogMessage({ data: "Authentication proxy started \n" }), onFind: () => this.sendIpcLogMessage({ data: "Authentication proxy started \n" }),
}); });
this.proxyProcess.stdout.on("data", (data: any) => { this.proxyProcess.stdout.on("data", (data: any) => {
this.sendIpcLogMessage({ data: data.toString() }); this.sendIpcLogMessage({ data: data.toString() });
}); });
return waitUntilUsed(this.port, 500, 10000); await waitUntilUsed(this.port, 500, 10000);
this.ready = true;
} }
protected parseError(data: string) { protected parseError(data: string) {
const error = data.split("http: proxy error:").slice(1).join("").trim(); const error = data.split("http: proxy error:").slice(1).join("").trim();
let errorMsg = error; let errorMsg = error;
const jsonError = error.split("Response: ")[1]; const jsonError = error.split("Response: ")[1];
if (jsonError) { if (jsonError) {
try { try {
const parsedError = JSON.parse(jsonError); const parsedError = JSON.parse(jsonError);
skipping to change at line 135 skipping to change at line 145
} }
protected sendIpcLogMessage(res: KubeAuthProxyLog) { protected sendIpcLogMessage(res: KubeAuthProxyLog) {
const channel = `kube-auth:${this.cluster.id}`; const channel = `kube-auth:${this.cluster.id}`;
logger.info(`[KUBE-AUTH]: out-channel "${channel}"`, { ...res, meta: this.cl uster.getMeta() }); logger.info(`[KUBE-AUTH]: out-channel "${channel}"`, { ...res, meta: this.cl uster.getMeta() });
broadcastMessage(channel, res); broadcastMessage(channel, res);
} }
public exit() { public exit() {
this.ready = false;
if (!this.proxyProcess) return; if (!this.proxyProcess) return;
logger.debug("[KUBE-AUTH]: stopping local proxy", this.cluster.getMeta()); logger.debug("[KUBE-AUTH]: stopping local proxy", this.cluster.getMeta());
this.proxyProcess.kill(); this.proxyProcess.kill();
this.proxyProcess.removeAllListeners(); this.proxyProcess.removeAllListeners();
this.proxyProcess.stderr.removeAllListeners(); this.proxyProcess.stderr.removeAllListeners();
this.proxyProcess.stdout.removeAllListeners(); this.proxyProcess.stdout.removeAllListeners();
this.proxyProcess = null; this.proxyProcess = null;
} }
} }
 End of changes. 7 change blocks. 
2 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)