mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
return undefined instead of localhost from getClusterIdFromHost
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
317c4cf072
commit
486083ddba
@ -2,7 +2,7 @@ import fs from "fs";
|
|||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { Cluster } from "../../main/cluster";
|
import { Cluster } from "../../main/cluster";
|
||||||
import { ClusterStore } from "../cluster-store";
|
import { ClusterStore, getClusterIdFromHost } from "../cluster-store";
|
||||||
import { workspaceStore } from "../workspace-store";
|
import { workspaceStore } from "../workspace-store";
|
||||||
|
|
||||||
const testDataIcon = fs.readFileSync("test-data/cluster-store-migration-icon.png");
|
const testDataIcon = fs.readFileSync("test-data/cluster-store-migration-icon.png");
|
||||||
@ -446,3 +446,13 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
|
|||||||
expect(icon.startsWith("data:;base64,")).toBe(true);
|
expect(icon.startsWith("data:;base64,")).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getClusterIdFromHost", () => {
|
||||||
|
it("should return undefined for non cluster frame hosts", () => {
|
||||||
|
expect(getClusterIdFromHost("localhost:45345")).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined for non cluster frame hosts", () => {
|
||||||
|
expect(getClusterIdFromHost("fe540901-0bd6-4f6c-b472-bce1559d7c4a.localhost:59110")).toBe("fe540901-0bd6-4f6c-b472-bce1559d7c4a");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -354,10 +354,15 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
|
|
||||||
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
||||||
|
|
||||||
export function getClusterIdFromHost(hostname: string): ClusterId {
|
export function getClusterIdFromHost(host: string): ClusterId | undefined {
|
||||||
const subDomains = hostname.split(":")[0].split(".");
|
// e.g host == "%clusterId.localhost:45345"
|
||||||
|
const subDomains = host.split(":")[0].split(".");
|
||||||
|
|
||||||
return subDomains.slice(-2)[0]; // e.g host == "%clusterId.localhost:45345"
|
if (subDomains.length >= 2) {
|
||||||
|
return subDomains[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getClusterFrameUrl(clusterId: ClusterId) {
|
export function getClusterFrameUrl(clusterId: ClusterId) {
|
||||||
@ -365,7 +370,7 @@ export function getClusterFrameUrl(clusterId: ClusterId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getHostedClusterId() {
|
export function getHostedClusterId() {
|
||||||
return getClusterIdFromHost(location.hostname);
|
return getClusterIdFromHost(location.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHostedCluster(): Cluster {
|
export function getHostedCluster(): Cluster {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user