Search in sources :

Example 6 with WebMethod

use of org.kohsuke.stapler.WebMethod in project blueocean-plugin by jenkinsci.

the class BitbucketServerEndpoint method doDelete.

@WebMethod(name = "")
@DELETE
public void doDelete(StaplerResponse resp) {
    final BitbucketEndpointConfiguration config = BitbucketEndpointConfiguration.get();
    config.removeEndpoint(getApiUrl());
    resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : BitbucketEndpointConfiguration(com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration) WebMethod(org.kohsuke.stapler.WebMethod) DELETE(org.kohsuke.stapler.verb.DELETE)

Example 7 with WebMethod

use of org.kohsuke.stapler.WebMethod in project blueocean-plugin by jenkinsci.

the class SigningPublicKey method asJSON.

/**
 * Renders the key as JSON in the JWK format.
 */
@WebMethod(name = "")
public JSONObject asJSON() {
    JSONObject jwk = new JSONObject();
    jwk.put("kty", "RSA");
    jwk.put("alg", "RS256");
    jwk.put("kid", kid);
    jwk.put("use", "sig");
    jwk.put("key_ops", Collections.singleton("verify"));
    jwk.put("n", Base64.getUrlEncoder().withoutPadding().encodeToString(key.getModulus().toByteArray()));
    jwk.put("e", Base64.getUrlEncoder().withoutPadding().encodeToString(key.getPublicExponent().toByteArray()));
    return jwk;
}
Also used : JSONObject(net.sf.json.JSONObject) WebMethod(org.kohsuke.stapler.WebMethod)

Example 8 with WebMethod

use of org.kohsuke.stapler.WebMethod in project blueocean-plugin by jenkinsci.

the class CredentialApi method create.

@POST
@WebMethod(name = "")
public CreateResponse create(@JsonBody JSONObject body, StaplerRequest request) throws IOException {
    User authenticatedUser = User.current();
    if (authenticatedUser == null) {
        throw new ServiceException.UnauthorizedException("No authenticated user found");
    }
    JSONObject jsonObject = body.getJSONObject("credentials");
    final IdCredentials credentials = request.bindJSON(IdCredentials.class, jsonObject);
    String domainName = DOMAIN_NAME;
    if (jsonObject.get("domain") != null && jsonObject.get("domain") instanceof String) {
        domainName = (String) jsonObject.get("domain");
    }
    CredentialsUtils.createCredentialsInUserStore(credentials, authenticatedUser, domainName, Collections.singletonList(new BlueOceanDomainSpecification()));
    CredentialsStoreAction.DomainWrapper domainWrapper = credentialStoreAction.getDomain(domainName);
    if (domainWrapper != null) {
        CredentialsStoreAction.CredentialsWrapper credentialsWrapper = domainWrapper.getCredential(credentials.getId());
        if (credentialsWrapper != null) {
            return new CreateResponse(new CredentialApi.Credential(credentialsWrapper, getLink().rel("domains").rel(domainName).rel("credentials")));
        }
    }
    // this should never happen
    throw new ServiceException.UnexpectedErrorException("Unexpected error, failed to create credential");
}
Also used : User(hudson.model.User) IdCredentials(com.cloudbees.plugins.credentials.common.IdCredentials) CreateResponse(io.jenkins.blueocean.rest.model.CreateResponse) JSONObject(net.sf.json.JSONObject) CredentialsStoreAction(com.cloudbees.plugins.credentials.CredentialsStoreAction) WebMethod(org.kohsuke.stapler.WebMethod) POST(org.kohsuke.stapler.verb.POST)

Example 9 with WebMethod

use of org.kohsuke.stapler.WebMethod in project workflow-cps-plugin by jenkinsci.

the class CpsThreadDumpAction method doProgramDotXml.

@WebMethod(name = "program.xml")
public void doProgramDotXml(StaplerRequest req, StaplerResponse rsp) throws Exception {
    Jenkins.get().checkPermission(Jenkins.RUN_SCRIPTS);
    CompletableFuture<String> f = new CompletableFuture<>();
    execution.runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {

        @Override
        public void onSuccess(CpsThreadGroup g) {
            try {
                f.complete(g.asXml());
            } catch (Throwable t) {
                f.completeExceptionally(t);
            }
        }

        @Override
        public void onFailure(Throwable t) {
            f.completeExceptionally(t);
        }
    });
    String xml;
    try {
        xml = f.get(1, TimeUnit.MINUTES);
    } catch (Exception x) {
        HttpResponses.error(x).generateResponse(req, rsp, this);
        return;
    }
    rsp.setContentType("text/xml;charset=UTF-8");
    PrintWriter pw = rsp.getWriter();
    pw.print(xml);
    pw.flush();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PrintWriter(java.io.PrintWriter) WebMethod(org.kohsuke.stapler.WebMethod)

Aggregations

WebMethod (org.kohsuke.stapler.WebMethod)9 JSONObject (net.sf.json.JSONObject)3 POST (org.kohsuke.stapler.verb.POST)3 TreeResponse (io.jenkins.blueocean.commons.stapler.TreeResponse)2 IOException (java.io.IOException)2 BitbucketEndpointConfiguration (com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration)1 CredentialsStoreAction (com.cloudbees.plugins.credentials.CredentialsStoreAction)1 IdCredentials (com.cloudbees.plugins.credentials.common.IdCredentials)1 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 XmlFile (hudson.XmlFile)1 Item (hudson.model.Item)1 User (hudson.model.User)1 AtomicFileWriter (hudson.util.AtomicFileWriter)1 IOException2 (hudson.util.IOException2)1 TrackRequest (io.jenkins.blueocean.analytics.Analytics.TrackRequest)1 ErrorMessage (io.jenkins.blueocean.commons.ErrorMessage)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 CreateResponse (io.jenkins.blueocean.rest.model.CreateResponse)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1