Java Code Examples for com.thoughtworks.go.plugin.api.response.validation.ValidationResult#isSuccessful()

The following examples show how to use com.thoughtworks.go.plugin.api.response.validation.ValidationResult#isSuccessful() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginConfig.java    From go-generic-artifactory-poller with Apache License 2.0 6 votes vote down vote up
public ValidationResult isPackageConfigurationValid(PackageConfiguration packageConfig, RepositoryConfiguration repoConfig) {
    GenericArtifactoryPackageConfig genericArtifactoryPackageConfig = new GenericArtifactoryPackageConfig(packageConfig);
    ValidationResult validationResult = genericArtifactoryPackageConfig.validatePackagePath();

    if(!validationResult.isSuccessful()){
        return validationResult;
    }

    validationResult = genericArtifactoryPackageConfig.validatePackageId();

    if(!validationResult.isSuccessful()){
        return validationResult;
    }

    detectInvalidKeys(packageConfig, validationResult, GenericArtifactoryPackageConfig.getValidKeys());

    return validationResult;
}
 
Example 2
Source File: PluginService.java    From gocd with Apache License 2.0 6 votes vote down vote up
void validatePluginSettings(PluginSettings pluginSettings) {
    pluginSettings.validateTree();
    if (pluginSettings.hasErrors()) {
        return;
    }

    final String pluginId = pluginSettings.getPluginId();
    final PluginSettingsConfiguration configuration = pluginSettings.toPluginSettingsConfiguration();

    final GoPluginExtension extension = findExtensionWhichCanHandleSettingsFor(pluginId);
    if (extension == null) {
        throw new IllegalArgumentException(String.format("Plugin '%s' does not exist or does not implement settings validation.", pluginId));
    }

    final ValidationResult result = extension.validatePluginSettings(pluginId, configuration);
    if (!result.isSuccessful()) {
        for (ValidationError error : result.getErrors()) {
            pluginSettings.populateErrorMessageFor(error.getKey(), error.getMessage());
        }
    }
}
 
Example 3
Source File: ElasticAgentProfileConfigurationValidator.java    From gocd with Apache License 2.0 6 votes vote down vote up
public void validate(ElasticProfile elasticAgentProfile, String pluginId) {
    try {
        ValidationResult result = elasticAgentExtension.validate(pluginId, elasticAgentProfile.getConfigurationAsMap(true));

        if (!result.isSuccessful()) {
            for (ValidationError error : result.getErrors()) {
                ConfigurationProperty property = elasticAgentProfile.getProperty(error.getKey());

                if (property == null) {
                    elasticAgentProfile.addNewConfiguration(error.getKey(), false);
                    property = elasticAgentProfile.getProperty(error.getKey());
                }
                property.addError(error.getKey(), error.getMessage());
            }
        }
    } catch (RecordNotFoundException e) {
        elasticAgentProfile.addError("pluginId", String.format("Unable to validate Elastic Agent Profile configuration, missing plugin: %s", pluginId));
    }
}
 
Example 4
Source File: RoleConfigurationValidator.java    From gocd with Apache License 2.0 6 votes vote down vote up
public void validate(PluginRoleConfig role, String pluginId) {
    try {
        ValidationResult result = authorizationExtension.validateRoleConfiguration(pluginId, role.getConfigurationAsMap(true));

        if (!result.isSuccessful()) {
            for (ValidationError error : result.getErrors()) {
                ConfigurationProperty property = role.getProperty(error.getKey());

                if (property == null) {
                    role.addNewConfiguration(error.getKey(), false);
                    property = role.getProperty(error.getKey());
                }
                property.addError(error.getKey(), error.getMessage());
            }
        }
    } catch (RecordNotFoundException e) {
        role.addError("pluginRole", String.format("Unable to validate `pluginRole` configuration, missing plugin: %s", pluginId));
    }
}
 
Example 5
Source File: GenericArtifactoryPoller.java    From go-generic-artifactory-poller with Apache License 2.0 5 votes vote down vote up
private void validateConfig(RepositoryConfiguration repoConfig, PackageConfiguration packageConfig) {
    ValidationResult errors = new PluginConfig().isRepositoryConfigurationValid(repoConfig);

    errors.addErrors(new PluginConfig().isPackageConfigurationValid(packageConfig, repoConfig).getErrors());

    if (!errors.isSuccessful()) {
        StringBuilder stringBuilder = new StringBuilder();
        for (ValidationError validationError : errors.getErrors()) {
            stringBuilder.append(validationError.getMessage()).append("; ");
        }
        String errorString = stringBuilder.toString();
        throw new RuntimeException(errorString.substring(0, errorString.length() - 2));
    }
}
 
