/** * Called to determine if there was an incomplete installation, what the statuses of the plugins are */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doIncompleteInstallStatus() { try { Map<String,String> jobs = InstallUtil.getPersistedInstallStatus(); if(jobs == null) { jobs = Collections.emptyMap(); } return HttpResponses.okJSON(jobs); } catch (Exception e) { return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage())); } }
return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage()));
@RequirePOST public HttpResponse doRename(@AncestorInPath User u, @QueryParameter String tokenUuid, @QueryParameter String newName) throws IOException { // only current user + administrator can rename token u.checkPermission(Jenkins.ADMINISTER); if (StringUtils.isBlank(newName)) { return HttpResponses.errorJSON("The name cannot be empty"); } if(StringUtils.isBlank(tokenUuid)){ // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } ApiTokenProperty p = u.getProperty(ApiTokenProperty.class); if (p == null) { return HttpResponses.errorWithoutStack(400, "The user does not have any ApiToken yet, try generating one before."); } boolean renameOk = p.tokenStore.renameToken(tokenUuid, newName); if(!renameOk){ // that could potentially happen if the token is removed from another page // between your page loaded and your action return HttpResponses.errorJSON("No token found, try refreshing the page"); } u.save(); return HttpResponses.ok(); }
@RequirePOST @Restricted(NoExternalUse.class) public HttpResponse doConfigureInstance(StaplerRequest req, @QueryParameter String rootUrl) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); Map<String, String> errors = new HashMap<>(); // pre-check data checkRootUrl(errors, rootUrl); if(!errors.isEmpty()){ return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors); } // use the parameters to configure the instance useRootUrl(errors, rootUrl); if(!errors.isEmpty()){ return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors); } InstallUtil.proceedToNextStateFrom(InstallState.CONFIGURE_INSTANCE); CrumbIssuer crumbIssuer = Jenkins.get().getCrumbIssuer(); JSONObject data = new JSONObject(); if (crumbIssuer != null) { data.accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req)); } return HttpResponses.okJSON(data); }
/** * Installs a list of plugins from a JSON POST. * @param req The request object. * @return A JSON response that includes a "correlationId" in the "data" element. * That "correlationId" can then be used in calls to * {@link UpdateCenter#doInstallStatus(org.kohsuke.stapler.StaplerRequest)}. * @throws IOException Error reading JSON payload fro request. */ @RequirePOST @Restricted(DoNotUse.class) // WebOnly public HttpResponse doInstallPlugins(StaplerRequest req) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String payload = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding()); JSONObject request = JSONObject.fromObject(payload); JSONArray pluginListJSON = request.getJSONArray("plugins"); List<String> plugins = new ArrayList<>(); for (int i = 0; i < pluginListJSON.size(); i++) { plugins.add(pluginListJSON.getString(i)); } UUID correlationId = UUID.randomUUID(); try { boolean dynamicLoad = request.getBoolean("dynamicLoad"); install(plugins, dynamicLoad, correlationId); JSONObject responseData = new JSONObject(); responseData.put("correlationId", correlationId.toString()); return hudson.util.HttpResponses.okJSON(responseData); } catch (Exception e) { return hudson.util.HttpResponses.errorJSON(e.getMessage()); } }
/** * Called to determine if there was an incomplete installation, what the statuses of the plugins are */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doIncompleteInstallStatus() { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); try { Map<String,String> jobs = InstallUtil.getPersistedInstallStatus(); if(jobs == null) { jobs = Collections.emptyMap(); } return HttpResponses.okJSON(jobs); } catch (Exception e) { return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage())); } }
return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage()));
/** * Installs a list of plugins from a JSON POST. * @param req The request object. * @return A JSON response that includes a "correlationId" in the "data" element. * That "correlationId" can then be used in calls to * {@link UpdateCenter#doInstallStatus(org.kohsuke.stapler.StaplerRequest)}. * @throws IOException Error reading JSON payload fro request. */ @RequirePOST @Restricted(DoNotUse.class) // WebOnly public HttpResponse doInstallPlugins(StaplerRequest req) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String payload = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding()); JSONObject request = JSONObject.fromObject(payload); JSONArray pluginListJSON = request.getJSONArray("plugins"); List<String> plugins = new ArrayList<>(); for (int i = 0; i < pluginListJSON.size(); i++) { plugins.add(pluginListJSON.getString(i)); } UUID correlationId = UUID.randomUUID(); try { boolean dynamicLoad = request.getBoolean("dynamicLoad"); install(plugins, dynamicLoad, correlationId); JSONObject responseData = new JSONObject(); responseData.put("correlationId", correlationId.toString()); return hudson.util.HttpResponses.okJSON(responseData); } catch (Exception e) { return hudson.util.HttpResponses.errorJSON(e.getMessage()); } }