Search in sources :

Example 1 with EncryptedConfigurationValue

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);
                }
            }
        }
    }
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with EncryptedConfigurationValue

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)));
    }
}
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) 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) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with EncryptedConfigurationValue

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);
        }
    }
}
Also used : EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) Map(java.util.Map)

Example 4 with EncryptedConfigurationValue

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"))));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.jupiter.api.Test)

Example 5 with EncryptedConfigurationValue

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"))));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)17 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)15 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)11 Test (org.junit.jupiter.api.Test)11 GoCipher (com.thoughtworks.go.security.GoCipher)7 ArrayList (java.util.ArrayList)5 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)4 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 ConfigRepoPluginInfo (com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo)4 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)3 Map (java.util.Map)3 Test (org.junit.Test)3 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)2 PluginInfo (com.thoughtworks.go.plugin.domain.common.PluginInfo)2 Capabilities (com.thoughtworks.go.plugin.domain.configrepo.Capabilities)2 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)1 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)1