Skip to content

Commit 5422d68

Browse files
authored
Merge pull request #2654 from headlamp-k8s/row-action-bugs
frontend: KubeObject: Refactor getAuthorization logic
2 parents 56d846b + cf5b206 commit 5422d68

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

frontend/src/lib/k8s/KubeObject.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -508,36 +508,24 @@ export class KubeObject<T extends KubeObjectInterface | KubeEvent = any> {
508508
};
509509

510510
if (!resourceAttrs.resource) {
511-
resourceAttrs['resource'] = this.pluralName;
511+
resourceAttrs['resource'] = this.apiName;
512512
}
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.
528-
// The idea is that, since this function may also be called from the instance's getAuthorization,
529-
// 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-
}
526+
const { group, version } = apiInfo[i];
527+
// The group and version are tied, so we take both if one is missing.
528+
const attrs = { ...resourceAttrs, group: group, version: version };
541529

542530
let authResult;
543531

0 commit comments

Comments
 (0)