mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Get tests passing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
2de306810e
commit
d293554c42
37 files changed
+612
-225
No files matched your search
@@ -17,30 +17,43 @@ const getClusterForRequestInjectable = getInjectable({
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
|
||||
return (req) => {
|
||||
if (!req.headers.host) {
|
||||
const { host } = req.headers;
|
||||
|
||||
if (!host || !req.url) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// lens-server is connecting to 127.0.0.1:<port>/<uid>
|
||||
if (req.url && req.headers.host.startsWith("127.0.0.1")) {
|
||||
const clusterId = req.url.split("/")[1];
|
||||
const cluster = getClusterById(clusterId);
|
||||
if (host.startsWith("127.0.0.1") || host.startsWith("localhost")) {
|
||||
{
|
||||
const clusterId = req.url.split("/")[1];
|
||||
const cluster = getClusterById(clusterId);
|
||||
|
||||
if (cluster) {
|
||||
// we need to swap path prefix so that request is proxied to kube api
|
||||
req.url = req.url.replace(`/${clusterId}`, apiKubePrefix);
|
||||
if (cluster) {
|
||||
// we need to swap path prefix so that request is proxied to kube api
|
||||
req.url = req.url.replace(`/${clusterId}`, apiKubePrefix);
|
||||
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
|
||||
return cluster;
|
||||
{
|
||||
const searchParams = new URLSearchParams(req.url);
|
||||
const clusterId = searchParams.get("clusterId");
|
||||
|
||||
if (clusterId) {
|
||||
return getClusterById(clusterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const clusterId = getClusterIdFromHost(req.headers.host);
|
||||
const clusterId = getClusterIdFromHost(host);
|
||||
|
||||
if (!clusterId) {
|
||||
return undefined;
|
||||
if (clusterId) {
|
||||
return getClusterById(clusterId);
|
||||
}
|
||||
|
||||
return getClusterById(clusterId);
|
||||
return undefined;
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ export class LensProxy {
|
||||
protected retryCounters = new Map<string, number>();
|
||||
|
||||
constructor(private readonly dependencies: Dependencies) {
|
||||
this.configureProxy(dependencies.proxy);
|
||||
this.configureProxy(this.dependencies.proxy);
|
||||
|
||||
this.proxyServer = https.createServer(
|
||||
{
|
||||
@@ -91,8 +91,13 @@ export class LensProxy {
|
||||
const isInternal = req.url.startsWith(`${apiPrefix}?`);
|
||||
const reqHandler = isInternal ? this.dependencies.shellApiRequest : this.dependencies.kubeApiUpgradeRequest;
|
||||
|
||||
(async () => reqHandler({ req, socket, head, cluster }))()
|
||||
.catch(error => this.dependencies.logger.error("[LENS-PROXY]: failed to handle proxy upgrade", error));
|
||||
(async () => {
|
||||
try {
|
||||
await reqHandler({ req, socket, head, cluster });
|
||||
} catch (error) {
|
||||
this.dependencies.logger.error("[LENS-PROXY]: failed to handle proxy upgrade", error);
|
||||
}
|
||||
})();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,14 +27,21 @@ const shellApiRequestInjectable = getInjectable({
|
||||
const nodeName = searchParams.get("node");
|
||||
const shellToken = searchParams.get("shellToken");
|
||||
|
||||
console.log("got shell api request", { tabId, clusterId: cluster?.id, nodeName });
|
||||
|
||||
if (!tabId || !cluster || !shellApiAuthenticator.authenticate(cluster.id, tabId, shellToken)) {
|
||||
socket.write("Invalid shell request");
|
||||
socket.end();
|
||||
} else {
|
||||
new WebSocketServer({ noServer: true })
|
||||
.handleUpgrade(req, socket, head, (websocket) => {
|
||||
openShellSession({ websocket, cluster, tabId, nodeName })
|
||||
.catch(error => logger.error(`[SHELL-SESSION]: failed to open a ${nodeName ? "node" : "local"} shell`, error));
|
||||
(async () => {
|
||||
try {
|
||||
await openShellSession({ websocket, cluster, tabId, nodeName });
|
||||
} catch (error) {
|
||||
logger.error(`[SHELL-SESSION]: failed to open a ${nodeName ? "node" : "local"} shell`, error);
|
||||
}
|
||||
})();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user