Search in sources :

Example 1 with ValidationException

use of com.netflix.spinnaker.front50.exception.ValidationException in project front50 by spinnaker.

the class PluginInfoService method validate.

private void validate(PluginInfo pluginInfo) {
    Errors errors = new GenericValidationErrors(pluginInfo);
    validators.forEach(v -> v.validate(pluginInfo, errors));
    if (errors.hasErrors()) {
        throw new ValidationException(errors);
    }
}
Also used : Errors(org.springframework.validation.Errors) GenericValidationErrors(com.netflix.spinnaker.front50.validator.GenericValidationErrors) GenericValidationErrors(com.netflix.spinnaker.front50.validator.GenericValidationErrors)

Example 2 with ValidationException

use of com.netflix.spinnaker.front50.exception.ValidationException in project front50 by spinnaker.

the class PipelineController method validatePipeline.

/**
 * Ensure basic validity of the pipeline. Invalid pipelines will raise runtime exceptions.
 *
 * @param pipeline The Pipeline to validate
 */
private void validatePipeline(final Pipeline pipeline, Boolean staleCheck) {
    // Pipelines must have an application and a name
    if (StringUtils.isAnyBlank(pipeline.getApplication(), pipeline.getName())) {
        throw new InvalidEntityException("A pipeline requires name and application fields");
    }
    // Check if pipeline type is templated
    if (TYPE_TEMPLATED.equals(pipeline.getType())) {
        PipelineTemplateDAO templateDAO = getTemplateDAO();
        // Check templated pipelines to ensure template is valid
        String source;
        switch(pipeline.getSchema()) {
            case "v2":
                V2TemplateConfiguration v2Config = objectMapper.convertValue(pipeline, V2TemplateConfiguration.class);
                source = v2Config.getTemplate().getReference();
                break;
            default:
                TemplateConfiguration v1Config = objectMapper.convertValue(pipeline.getConfig(), TemplateConfiguration.class);
                source = v1Config.getPipeline().getTemplate().getSource();
                break;
        }
        // Check if template id which is after :// is in the store
        if (source.startsWith(SPINNAKER_PREFIX)) {
            String templateId = source.substring(SPINNAKER_PREFIX.length());
            try {
                templateDAO.findById(templateId);
            } catch (NotFoundException notFoundEx) {
                throw new BadRequestException("Configured pipeline template not found", notFoundEx);
            }
        }
    }
    checkForDuplicatePipeline(pipeline.getApplication(), pipeline.getName().trim(), pipeline.getId());
    final ValidatorErrors errors = new ValidatorErrors();
    pipelineValidators.forEach(it -> it.validate(pipeline, errors));
    if (staleCheck && !Strings.isNullOrEmpty(pipeline.getId()) && pipeline.getLastModified() != null) {
        checkForStalePipeline(pipeline, errors);
    }
    if (errors.hasErrors()) {
        String message = errors.getAllErrorsMessage();
        throw new ValidationException(message, errors.getAllErrors());
    }
}
Also used : ValidationException(com.netflix.spinnaker.kork.web.exceptions.ValidationException) PipelineTemplateDAO(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) V2TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration) TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration) ValidatorErrors(com.netflix.spinnaker.front50.api.validator.ValidatorErrors) InvalidEntityException(com.netflix.spinnaker.front50.exceptions.InvalidEntityException) V2TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration)

Example 3 with ValidationException

use of com.netflix.spinnaker.front50.exception.ValidationException in project front50 by spinnaker.

the class ApplicationService method validate.

private void validate(Application application) {
    ApplicationValidationErrors errors = new ApplicationValidationErrors(application);
    validators.forEach(v -> v.validate(application, errors));
    if (errors.hasErrors()) {
        throw new ValidationException(errors);
    }
}
Also used : ValidationException(com.netflix.spinnaker.front50.exception.ValidationException) ApplicationValidationErrors(com.netflix.spinnaker.front50.validator.ApplicationValidationErrors)

Aggregations

ValidatorErrors (com.netflix.spinnaker.front50.api.validator.ValidatorErrors)1 BadRequestException (com.netflix.spinnaker.front50.exception.BadRequestException)1 ValidationException (com.netflix.spinnaker.front50.exception.ValidationException)1 InvalidEntityException (com.netflix.spinnaker.front50.exceptions.InvalidEntityException)1 PipelineTemplateDAO (com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO)1 TemplateConfiguration (com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration)1 V2TemplateConfiguration (com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration)1 ApplicationValidationErrors (com.netflix.spinnaker.front50.validator.ApplicationValidationErrors)1 GenericValidationErrors (com.netflix.spinnaker.front50.validator.GenericValidationErrors)1 NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)1 ValidationException (com.netflix.spinnaker.kork.web.exceptions.ValidationException)1 Errors (org.springframework.validation.Errors)1