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 return apiTarget
} }
protected async newApiTarget(timeout: number) { protected async newApiTarget(timeout: number): Promise<ServerOptions> {
return { return {
changeOrigin: true, changeOrigin: true,
timeout: timeout, timeout: timeout,

View File

@ -28,9 +28,7 @@ export class KubeAuthProxy {
public async run(): Promise<void> { public async run(): Promise<void> {
if (this.proxyProcess) { if (this.proxyProcess) {
return new Promise((resolve, reject) => { return;
resolve()
})
} }
const proxyBin = await this.kubectl.kubectlPath() const proxyBin = await this.kubectl.kubectlPath()
const configWatcher = watch(this.cluster.kubeconfigPath(), (eventType: string, filename: string) => { 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) => { ws.on("connection", ((con: WebSocket, req: http.IncomingMessage) => {
const cluster = this.clusterManager.getClusterForRequest(req) const cluster = this.clusterManager.getClusterForRequest(req)
const contextHandler = cluster.contextHandler const contextHandler = cluster.contextHandler
const nodeParam = this.getNodeParam(req.url) const nodeParam = (url.parse(req.url, true).query["node"] || "").toString();
contextHandler.withTemporaryKubeconfig((kubeconfigPath) => { contextHandler.withTemporaryKubeconfig((kubeconfigPath) => {
return new Promise<boolean>(async (resolve, reject) => { return new Promise<boolean>(async (resolve, reject) => {
@ -112,18 +112,6 @@ export class LensProxy {
return ws 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> { protected async getProxyTarget(req: http.IncomingMessage, contextHandler: ContextHandler): Promise<httpProxy.ServerOptions> {
if (req.url.startsWith("/api-kube/")) { if (req.url.startsWith("/api-kube/")) {
delete req.headers.authorization delete req.headers.authorization

View File

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