use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageDefinitionService method performPluginValidationsFor.
public void performPluginValidationsFor(final PackageDefinition packageDefinition) {
String pluginId = packageDefinition.getRepository().getPluginConfiguration().getId();
ValidationResult validationResult = packageRepositoryExtension.isPackageConfigurationValid(pluginId, buildPackageConfigurations(packageDefinition), buildRepositoryConfigurations(packageDefinition.getRepository()));
for (ValidationError error : validationResult.getErrors()) {
packageDefinition.addConfigurationErrorFor(error.getKey(), error.getMessage());
}
for (ConfigurationProperty configurationProperty : packageDefinition.getConfiguration()) {
String key = configurationProperty.getConfigurationKey().getName();
if (PackageMetadataStore.getInstance().hasOption(packageDefinition.getRepository().getPluginConfiguration().getId(), key, PackageConfiguration.REQUIRED)) {
if (configurationProperty.getValue().isEmpty() && configurationProperty.doesNotHaveErrorsAgainstConfigurationValue()) {
configurationProperty.addErrorAgainstConfigurationValue(localizer.localize("MANDATORY_CONFIGURATION_FIELD_WITH_NAME", configurationProperty.getConfigurationKey().getName()));
}
}
}
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageRepositoryService method performPluginValidationsFor.
void performPluginValidationsFor(final PackageRepository packageRepository) {
if (!validatePluginId(packageRepository)) {
return;
}
for (ConfigurationProperty configurationProperty : packageRepository.getConfiguration()) {
String key = configurationProperty.getConfigurationKey().getName();
String pluginId = packageRepository.getPluginConfiguration().getId();
if (repositoryMetadataStore.hasOption(pluginId, key, PackageConfiguration.REQUIRED)) {
if (configurationProperty.getValue().isEmpty()) {
configurationProperty.addErrorAgainstConfigurationValue(localizer.localize("MANDATORY_CONFIGURATION_FIELD"));
}
}
}
ValidationResult validationResult = packageRepositoryExtension.isRepositoryConfigurationValid(packageRepository.getPluginConfiguration().getId(), populateConfiguration(packageRepository.getConfiguration()));
for (ValidationError error : validationResult.getErrors()) {
packageRepository.addConfigurationErrorFor(error.getKey(), error.getMessage());
}
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PluggableScmService method validate.
public void validate(final SCM scmConfig) {
final String pluginId = scmConfig.getPluginConfiguration().getId();
final SCMPropertyConfiguration configuration = getScmPropertyConfiguration(scmConfig);
ValidationResult validationResult = scmExtension.isSCMConfigurationValid(pluginId, configuration);
if (SCMMetadataStore.getInstance().hasPreferenceFor(pluginId)) {
SCMConfigurations configurationMetadata = SCMMetadataStore.getInstance().getConfigurationMetadata(pluginId);
for (SCMConfiguration scmConfiguration : configurationMetadata.list()) {
String key = scmConfiguration.getKey();
boolean isRequired = SCMMetadataStore.getInstance().hasOption(pluginId, key, Property.REQUIRED);
ConfigurationProperty property = scmConfig.getConfiguration().getProperty(key);
String configValue = property == null ? null : property.getValue();
if (isRequired && StringUtils.isBlank(configValue)) {
validationResult.addError(new ValidationError(key, localizer.localize("MANDATORY_CONFIGURATION_FIELD")));
}
}
}
for (ValidationError validationError : validationResult.getErrors()) {
ConfigurationProperty property = scmConfig.getConfiguration().getProperty(validationError.getKey());
if (property != null) {
property.addError(validationError.getKey(), validationError.getMessage());
}
}
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty 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.domain.config.ConfigurationProperty 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();
}
Aggregations