Search in sources :

Example 6 with EncryptedConfigurationValue

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

the class ConfigurationPropertyBuilder method create.

public ConfigurationProperty create(String key, String value, String encryptedValue, Boolean isSecure) {
    ConfigurationProperty configurationProperty = new ConfigurationProperty();
    configurationProperty.setConfigurationKey(new ConfigurationKey(key));
    if (isNotBlank(value) && isNotBlank(encryptedValue)) {
        configurationProperty.addError("configurationValue", "You may only specify `value` or `encrypted_value`, not both!");
        configurationProperty.addError("encryptedValue", "You may only specify `value` or `encrypted_value`, not both!");
        configurationProperty.setConfigurationValue(new ConfigurationValue(value));
        configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encryptedValue));
        return configurationProperty;
    }
    if (isSecure) {
        if (isNotBlank(encryptedValue)) {
            configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encryptedValue));
        }
        if (isNotBlank(value)) {
            configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encrypt(value)));
        }
    } else {
        if (isNotBlank(encryptedValue)) {
            configurationProperty.addError("encryptedValue", "encrypted_value cannot be specified to a unsecured property.");
            configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encryptedValue));
        }
        if (isNotBlank(value)) {
            configurationProperty.setConfigurationValue(new ConfigurationValue(value));
        }
    }
    return configurationProperty;
}
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)

Example 7 with EncryptedConfigurationValue

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

the class SCMTest method shouldGetConfigAsMap.

@Test
public void shouldGetConfigAsMap() throws Exception {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
    GoCipher cipher = new GoCipher();
    List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
    List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), new ConfigurationValue(values.get(3)), new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
    SCM scm = new SCM("scm-id", pluginConfiguration, configuration);
    Map<String, Map<String, String>> configMap = scm.getConfigAsMap();
    assertThat(configMap.keySet().size(), is(keys.size()));
    assertThat(configMap.values().size(), is(values.size()));
    assertThat(configMap.keySet().containsAll(keys), is(true));
    for (int i = 0; i < keys.size(); i++) {
        assertThat(configMap.get(keys.get(i)).get(SCM.VALUE_KEY), is(values.get(i)));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) 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) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Test(org.junit.Test)

Example 8 with EncryptedConfigurationValue

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

the class SCMTest method shouldClearConfigurationsWhichAreEmptyAndNoErrors.

@Test
public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception {
    SCM scm = new SCM();
    scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue()));
    scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue()));
    scm.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");
    scm.getConfiguration().add(configurationProperty);
    scm.clearEmptyConfigurations();
    assertThat(scm.getConfiguration().size(), is(1));
    assertThat(scm.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)

Aggregations

ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)8 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)8 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)8 Test (org.junit.Test)7 Configuration (com.thoughtworks.go.domain.config.Configuration)4 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)2 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)1 Map (java.util.Map)1