public WebHookAction resolve(final String projectName, StaplerRequest request) { Iterator<String> restOfPathParts = Splitter.on('/').omitEmptyStrings().split(request.getRestOfPath()).iterator(); Item project = resolveProject(projectName, restOfPathParts); if (project == null) { throw HttpResponses.notFound(); } return resolveAction(project, Joiner.on('/').join(restOfPathParts), request); }
/** * Web binding for {@literal /metricsHistory} * * @return the response */ @Restricted(NoExternalUse.class) // only for use by stapler web binding public HttpResponse doMetricsHistory() { if (!Sampler.isEnabled()) { return HttpResponses.notFound(); } return new MetricsHistoryResponse(); }
/** * Binds the metrics history to the CORS aware URL {@code /metrics/metricsHistory} where the metrics access key is * provided in the form field {@code key} or an {@code Authorization: Jenkins-Metrics-Key {key}} header * * @param req the request * @param key the key from the form field. * @return the {@link HttpResponse} * @throws IllegalAccessException if the access attempt is invalid. */ @SuppressWarnings("unused") // stapler binding @Restricted(NoExternalUse.class) // stapler binding public HttpResponse doMetricsHistory(StaplerRequest req, @QueryParameter("key") String key) throws IllegalAccessException { if (!Sampler.isEnabled()) { return HttpResponses.notFound(); } requireCorrectMethod(req); if (StringUtils.isBlank(key)) { key = getKeyFromAuthorizationHeader(req); } Metrics.checkAccessKeyMetrics(key); return Metrics.cors(key, new MetricsHistoryResponse()); }
throw HttpResponses.notFound();
private static Job<?, ?> getProject(String job, Boolean throwErrorWhenNotFound) { Job<?, ?> p = null; if (job != null) { // as the user might have ViewStatus permission only (e.g. as anonymous) we get get the project impersonate and check for permission after getting the project SecurityContext orig = ACL.impersonate(ACL.SYSTEM); try { // first try to get Job via JobSelectorExtensionPoints for (JobSelectorExtensionPoint jobSelector : ExtensionList.lookup(JobSelectorExtensionPoint.class)) { p = jobSelector.select(job); if (p != null) { break; } } if (p == null && jInstance != null) { p = jInstance.getItemByFullName(job, Job.class); } } finally { SecurityContextHolder.setContext(orig); } } // check if user has permission to view the status if(throwErrorWhenNotFound && (p == null || !p.hasPermission(VIEW_STATUS))){ throw HttpResponses.notFound(); } return p; }