mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
refactor to better name
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
parent
f68b96efe3
commit
e20d2f361b
@ -41,16 +41,31 @@ export interface IKubeApiLinkBase extends IKubeApiLinkRef {
|
||||
}
|
||||
|
||||
export class KubeApi<T extends KubeObject = any> {
|
||||
static parseApi(apiPath = "") {
|
||||
static parseApi(apiPath = ""): IKubeApiLinkBase {
|
||||
apiPath = new URL(apiPath, location.origin).pathname;
|
||||
|
||||
const [, prefix, ...parts] = apiPath.split("/");
|
||||
const apiPrefix = `/${prefix}`;
|
||||
|
||||
const [left, right, found] = split(parts, "namespaces");
|
||||
const [left, right, namespaced] = split(parts, "namespaces");
|
||||
let apiGroup, apiVersion, namespace, resource, name;
|
||||
|
||||
if (!found) {
|
||||
if (namespaced) {
|
||||
switch (right.length) {
|
||||
case 0:
|
||||
resource = "namespaces"; // special case this due to `split` removing namespaces
|
||||
break;
|
||||
case 1:
|
||||
resource = right[0];
|
||||
break;
|
||||
default:
|
||||
[namespace, resource, name] = right;
|
||||
break;
|
||||
}
|
||||
|
||||
apiVersion = left.pop();
|
||||
apiGroup = left.join("/");
|
||||
} else {
|
||||
switch (left.length) {
|
||||
case 2:
|
||||
resource = left.pop();
|
||||
@ -85,21 +100,6 @@ export class KubeApi<T extends KubeObject = any> {
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (right.length) {
|
||||
case 0:
|
||||
resource = "namespaces"; // special case this due to `split` removing namespaces
|
||||
break;
|
||||
case 1:
|
||||
resource = right[0];
|
||||
break;
|
||||
default:
|
||||
[namespace, resource, name] = right;
|
||||
break;
|
||||
}
|
||||
|
||||
apiVersion = left.pop();
|
||||
apiGroup = left.join("/");
|
||||
}
|
||||
|
||||
const apiVersionWithGroup = [apiGroup, apiVersion].filter(v => v).join("/");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user