Skip to content

Commit

Permalink
Merge pull request #2654 from headlamp-k8s/row-action-bugs
Browse files Browse the repository at this point in the history
frontend: KubeObject: Refactor getAuthorization logic
  • Loading branch information
joaquimrocha authored Jan 7, 2025
2 parents 56d846b + cf5b206 commit 5422d68
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions frontend/src/lib/k8s/KubeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,36 +508,24 @@ export class KubeObject<T extends KubeObjectInterface | KubeEvent = any> {
};

if (!resourceAttrs.resource) {
resourceAttrs['resource'] = this.pluralName;
resourceAttrs['resource'] = this.apiName;
}

// @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.
// 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;
}
const { group, version } = apiInfo[i];
// The group and version are tied, so we take both if one is missing.
const attrs = { ...resourceAttrs, group: group, version: version };

let authResult;

Expand Down

0 comments on commit 5422d68

Please sign in to comment.