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 && StringUtil.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.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 && StringUtil.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 PackageRepositoriesTest method shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound.
@Test
public void shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound() {
com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
packageConfiguration.add(new PackageMaterialProperty("k1"));
packageConfiguration.add(new PackageMaterialProperty("k2").with(PART_OF_IDENTITY, false));
PackageMetadataStore.getInstance().addMetadataFor("plugin", new PackageConfigurations(packageConfiguration));
String expectedErrorMessage = "Cannot save package or repo, found duplicate packages. [Repo Name: 'repo-repo1', Package Name: 'pkg1'], [Repo Name: 'repo-repo1', Package Name: 'pkg3'], [Repo Name: 'repo-repo1', Package Name: 'pkg5']";
PackageRepository repository = PackageRepositoryMother.create("repo1");
PackageDefinition definition1 = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
PackageDefinition definition2 = PackageDefinitionMother.create("2", "pkg2", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v2"))), repository);
PackageDefinition definition3 = PackageDefinitionMother.create("3", "pkg3", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
PackageDefinition definition4 = PackageDefinitionMother.create("4", "pkg4", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("V1"))), repository);
PackageDefinition definition5 = PackageDefinitionMother.create("5", "pkg5", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("v2"))), repository);
repository.setPackages(new Packages(definition1, definition2, definition3, definition4, definition5));
PackageRepositories packageRepositories = new PackageRepositories(repository);
packageRepositories.validate(null);
assertThat(definition1.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition3.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition3.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
assertThat(definition5.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
assertThat(definition5.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
assertThat(definition2.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
assertThat(definition2.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
assertThat(definition4.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
assertThat(definition4.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class XmlPartialConfigProvider method getFiles.
public File[] getFiles(File configRepoCheckoutDirectory, PartialConfigLoadContext context) {
String pattern = defaultPattern;
Configuration configuration = context.configuration();
if (configuration != null) {
ConfigurationProperty explicitPattern = configuration.getProperty("pattern");
if (explicitPattern != null) {
pattern = explicitPattern.getValue();
}
}
return getFiles(configRepoCheckoutDirectory, pattern);
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class SCMTest method shouldNotUpdateSecurePropertyWhenPluginIsMissing.
@Test
public void shouldNotUpdateSecurePropertyWhenPluginIsMissing() {
GoCipher goCipher = new GoCipher();
ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), null, new EncryptedConfigurationValue("value"), goCipher);
ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value1"), null, goCipher);
SCM scm = SCMMother.create("scm-id", "scm-name", "plugin-id", "version", new Configuration(secureProperty, nonSecureProperty));
scm.applyPluginMetadata();
assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
assertThat(secureProperty.getConfigurationValue(), is(nullValue()));
assertThat(nonSecureProperty.getConfigurationValue(), is(notNullValue()));
assertThat(nonSecureProperty.getEncryptedConfigurationValue(), is(nullValue()));
}
Aggregations