Skip to content

Commit 5ccb37c

Browse files
committed
frontend: KubeObject: Refactor getAuthorization logic
Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
1 parent 1e75944 commit 5ccb37c

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

frontend/src/lib/k8s/KubeObject.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,31 +513,22 @@ export class KubeObject<T extends KubeObjectInterface | KubeEvent = any> {
513513

514514
// @todo: We should get the API info from the API endpoint.
515515

516-
// If we already have the group, version, and resource, then we can make the request
517-
// without trying the API info, which may have several versions and thus be less optimal.
516+
// If we already have the group and version, then we can make the request without
517+
// trying the API info, which may have several versions and thus be less optimal.
518518
if (!!resourceAttrs.group && !!resourceAttrs.version && !!resourceAttrs.resource) {
519519
return this.fetchAuthorization(resourceAttrs);
520520
}
521521

522-
// If we don't have the group, version, and resource, then we have to try all of the
522+
// If we don't have the group or version, then we have to try all of the
523523
// API info versions until we find one that works.
524524
const apiInfo = this.apiEndpoint.apiInfo;
525525
for (let i = 0; i < apiInfo.length; i++) {
526-
const { group, version, resource } = apiInfo[i];
527-
// We only take from the details from the apiInfo if they're missing from the resourceAttrs.
526+
const { group, version } = apiInfo[i];
527+
// We only take the details from the apiInfo if they're missing from the resourceAttrs.
528528
// The idea is that, since this function may also be called from the instance's getAuthorization,
529529
// it may already have the details from the instance's API version.
530-
const attrs = { ...resourceAttrs };
531-
532-
if (!!attrs.resource) {
533-
attrs.resource = resource;
534-
}
535-
if (!!attrs.group) {
536-
attrs.group = group;
537-
}
538-
if (!!attrs.version) {
539-
attrs.version = version;
540-
}
530+
// The group and version are tied, so we take both if one is missing.
531+
const attrs = { ...resourceAttrs, group: group, version: version };
541532

542533
let authResult;
543534

0 commit comments

Comments
 (0)