New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1878953: Fix RBAC with upload form and golden images #7685
Conversation
@glekner: This pull request references Bugzilla bug 1878953, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh |
@glekner: This pull request references Bugzilla bug 1878953, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. 3 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
c6d9533
to
4e0753b
Compare
const goldenNamespaces = React.useMemo(() => { | ||
return [ | ||
...new Set( | ||
(commonTemplates || []) | ||
.map((template) => getParameterValue(template, TEMPLATE_BASE_IMAGE_NAMESPACE_PARAMETER)) | ||
.filter((ns) => !!ns), | ||
), | ||
]; | ||
}, [commonTemplates]); | ||
|
||
const goldenNamespacesResources = React.useMemo(() => { | ||
return goldenNamespaces.map((ns) => ({ | ||
group: DataVolumeModel.apiGroup, | ||
resource: DataVolumeModel.plural, | ||
verb: 'create' as K8sVerb, | ||
namespace: ns, | ||
})); | ||
}, [goldenNamespaces]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be done in one useMemo
export const useMultipleAccessReviews = ( | ||
multipleResourceAttributes: AccessReviewResourceAttributes[], | ||
impersonate?, | ||
): [{ resourceAttributes: AccessReviewResourceAttributes; allowed: boolean }[], boolean] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would extract this { resourceAttributes: AccessReviewResourceAttributes; allowed: boolean }
as separate type as it can be reused later - ie type AccessReviewsResult = { resourceAttributes: AccessReviewResourceAttributes; allowed: boolean };
but feel free to pick a better name.
impersonate?, | ||
): [{ resourceAttributes: AccessReviewResourceAttributes; allowed: boolean }[], boolean] => { | ||
const [loading, setLoading] = React.useState(true); | ||
const [allowedArr, setAllowedArr] = React.useState([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [allowedArr, setAllowedArr] = React.useState([]); | |
const [allowedArr, setAllowedArr] = React.useState<AccessReviewsResult[]>([]); |
const promises = multipleResourceAttributes.map((resourceAttributes) => { | ||
const { | ||
group = '', | ||
resource = '', | ||
subresource = '', | ||
verb = '' as K8sVerb, | ||
name = '', | ||
namespace = '', | ||
} = resourceAttributes; | ||
const impersonateKey = getImpersonateKey(impersonate); | ||
return checkAccessInternal( | ||
group, | ||
resource, | ||
subresource, | ||
verb, | ||
name, | ||
namespace, | ||
impersonateKey, | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can reuse checkAccess
const promises = multipleResourceAttributes.map((resourceAttributes) => { | |
const { | |
group = '', | |
resource = '', | |
subresource = '', | |
verb = '' as K8sVerb, | |
name = '', | |
namespace = '', | |
} = resourceAttributes; | |
const impersonateKey = getImpersonateKey(impersonate); | |
return checkAccessInternal( | |
group, | |
resource, | |
subresource, | |
verb, | |
name, | |
namespace, | |
impersonateKey, | |
); | |
}); | |
const promises = multipleResourceAttributes.map((resourceAttributes) => | |
checkAccess(resourceAttributes, impersonate), | |
); |
Promise.all(promises) | ||
.then((values) => { | ||
setLoading(false); | ||
const updatedAllowedArr = (values || []).map((result: SelfSubjectAccessReviewKind) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think you need []
fallback. You also dont need to specify result: SelfSubjectAccessReviewKind
as that is correctly infered from promises
.
I would also prefer to specify generic for map as AccessReviewsResult
const updatedAllowedArr = (values || []).map((result: SelfSubjectAccessReviewKind) => ({ | |
const updatedAllowedArr = (values).map<AccessReviewsResult>((result) => ({ |
setLoading(false); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [multipleResourceAttributes]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not ignore impersonate
as dependency. (and delete // eslint-disable-next-line react-hooks/exhaustive-deps
above it)
@@ -124,6 +124,55 @@ export const useAccessReview2 = ( | |||
return [isAllowed, loading]; | |||
}; | |||
|
|||
export const useMultipleAccessReviews = ( | |||
multipleResourceAttributes: AccessReviewResourceAttributes[], | |||
impersonate?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impersonate?, | |
impersonate?: boolean, |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: glekner, rawagner The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest Please review the full test history for this PR and help us cut down flakes. |
7 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
@glekner: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/retest Please review the full test history for this PR and help us cut down flakes. |
@glekner: All pull requests linked via external trackers have merged: Bugzilla bug 1878953 has been moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
No description provided.