Search in sources :

Example 46 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PluginService method validatePluginSettingsFor.

public void validatePluginSettingsFor(PluginSettings pluginSettings) {
    String pluginId = pluginSettings.getPluginId();
    PluginSettingsConfiguration configuration = pluginSettings.toPluginSettingsConfiguration();
    GoPluginExtension extension = findExtensionWhichCanHandleSettingsFor(pluginId);
    if (extension == null)
        throw new IllegalArgumentException(String.format("Plugin '%s' does not exist or does not implement settings validation.", pluginId));
    ValidationResult result = extension.validatePluginSettings(pluginId, configuration);
    if (!result.isSuccessful()) {
        for (ValidationError error : result.getErrors()) {
            pluginSettings.populateErrorMessageFor(error.getKey(), error.getMessage());
        }
    }
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 47 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class ElasticAgentExtensionConverterV1Test method shouldHandleValidationResponse.

@Test
public void shouldHandleValidationResponse() {
    String responseBody = "[{\"key\":\"key-one\",\"message\":\"error on key one\"}, {\"key\":\"key-two\",\"message\":\"error on key two\"}]";
    ValidationResult result = new ElasticAgentExtensionConverterV1().getValidationResultResponseFromBody(responseBody);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.getErrors().size(), is(2));
    assertThat(result.getErrors().get(0).getKey(), is("key-one"));
    assertThat(result.getErrors().get(0).getMessage(), is("error on key one"));
    assertThat(result.getErrors().get(1).getKey(), is("key-two"));
    assertThat(result.getErrors().get(1).getMessage(), is("error on key two"));
}
Also used : ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 48 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class RoleConfigCommandTest method shouldPassValidationIfNameIsNotNull.

@Test
public void shouldPassValidationIfNameIsNotNull() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    PluginRoleConfig pluginRoleConfig = new PluginRoleConfig("foo", "ldap");
    cruiseConfig.server().security().addRole(pluginRoleConfig);
    cruiseConfig.server().security().securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    when(extension.validateRoleConfiguration(eq("cd.go.ldap"), Matchers.<Map<String, String>>any())).thenReturn(new ValidationResult());
    RoleConfigCommand command = new StubCommand(goConfigService, pluginRoleConfig, extension, currentUser, result);
    boolean isValid = command.isValid(cruiseConfig);
    assertTrue(isValid);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 49 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class RoleConfigCommand method validate.

private void validate(CruiseConfig preprocessedConfig) {
    if (role instanceof PluginRoleConfig) {
        PluginRoleConfig role = (PluginRoleConfig) this.role;
        PluginRoleConfig preprocessedRole = (PluginRoleConfig) this.preprocessedRole;
        SecurityAuthConfig securityAuthConfig = preprocessedConfig.server().security().securityAuthConfigs().find(role.getAuthConfigId());
        if (securityAuthConfig == null) {
            role.addError("authConfigId", "No such security auth configuration present " + role.getAuthConfigId());
            return;
        }
        try {
            ValidationResult result = extension.validateRoleConfiguration(securityAuthConfig.getPluginId(), role.getConfigurationAsMap(true));
            if (!result.isSuccessful()) {
                for (ValidationError validationError : result.getErrors()) {
                    ConfigurationProperty property = preprocessedRole.getProperty(validationError.getKey());
                    if (property == null) {
                        role.addNewConfiguration(validationError.getKey(), false);
                        preprocessedRole.addNewConfiguration(validationError.getKey(), false);
                        property = preprocessedRole.getProperty(validationError.getKey());
                    }
                    property.addError(validationError.getKey(), validationError.getMessage());
                }
            }
        } catch (PluginNotFoundException e) {
            role.addError("authConfigId", "Could not find a security authorization config with id '" + role.getAuthConfigId() + "'.");
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 50 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageDefinitionService method validatePackageConfiguration.

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();
}
Also used : ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Aggregations

ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)85 Test (org.junit.Test)69 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)43 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)17 Configuration (com.thoughtworks.go.domain.config.Configuration)14 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)11 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)10 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)10 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)9 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)5 Username (com.thoughtworks.go.server.domain.Username)5 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3