mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove sign along changes
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1a5ebc94f4
commit
fb109e8cff
@ -9,7 +9,7 @@ import { comparer } from "mobx";
|
|||||||
export class Tracker extends Util.Singleton {
|
export class Tracker extends Util.Singleton {
|
||||||
static readonly GA_ID = "UA-159377374-1";
|
static readonly GA_ID = "UA-159377374-1";
|
||||||
static readonly SEGMENT_KEY = "YENwswyhlOgz8P7EFKUtIZ2MfON7Yxqb";
|
static readonly SEGMENT_KEY = "YENwswyhlOgz8P7EFKUtIZ2MfON7Yxqb";
|
||||||
protected eventHandlers: Array<(ev: EventBus.AppEvent) => void> = [];
|
protected eventHandlers: Array<(ev: EventBus.AppEvent ) => void> = [];
|
||||||
protected started = false;
|
protected started = false;
|
||||||
protected visitor: ua.Visitor;
|
protected visitor: ua.Visitor;
|
||||||
protected analytics: Analytics;
|
protected analytics: Analytics;
|
||||||
@ -124,28 +124,30 @@ export class Tracker extends Util.Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected resolveOS() {
|
protected resolveOS() {
|
||||||
|
let os = "";
|
||||||
if (App.isMac) {
|
if (App.isMac) {
|
||||||
return "MacOS";
|
os = "MacOS";
|
||||||
|
} else if(App.isWindows) {
|
||||||
|
os = "Windows";
|
||||||
|
} else if (App.isLinux) {
|
||||||
|
os = "Linux";
|
||||||
|
if (App.isSnap) {
|
||||||
|
os += "; Snap";
|
||||||
|
} else {
|
||||||
|
os += "; AppImage";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
os = "Unknown";
|
||||||
}
|
}
|
||||||
|
return os;
|
||||||
if (App.isWindows) {
|
|
||||||
return "Windows";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (App.isLinux) {
|
|
||||||
return `Linux; ${App.isSnap ? "Snap" : "AppImage"}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Unknown";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async event(eventCategory: string, eventAction: string, otherParams = {}) {
|
protected async event(eventCategory: string, eventAction: string, otherParams = {}) {
|
||||||
const allowed = await this.isTelemetryAllowed();
|
|
||||||
if (!allowed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const allowed = await this.isTelemetryAllowed();
|
||||||
|
if (!allowed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.visitor.event({
|
this.visitor.event({
|
||||||
ec: eventCategory,
|
ec: eventCategory,
|
||||||
ea: eventAction,
|
ea: eventAction,
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import { Router } from "./router";
|
|||||||
import { ClusterManager } from "./cluster-manager";
|
import { ClusterManager } from "./cluster-manager";
|
||||||
import { ContextHandler } from "./context-handler";
|
import { ContextHandler } from "./context-handler";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
import _ from "lodash";
|
|
||||||
|
|
||||||
export class LensProxy {
|
export class LensProxy {
|
||||||
protected origin: string;
|
protected origin: string;
|
||||||
@ -65,55 +64,50 @@ export class LensProxy {
|
|||||||
|
|
||||||
protected async handleProxyUpgrade(proxy: httpProxy, req: http.IncomingMessage, socket: net.Socket, head: Buffer) {
|
protected async handleProxyUpgrade(proxy: httpProxy, req: http.IncomingMessage, socket: net.Socket, head: Buffer) {
|
||||||
const cluster = this.clusterManager.getClusterForRequest(req);
|
const cluster = this.clusterManager.getClusterForRequest(req);
|
||||||
if (!cluster) {
|
if (cluster) {
|
||||||
return;
|
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "");
|
||||||
}
|
const apiUrl = url.parse(cluster.apiUrl);
|
||||||
|
const pUrl = url.parse(proxyUrl);
|
||||||
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "");
|
const connectOpts = { port: parseInt(pUrl.port), host: pUrl.hostname };
|
||||||
const apiUrl = url.parse(cluster.apiUrl);
|
const proxySocket = new net.Socket();
|
||||||
const pUrl = url.parse(proxyUrl);
|
proxySocket.connect(connectOpts, () => {
|
||||||
const connectOpts = { port: parseInt(pUrl.port), host: pUrl.hostname };
|
proxySocket.write(`${req.method} ${pUrl.path} HTTP/1.1\r\n`);
|
||||||
const proxySocket = new net.Socket();
|
proxySocket.write(`Host: ${apiUrl.host}\r\n`);
|
||||||
proxySocket.connect(connectOpts, () => {
|
for (let i = 0; i < req.rawHeaders.length; i += 2) {
|
||||||
proxySocket.write(`${req.method} ${pUrl.path} HTTP/1.1\r\n`);
|
const key = req.rawHeaders[i];
|
||||||
proxySocket.write(`Host: ${apiUrl.host}\r\n`);
|
if (key !== "Host" && key !== "Authorization") {
|
||||||
|
proxySocket.write(`${req.rawHeaders[i]}: ${req.rawHeaders[i+1]}\r\n`);
|
||||||
for (const [key, value] of _.chunk(req.rawHeaders, 2)) {
|
}
|
||||||
if (["Host", "Authorization"].includes(key)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
proxySocket.write("\r\n");
|
||||||
|
proxySocket.write(head);
|
||||||
|
});
|
||||||
|
|
||||||
proxySocket.write(`${key}: ${value}\r\n`);
|
proxySocket.setKeepAlive(true);
|
||||||
}
|
socket.setKeepAlive(true);
|
||||||
|
proxySocket.setTimeout(0);
|
||||||
|
socket.setTimeout(0);
|
||||||
|
|
||||||
proxySocket.write("\r\n");
|
proxySocket.on('data', function (chunk) {
|
||||||
proxySocket.write(head);
|
socket.write(chunk);
|
||||||
});
|
});
|
||||||
|
proxySocket.on('end', function () {
|
||||||
proxySocket.setKeepAlive(true);
|
socket.end();
|
||||||
socket.setKeepAlive(true);
|
});
|
||||||
proxySocket.setTimeout(0);
|
proxySocket.on('error', function (err) {
|
||||||
socket.setTimeout(0);
|
socket.write("HTTP/" + req.httpVersion + " 500 Connection error\r\n\r\n");
|
||||||
|
socket.end();
|
||||||
proxySocket.on('data', function (chunk) {
|
});
|
||||||
socket.write(chunk);
|
socket.on('data', function (chunk) {
|
||||||
});
|
proxySocket.write(chunk);
|
||||||
proxySocket.on('end', function () {
|
});
|
||||||
socket.end();
|
socket.on('end', function () {
|
||||||
});
|
proxySocket.end();
|
||||||
proxySocket.on('error', function (err) {
|
});
|
||||||
socket.write(`HTTP/${req.httpVersion} 500 Connection error\r\n\r\n`);
|
socket.on('error', function () {
|
||||||
socket.end();
|
proxySocket.end();
|
||||||
});
|
});
|
||||||
socket.on('data', function (chunk) {
|
}
|
||||||
proxySocket.write(chunk);
|
|
||||||
});
|
|
||||||
socket.on('end', function () {
|
|
||||||
proxySocket.end();
|
|
||||||
});
|
|
||||||
socket.on('error', function () {
|
|
||||||
proxySocket.end();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createProxy(): httpProxy {
|
protected createProxy(): httpProxy {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
import { EventEmitter } from "../../common/event-emitter";
|
import { EventEmitter } from "../../common/event-emitter";
|
||||||
import { cancelableFetch, CancelablePromise } from "../utils/cancelableFetch";
|
import { cancelableFetch } from "../utils/cancelableFetch";
|
||||||
|
|
||||||
export interface JsonApiData {
|
export interface JsonApiData {
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
return this.request<T>(path, params, { ...reqInit, method: "delete" });
|
return this.request<T>(path, params, { ...reqInit, method: "delete" });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected request<D>(path: string, params?: P, init: RequestInit = {}): CancelablePromise<D> {
|
protected request<D>(path: string, params?: P, init: RequestInit = {}) {
|
||||||
let reqUrl = this.config.apiBase + path;
|
let reqUrl = this.config.apiBase + path;
|
||||||
const reqInit: RequestInit = { ...this.reqInit, ...init };
|
const reqInit: RequestInit = { ...this.reqInit, ...init };
|
||||||
const { data, query } = params || {} as P;
|
const { data, query } = params || {} as P;
|
||||||
@ -92,27 +92,28 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async parseResponse<D>(res: Response, log: JsonApiLog): Promise<D> {
|
protected parseResponse<D>(res: Response, log: JsonApiLog): Promise<D> {
|
||||||
const { status } = res;
|
const { status } = res;
|
||||||
const text = await res.text();
|
return res.text().then(text => {
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = text ? JSON.parse(text) : ""; // DELETE-requests might not have response-body
|
data = text ? JSON.parse(text) : ""; // DELETE-requests might not have response-body
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data = text;
|
data = text;
|
||||||
}
|
}
|
||||||
if (status >= 200 && status < 300) {
|
if (status >= 200 && status < 300) {
|
||||||
this.onData.emit(data, res);
|
this.onData.emit(data, res);
|
||||||
this.writeLog({ ...log, data });
|
this.writeLog({ ...log, data });
|
||||||
return data;
|
return data;
|
||||||
} else if (log.method === "GET" && res.status === 403) {
|
} else if (log.method === "GET" && res.status === 403) {
|
||||||
this.writeLog({ ...log, data });
|
this.writeLog({ ...log, data });
|
||||||
} else {
|
} else {
|
||||||
const error = new JsonApiErrorParsed(data, this.parseError(data, res));
|
const error = new JsonApiErrorParsed(data, this.parseError(data, res));
|
||||||
this.onError.emit(error, res);
|
this.onError.emit(error, res);
|
||||||
this.writeLog({ ...log, error });
|
this.writeLog({ ...log, error });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected parseError(error: JsonApiError | string, res: Response): string[] {
|
protected parseError(error: JsonApiError | string, res: Response): string[] {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user