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());
}
}
}
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"));
}
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);
}
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() + "'.");
}
}
}
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();
}
Aggregations