use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class RoleConfigurationValidator method validate.
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 (PluginNotFoundException e) {
role.addError("pluginRole", String.format("Unable to validate `pluginRole` configuration, missing plugin: %s", pluginId));
}
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableTaskService method validate.
public boolean validate(final PluggableTask modifiedTask) {
final TaskConfig configuration = new TaskConfig();
for (ConfigurationProperty configurationProperty : modifiedTask.getConfiguration()) {
configuration.add(new TaskConfigProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue()));
}
final String pluginId = modifiedTask.getPluginConfiguration().getId();
ValidationResult validationResult = taskExtension.validate(pluginId, configuration);
final TaskPreference preference = PluggableTaskConfigStore.store().preferenceFor(pluginId);
if (PluggableTaskConfigStore.store().hasPreferenceFor(pluginId)) {
for (ConfigurationProperty configurationProperty : modifiedTask.getConfiguration()) {
String key = configurationProperty.getConfigurationKey().getName();
final Property property = preference.getConfig().get(key);
if (property != null) {
final Boolean required = property.getOption(Property.REQUIRED);
if (required && StringUtils.isBlank(configurationProperty.getConfigValue()))
validationResult.addError(new ValidationError(property.getKey(), localizer.localize("MANDATORY_CONFIGURATION_FIELD")));
}
}
}
for (ValidationError validationError : validationResult.getErrors()) {
modifiedTask.getConfiguration().getProperty(validationError.getKey()).addError(validationError.getKey(), validationError.getMessage());
}
return validationResult.isSuccessful();
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class RoleConfigCommandTest method shouldPassValidationForValidRole.
@Test
public void shouldPassValidationForValidRole() {
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 ElasticAgentProfileCreateCommandTest method shouldInvokePluginValidationsBeforeSave.
@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key", "error"));
when(extension.validate(eq("aws"), Matchers.<Map<String, String>>any())).thenReturn(validationResult);
ElasticProfile newProfile = new ElasticProfile("foo", "aws", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
PluginProfileCommand command = new ElasticAgentProfileCreateCommand(mock(GoConfigService.class), newProfile, extension, null, new HttpLocalizedOperationResult());
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
thrown.expect(PluginProfileNotFoundException.class);
thrown.expectMessage("Elastic agent profile `foo` does not exist.");
command.isValid(cruiseConfig);
command.update(cruiseConfig);
assertThat(newProfile.first().errors().size(), is(1));
assertThat(newProfile.first().errors().asString(), is("error"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginProfilesService method validatePluginProperties.
private void validatePluginProperties(PluginProfileCommand command, PluginProfile newPluginProfile) {
try {
ValidationResult result = command.validateUsingExtension(newPluginProfile.getPluginId(), newPluginProfile.getConfigurationAsMap(true));
addErrorsToConfiguration(result, newPluginProfile);
} catch (PluginNotFoundException e) {
newPluginProfile.addError("pluginId", String.format("Plugin with id `%s` is not found.", newPluginProfile.getPluginId()));
} catch (Exception e) {
// Ignore - it will be the invalid cipher text exception for an encrypted value. This will be validated later during entity update
}
}
Aggregations