Search in sources :

Example 46 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PackageRepositoryTest 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("value2"), null, goCipher);
    PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
    ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), null, new EncryptedConfigurationValue("value"), goCipher);
    PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
    packageRepository.applyPackagePluginMetadata();
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getConfigurationValue(), is(nullValue()));
    assertThat(nonSecureProperty.getConfigurationValue(), is(notNullValue()));
    assertThat(nonSecureProperty.getEncryptedConfigurationValue(), is(nullValue()));
    assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureRepoProperty.getConfigurationValue(), is(nullValue()));
    assertThat(nonSecureRepoProperty.getConfigurationValue(), is(notNullValue()));
    assertThat(nonSecureRepoProperty.getEncryptedConfigurationValue(), is(nullValue()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) Test(org.junit.Test)

Example 47 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PackageRepositoryTest method shouldClearConfigurationsWhichAreEmptyAndNoErrors.

@Test
public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception {
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue()));
    packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue()));
    packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null));
    ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null);
    configurationProperty.addErrorAgainstConfigurationValue("error");
    packageRepository.getConfiguration().add(configurationProperty);
    packageRepository.clearEmptyConfigurations();
    assertThat(packageRepository.getConfiguration().size(), is(1));
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.Test)

Example 48 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PackageRepositoryTest method shouldValidateUniqueKeysInConfiguration.

@Test
public void shouldValidateUniqueKeysInConfiguration() {
    ConfigurationProperty one = new ConfigurationProperty(new ConfigurationKey("one"), new ConfigurationValue("value1"));
    ConfigurationProperty duplicate1 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value2"));
    ConfigurationProperty duplicate2 = new ConfigurationProperty(new ConfigurationKey("ONE"), new ConfigurationValue("value3"));
    ConfigurationProperty two = new ConfigurationProperty(new ConfigurationKey("two"), new ConfigurationValue());
    PackageRepository repository = new PackageRepository();
    repository.setConfiguration(new Configuration(one, duplicate1, duplicate2, two));
    repository.setName("yum");
    repository.validate(null);
    assertThat(one.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Repository 'yum'"), is(true));
    assertThat(duplicate1.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Repository 'yum'"), is(true));
    assertThat(duplicate2.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for Repository 'yum'"), is(true));
    assertThat(two.errors().isEmpty(), is(true));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) Test(org.junit.Test)

Example 49 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class PluginSettings method populateSettingsMap.

public PluginSettings populateSettingsMap(PluginSettingsConfiguration configuration) {
    for (Property property : configuration.list()) {
        String settingsKey = property.getKey();
        settingsMap.add(new ConfigurationProperty(new ConfigurationKey(settingsKey), new ConfigurationValue("")));
    }
    return this;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Property(com.thoughtworks.go.plugin.api.config.Property) PluginSettingsProperty(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty)

Example 50 with ConfigurationValue

use of com.thoughtworks.go.domain.config.ConfigurationValue in project gocd by gocd.

the class JobAgentMetadata method elasticProfile.

public ElasticProfile elasticProfile() {
    Gson gson = new Gson();
    Map map = gson.fromJson(metadata, LinkedHashMap.class);
    String pluginId = (String) map.get("pluginId");
    String id = (String) map.get("id");
    Map<String, String> properties = (Map<String, String>) map.get("properties");
    Collection<ConfigurationProperty> configProperties = properties.entrySet().stream().map(new Function<Map.Entry<String, String>, ConfigurationProperty>() {

        @Override
        public ConfigurationProperty apply(Map.Entry<String, String> entry) {
            return new ConfigurationProperty(new ConfigurationKey(entry.getKey()), new ConfigurationValue(entry.getValue()));
        }
    }).collect(Collectors.toList());
    return new ElasticProfile(id, pluginId, configProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Function(java.util.function.Function) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Gson(com.google.gson.Gson) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)56 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)50 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)49 Test (org.junit.Test)47 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)28 Configuration (com.thoughtworks.go.domain.config.Configuration)20 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)14 GoCipher (com.thoughtworks.go.security.GoCipher)10 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)9 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)9 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)7 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)7 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)6 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)5 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 SCM (com.thoughtworks.go.domain.scm.SCM)3