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;
}
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)));
}
}
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"));
}
Aggregations