Search in sources :

Example 16 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 17 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 18 with ConfigurationValue

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

the class PackageRepositoryTest method shouldMakeConfigurationSecureBasedOnMetadata.

@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
    GoCipher goCipher = new GoCipher();
    /*secure property is set based on metadata*/
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
    //meta data of package
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    /*secure property is set based on metadata*/
    ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
    //meta data of repo
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", repositoryConfiguration);
    packageRepository.applyPackagePluginMetadata();
    //assert package properties
    assertThat(secureProperty.isSecure(), is(true));
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
    //assert repository properties
    assertThat(secureRepoProperty.isSecure(), is(true));
    assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureRepoProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureRepoProperty.isSecure(), is(false));
    assertThat(nonSecureRepoProperty.getValue(), is("value2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) 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) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 19 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 20 with ConfigurationValue

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

the class SCM method setPluginConfigurationAttributes.

protected void setPluginConfigurationAttributes(Map attributes) {
    SCMConfigurations scmConfigurations = SCMMetadataStore.getInstance().getConfigurationMetadata(pluginConfiguration.getId());
    if (scmConfigurations == null) {
        throw new RuntimeException("metadata unavailable for plugin: " + pluginConfiguration.getId());
    }
    for (SCMConfiguration scmConfiguration : scmConfigurations.list()) {
        String key = scmConfiguration.getKey();
        if (attributes.containsKey(key)) {
            if (configuration.getProperty(key) == null) {
                configuration.addNewConfiguration(scmConfiguration.getKey(), scmConfiguration.getOption(Property.SECURE));
            }
            configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key)));
            configuration.getProperty(key).handleSecureValueConfiguration(scmConfiguration.getOption(Property.SECURE));
        }
    }
}
Also used : ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations)

Aggregations

ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)34 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)28 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)27 Test (org.junit.Test)27 Configuration (com.thoughtworks.go.domain.config.Configuration)20 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)14 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)9 GoCipher (com.thoughtworks.go.security.GoCipher)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)5 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)4 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SCM (com.thoughtworks.go.domain.scm.SCM)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)3 HashMap (java.util.HashMap)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2