use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.
the class ArtifactTypeConfigs method setConfigAttributes.
@Override
public void setConfigAttributes(Object attributes) {
clear();
if (attributes == null) {
return;
}
List<Map> attrList = (List<Map>) attributes;
for (Map attrMap : attrList) {
String type = (String) attrMap.get("artifactTypeValue");
if (TestArtifactConfig.TEST_PLAN_DISPLAY_NAME.equals(type) || BuildArtifactConfig.ARTIFACT_PLAN_DISPLAY_NAME.equals(type)) {
String source = (String) attrMap.get(BuiltinArtifactConfig.SRC);
String destination = (String) attrMap.get(BuiltinArtifactConfig.DEST);
if (source.trim().isEmpty() && destination.trim().isEmpty()) {
continue;
}
if (TestArtifactConfig.TEST_PLAN_DISPLAY_NAME.equals(type)) {
this.add(new TestArtifactConfig(source, destination));
} else {
this.add(new BuildArtifactConfig(source, destination));
}
} else {
String artifactId = (String) attrMap.get(PluggableArtifactConfig.ID);
String storeId = (String) attrMap.get(PluggableArtifactConfig.STORE_ID);
String pluginId = (String) attrMap.get("pluginId");
Map<String, Object> userSpecifiedConfiguration = (Map<String, Object>) attrMap.get("configuration");
PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig(artifactId, storeId);
this.add(pluggableArtifactConfig);
if (userSpecifiedConfiguration == null) {
return;
}
if (StringUtils.isBlank(pluginId)) {
Configuration configuration = pluggableArtifactConfig.getConfiguration();
for (String key : userSpecifiedConfiguration.keySet()) {
Map<String, String> configurationMetadata = (Map<String, String>) userSpecifiedConfiguration.get(key);
if (configurationMetadata != null) {
boolean isSecure = Boolean.parseBoolean(configurationMetadata.get("isSecure"));
if (configuration.getProperty(key) == null) {
configuration.addNewConfiguration(key, isSecure);
}
if (isSecure) {
configuration.getProperty(key).setEncryptedValue(new EncryptedConfigurationValue(configurationMetadata.get("value")));
} else {
configuration.getProperty(key).setConfigurationValue(new ConfigurationValue(configurationMetadata.get("value")));
}
}
}
} else {
for (Map.Entry<String, Object> configuration : userSpecifiedConfiguration.entrySet()) {
pluggableArtifactConfig.getConfiguration().addNewConfigurationWithValue(configuration.getKey(), String.valueOf(configuration.getValue()), false);
}
}
}
}
}
use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.
the class PluggableTaskTest method testConfigAsMap.
@Test
public void testConfigAsMap() 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)), null, new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
PluggableTask task = new PluggableTask(pluginConfiguration, configuration);
Map<String, Map<String, String>> configMap = task.configAsMap();
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(PluggableTask.VALUE_KEY), is(values.get(i)));
}
}
use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.
the class FetchPluggableArtifactTask method setFetchTaskAttributes.
@Override
protected void setFetchTaskAttributes(Map attributeMap) {
this.artifactId = (String) attributeMap.get(ARTIFACT_ID);
if (StringUtils.isBlank(this.artifactId)) {
return;
}
final Map<String, Object> userSpecifiedConfiguration = (Map<String, Object>) attributeMap.get(CONFIGURATION);
if (userSpecifiedConfiguration == null) {
return;
}
final String pluginId = (String) attributeMap.get("pluginId");
if (StringUtils.isBlank(pluginId)) {
for (String key : userSpecifiedConfiguration.keySet()) {
Map<String, String> configurationMetadata = (Map<String, String>) userSpecifiedConfiguration.get(key);
if (configurationMetadata != null) {
boolean isSecure = Boolean.parseBoolean(configurationMetadata.get("isSecure"));
if (configuration.getProperty(key) == null) {
configuration.addNewConfiguration(key, isSecure);
}
if (isSecure) {
configuration.getProperty(key).setEncryptedValue(new EncryptedConfigurationValue(configurationMetadata.get("value")));
} else {
configuration.getProperty(key).setConfigurationValue(new ConfigurationValue(configurationMetadata.get("value")));
}
}
}
} else {
for (Map.Entry<String, Object> configuration : userSpecifiedConfiguration.entrySet()) {
this.configuration.addNewConfigurationWithValue(configuration.getKey(), String.valueOf(configuration.getValue()), false);
}
}
}
use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.
the class ElasticProfileTest method addConfigurations_shouldAddConfigurationsWithEncryptedValue.
@Test
public void addConfigurations_shouldAddConfigurationsWithEncryptedValue() throws Exception {
ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new EncryptedConfigurationValue("some_name"));
ElasticProfile profile = new ElasticProfile("id", "prod-cluster");
profile.addConfigurations(Arrays.asList(property));
assertThat(profile.size(), is(1));
assertThat(profile, contains(new ConfigurationProperty(new ConfigurationKey("username"), new EncryptedConfigurationValue("some_name"))));
}
use of com.thoughtworks.go.domain.config.EncryptedConfigurationValue in project gocd by gocd.
the class FetchPluggableArtifactTaskTest method shouldSetConfiguration_whenPluginIsNotProvided.
@Test
void shouldSetConfiguration_whenPluginIsNotProvided() throws CryptoException {
final HashMap<Object, Object> configAttrs = new HashMap<>();
configAttrs.put(FetchPluggableArtifactTask.ARTIFACT_ID, "installers");
configAttrs.put(FetchPluggableArtifactTask.CONFIGURATION, Collections.singletonMap("NAME", new HashMap<String, String>() {
{
put("value", new GoCipher().encrypt("gocd.zip"));
put("isSecure", "true");
}
}));
FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}");
task.setFetchTaskAttributes(configAttrs);
Assertions.assertThat(task.getArtifactId()).isEqualTo("installers");
Assertions.assertThat(task.getConfiguration()).hasSize(1).contains(new ConfigurationProperty(new ConfigurationKey("NAME"), new EncryptedConfigurationValue(new GoCipher().encrypt("gocd.zip"))));
}
Aggregations