Search in sources :

Example 1 with POST

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

the class BluePipelineContainer method create.

/**
     * Create new pipeline.
     *
     * @param body {@link BluePipelineCreateRequest} request object
     * @return {@link CreateResponse} response
     */
@POST
@WebMethod(name = "")
public CreateResponse create(@JsonBody JSONObject body, StaplerRequest staplerRequest) throws IOException {
    ErrorMessage err = new ErrorMessage(400, "Failed to create Git pipeline");
    if (body.get("name") == null) {
        err.add(new ErrorMessage.Error("name", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "name is required"));
    }
    if (body.get("$class") == null) {
        err.add(new ErrorMessage.Error("$class", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "$class is required"));
    }
    if (!err.getErrors().isEmpty()) {
        throw new ServiceException.BadRequestExpception(err);
    }
    BluePipelineCreateRequest request = staplerRequest.bindJSON(BluePipelineCreateRequest.class, body);
    return create(request);
}
Also used : ErrorMessage(io.jenkins.blueocean.commons.ErrorMessage) WebMethod(org.kohsuke.stapler.WebMethod) POST(org.kohsuke.stapler.verb.POST)

Example 2 with POST

use of org.kohsuke.stapler.verb.POST 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, ImmutableList.<DomainSpecification>of(new BlueOceanDomainSpecification()));
    CredentialsStoreAction.DomainWrapper domainWrapper = credentialStoreAction.getDomain(domainName);
    if (domainWrapper != null) {
        return new CreateResponse(new CredentialApi.Credential(domainWrapper.getCredential(credentials.getId()), 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) JSONObject(net.sf.json.JSONObject) IdCredentials(com.cloudbees.plugins.credentials.common.IdCredentials) CredentialsStoreAction(com.cloudbees.plugins.credentials.CredentialsStoreAction) CreateResponse(io.jenkins.blueocean.rest.model.CreateResponse) WebMethod(org.kohsuke.stapler.WebMethod) POST(org.kohsuke.stapler.verb.POST)

Aggregations

WebMethod (org.kohsuke.stapler.WebMethod)2 POST (org.kohsuke.stapler.verb.POST)2 CredentialsStoreAction (com.cloudbees.plugins.credentials.CredentialsStoreAction)1 IdCredentials (com.cloudbees.plugins.credentials.common.IdCredentials)1 User (hudson.model.User)1 ErrorMessage (io.jenkins.blueocean.commons.ErrorMessage)1 CreateResponse (io.jenkins.blueocean.rest.model.CreateResponse)1 JSONObject (net.sf.json.JSONObject)1