Example 6
Source File: PluggableTaskService.java    From gocd with Apache License 2.0 5 votes vote down vote up
public boolean isValid(PluggableTask task) {
    if(!task.isValid()) {
        return false;
    }

    ValidationResult validationResult = taskExtension.validate(task.getPluginConfiguration().getId(), task.toTaskConfig());
    mapErrorsToConfiguration(validationResult, task);

    return validationResult.isSuccessful();
}
 
Example 7
Source File: PackageDefinitionService.java    From gocd with Apache License 2.0 5 votes vote down vote up
public boolean validatePackageConfiguration(final PackageDefinition packageDefinition) {
    String pluginId = packageDefinition.getRepository().getPluginConfiguration().getId();
    if (!packageDefinition.getRepository().doesPluginExist()) {
        throw new RuntimeException(String.format("Plugin with id '%s' is not found.", pluginId));
    }

    ValidationResult validationResult = packageRepositoryExtension.isPackageConfigurationValid(pluginId, buildPackageConfigurations(packageDefinition), buildRepositoryConfigurations(packageDefinition.getRepository()));
    addErrorsToConfiguration(validationResult, packageDefinition);

    return validationResult.isSuccessful();
}
 
Example 8
Source File: PackageRepositoryService.java    From gocd with Apache License 2.0 5 votes vote down vote up
public boolean validateRepositoryConfiguration(final PackageRepository packageRepository) {
    if (!packageRepository.doesPluginExist()) {
        throw new RuntimeException(String.format("Plugin with id '%s' is not found.", packageRepository.getPluginConfiguration().getId()));
    }

    ValidationResult validationResult = packageRepositoryExtension.isRepositoryConfigurationValid(packageRepository.getPluginConfiguration().getId(), populateConfiguration(packageRepository.getConfiguration()));
    addErrorsToConfiguration(validationResult, packageRepository);

    return validationResult.isSuccessful();
}
 
Example 9
Source File: PluggableScmService.java    From gocd with Apache License 2.0 5 votes vote down vote up
public boolean isValid(final SCM scmConfig) {
    if (!scmConfig.doesPluginExist()) {
        throw new RuntimeException(format("Plugin with id '%s' is not found.", scmConfig.getPluginConfiguration().getId()));
    }

    ValidationResult validationResult = scmExtension.isSCMConfigurationValid(scmConfig.getPluginConfiguration().getId(), getScmPropertyConfiguration(scmConfig));
    addErrorsToConfiguration(validationResult, scmConfig);

    return validationResult.isSuccessful();
}
 
Example 10
Source File: RuleAwarePluginProfileService.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void addErrorsToConfiguration(ValidationResult result, RuleAwarePluginProfile newSecurityAuthConfig) {
    if (!result.isSuccessful()) {
        for (com.thoughtworks.go.plugin.api.response.validation.ValidationError validationError : result.getErrors()) {
            ConfigurationProperty property = newSecurityAuthConfig.getConfiguration().getProperty(validationError.getKey());

            if (property != null) {
                property.addError(validationError.getKey(), validationError.getMessage());
            } else {
                newSecurityAuthConfig.addError(validationError.getKey(), validationError.getMessage());
            }
        }
    }
}
 
Example 11
Source File: PluginProfilesService.java    From gocd with Apache License 2.0 5 votes vote down vote up
private void addErrorsToConfiguration(ValidationResult result, PluginProfile newSecurityAuthConfig) {
    if (!result.isSuccessful()) {
        for (com.thoughtworks.go.plugin.api.response.validation.ValidationError validationError : result.getErrors()) {
            ConfigurationProperty property = newSecurityAuthConfig.getProperty(validationError.getKey());

            if (property != null) {
                property.addError(validationError.getKey(), validationError.getMessage());
            } else {
                newSecurityAuthConfig.addError(validationError.getKey(), validationError.getMessage());
            }
        }
    }
}