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

random micro fixes & refactoring

This commit is contained in:
Roman 2020-06-15 17:47:07 +03:00
parent bfd1a4e0b8
commit d6258b38d0
4 changed files with 9 additions and 24 deletions

View File

@ -141,7 +141,7 @@ export class ContextHandler {
return apiTarget
}
protected async newApiTarget(timeout: number) {
protected async newApiTarget(timeout: number): Promise<ServerOptions> {
return {
changeOrigin: true,
timeout: timeout,

View File

@ -28,9 +28,7 @@ export class KubeAuthProxy {
public async run(): Promise<void> {
if (this.proxyProcess) {
return new Promise((resolve, reject) => {
resolve()
})
return;
}
const proxyBin = await this.kubectl.kubectlPath()
const configWatcher = watch(this.cluster.kubeconfigPath(), (eventType: string, filename: string) => {

View File

@ -98,7 +98,7 @@ export class LensProxy {
ws.on("connection", ((con: WebSocket, req: http.IncomingMessage) => {
const cluster = this.clusterManager.getClusterForRequest(req)
const contextHandler = cluster.contextHandler
const nodeParam = this.getNodeParam(req.url)
const nodeParam = (url.parse(req.url, true).query["node"] || "").toString();
contextHandler.withTemporaryKubeconfig((kubeconfigPath) => {
return new Promise<boolean>(async (resolve, reject) => {
@ -112,18 +112,6 @@ export class LensProxy {
return ws
}
protected getNodeParam(requestUrl: string) {
const reqUrl = url.parse(requestUrl, true)
const urlParams = reqUrl.query
let nodeParam: string = null
for (const [key, value] of Object.entries(urlParams)) {
if (key === "node") {
nodeParam = value.toString()
}
}
return nodeParam
}
protected async getProxyTarget(req: http.IncomingMessage, contextHandler: ContextHandler): Promise<httpProxy.ServerOptions> {
if (req.url.startsWith("/api-kube/")) {
delete req.headers.authorization

View File

@ -131,12 +131,12 @@ export class ShellSession extends EventEmitter {
// send shell output to websocket
this.shellProcess.onData(((data: string) => {
this.sendResponse(data)
}).bind(this));
}));
}
protected pipeStdin() {
// write websocket messages to shellProcess
this.websocket.on("message", function(data: string) {
this.websocket.on("message", (data: string) => {
if (!this.running) { return }
const message = Buffer.from(data.slice(1, data.length), "base64").toString()
@ -149,11 +149,10 @@ export class ShellSession extends EventEmitter {
this.shellProcess.resize(resizeMsgObj["Width"], resizeMsgObj["Height"])
break;
case "9":
this.token = message
this.emit('newToken', this.token)
this.emit('newToken', message)
break;
}
}.bind(this))
})
}
protected exit(code = 1000) {
@ -162,10 +161,10 @@ export class ShellSession extends EventEmitter {
}
protected closeWebsocketOnProcessExit() {
this.shellProcess.on("exit", (code) => {
this.shellProcess.onExit(({ exitCode }) => {
this.running = false
let timeout = 0
if (code > 0) {
if (exitCode > 0) {
this.sendResponse("Terminal will auto-close in 15 seconds ...")
timeout = 15*1000
}