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);
}
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");
}
Aggregations