use of io.jenkins.blueocean.commons.ErrorMessage.Error in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequest method validate.
@Override
protected List<Error> validate(String name, BlueScmConfig scmConfig) {
List<Error> errors = new ArrayList<>();
if (scmConfig.getUri() == null) {
errors.add(new ErrorMessage.Error("scmConfig.uri", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "uri is required"));
} else {
StandardCredentials credentials = null;
String credentialId = computeCredentialId(scmConfig);
if (credentialId != null) {
credentials = GitUtils.getCredentials(Jenkins.get(), scmConfig.getUri(), credentialId);
if (credentials == null) {
errors.add(new ErrorMessage.Error("scmConfig.credentialId", ErrorMessage.Error.ErrorCodes.NOT_FOUND.toString(), String.format("credentialId: %s not found", credentialId)));
}
}
// validate credentials if no credential id (perhaps git repo doesn't need auth or credentials is present)
if (credentialId == null || credentials != null) {
errors.addAll(GitUtils.validateCredentials(scmConfig.getUri(), credentials));
}
}
return errors;
}
use of io.jenkins.blueocean.commons.ErrorMessage.Error in project blueocean-plugin by jenkinsci.
the class AbstractMultiBranchCreateRequest method validateInternal.
private void validateInternal(String name, BlueScmConfig scmConfig, BlueOrganization organization) {
checkUserIsAuthenticatedAndHasItemCreatePermission(organization);
// If scmConfig is empty then we are missing the uri and name
if (scmConfig == null) {
throw fail(new Error("scmConfig", ErrorCodes.MISSING.toString(), "scmConfig is required"));
}
if (scmConfig.getUri() == null) {
throw fail(new Error(ERROR_FIELD_SCM_CONFIG_URI, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_URI + " is required"));
}
if (getName() == null) {
throw fail(new Error(ERROR_FIELD_SCM_CONFIG_NAME, ErrorCodes.MISSING.toString(), ERROR_FIELD_SCM_CONFIG_NAME + " is required"));
}
List<Error> errors = new ArrayList<>(new LinkedList(validate(name, scmConfig)));
// Validate that name matches rules
try {
Jenkins.get().getProjectNamingStrategy().checkName(getName());
Jenkins.checkGoodName(name);
} catch (Failure f) {
errors.add(new Error(ERROR_FIELD_SCM_CONFIG_NAME, Error.ErrorCodes.INVALID.toString(), getName() + " in not a valid name"));
}
ModifiableTopLevelItemGroup parent = getParent(organization);
if (parent.getItem(name) != null) {
errors.add(new Error(ERROR_NAME, Error.ErrorCodes.ALREADY_EXISTS.toString(), getName() + " already exists"));
}
if (!errors.isEmpty()) {
throw fail(errors);
}
}
use of io.jenkins.blueocean.commons.ErrorMessage.Error in project blueocean-plugin by jenkinsci.
the class AbstractMultiBranchCreateRequest method assignCredentialToProject.
private void assignCredentialToProject(BlueScmConfig scmConfig, MultiBranchProject project) throws IOException {
User authenticatedUser = User.current();
String credentialId = computeCredentialId(scmConfig);
if (StringUtils.isNotBlank(credentialId)) {
Domain domain = CredentialsUtils.findDomain(credentialId, authenticatedUser);
if (domain == null) {
throw new ServiceException.BadRequestException(new ErrorMessage(400, "Failed to create pipeline").add(new Error(ERROR_FIELD_SCM_CREDENTIAL_ID, Error.ErrorCodes.INVALID.toString(), "No domain in user credentials found for credentialId: " + credentialId)));
}
if (StringUtils.isEmpty(scmConfig.getUri())) {
throw new ServiceException.BadRequestException("uri not specified");
}
if (domain.test(new BlueOceanDomainRequirement())) {
// this is blueocean specific domain
project.addProperty(new BlueOceanCredentialsProvider.FolderPropertyImpl(authenticatedUser.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(scmConfig.getUri())));
}
}
}
Aggregations