From 5ccb37c334dc91df5ddf6d56aec370d56789de78 Mon Sep 17 00:00:00 2001 From: Evangelos Skopelitis Date: Mon, 16 Dec 2024 17:25:27 -0500 Subject: [PATCH] frontend: KubeObject: Refactor getAuthorization logic Signed-off-by: Evangelos Skopelitis --- frontend/src/lib/k8s/KubeObject.ts | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/frontend/src/lib/k8s/KubeObject.ts b/frontend/src/lib/k8s/KubeObject.ts index 38d7f857cd..339bb7e7ee 100644 --- a/frontend/src/lib/k8s/KubeObject.ts +++ b/frontend/src/lib/k8s/KubeObject.ts @@ -513,31 +513,22 @@ export class KubeObject { // @todo: We should get the API info from the API endpoint. - // If we already have the group, version, and resource, then we can make the request - // without trying the API info, which may have several versions and thus be less optimal. + // If we already have the group and version, then we can make the request without + // trying the API info, which may have several versions and thus be less optimal. if (!!resourceAttrs.group && !!resourceAttrs.version && !!resourceAttrs.resource) { return this.fetchAuthorization(resourceAttrs); } - // If we don't have the group, version, and resource, then we have to try all of the + // If we don't have the group or version, then we have to try all of the // API info versions until we find one that works. const apiInfo = this.apiEndpoint.apiInfo; for (let i = 0; i < apiInfo.length; i++) { - const { group, version, resource } = apiInfo[i]; - // We only take from the details from the apiInfo if they're missing from the resourceAttrs. + const { group, version } = apiInfo[i]; + // We only take the details from the apiInfo if they're missing from the resourceAttrs. // The idea is that, since this function may also be called from the instance's getAuthorization, // it may already have the details from the instance's API version. - const attrs = { ...resourceAttrs }; - - if (!!attrs.resource) { - attrs.resource = resource; - } - if (!!attrs.group) { - attrs.group = group; - } - if (!!attrs.version) { - attrs.version = version; - } + // The group and version are tied, so we take both if one is missing. + const attrs = { ...resourceAttrs, group: group, version: version }; let authResult;