-
Notifications
You must be signed in to change notification settings - Fork 247
[JENKINS-19413] Use CredentialsDescriptor.findContextInPath rather than directly StaplerRequest2.findAncestorObject
#651
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
Conversation
…than directly `StaplerRequest2.findAncestorObject`
| if (request != null) { | ||
| context = request.findAncestorObject(ModelObject.class); | ||
| } | ||
| context = CredentialsDescriptor.findContextInPath(ModelObject.class); |
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.
The existing code had a check that we are in a Stapler request. if that was needed this will now throw a NullPointerException, did you check that calls to this are only web methods?
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 double check but the other overload of this method passed in StaplerRequest2 already without checking. (It would make no sense outside of a request context.)
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.
CredentialsSelectHelper methods touched here are used from
| <j:set var="context" value="${selectHelper.resolveContext(attrs.context ?: it)}"/> |
credentials-plugin/src/main/resources/lib/credentials/select.jelly
Lines 115 to 117 in f8963c3
| <j:set var="storeItems" value="${selectHelper.getStoreItems(context, includeUser)}"/> | |
| <j:choose> | |
| <j:when test="${selectHelper.hasCreatePermission(context, includeUser) and storeItems != null and !storeItems.isEmpty()}"> |
Whereas
credentials-plugin/src/main/java/com/cloudbees/plugins/credentials/CredentialsDescriptor.java
Line 328 in f8963c3
| public static <T extends ModelObject> T findContextInPath(@NonNull StaplerRequest2 request, @NonNull Class<T> type) { |
credentials-plugin/src/main/java/com/cloudbees/plugins/credentials/ContextInPath.java
Line 44 in f8963c3
| return CredentialsDescriptor.findContextInPath(request, type); |
| StaplerRequest2 request = Stapler.getCurrentRequest2(); | ||
| if (request != null) { | ||
| return request.findAncestorObject(ModelObject.class); | ||
| } | ||
| return null; |
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.
The existing code had a check that we where in a Stapler request. if that was needed this will now throw a NullPointerException, did you check that calls to this are only web methods, or that null is never passed for any non web methods?
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.
#651 (comment) again
Fixes jenkinsci/ec2-fleet-plugin#491 and similarly enables jenkinsci/jenkins#11055.
Using utility from #62 (comment) rather than copying
StaplerRefererfrom other plugins, where it is limited toItem(here we actually needUserat least). See also #373 (comment).