Search in sources :

Example 1 with ConfigurationHolder

use of com.thoughtworks.go.config.helper.ConfigurationHolder in project gocd by gocd.

the class PackageRepositoryTest method shouldCreatePackageBasedOnParams.

@Test
void shouldCreatePackageBasedOnParams() throws Exception {
    PackageRepository packageRepository = PackageRepositoryMother.create("repo-id1", "packageRepository", "plugin-id", "1.0", null);
    Map packageDefAttr = createPackageDefinitionConfiguration("package_name", "pluginId", new ConfigurationHolder("key1", "value1"), new ConfigurationHolder("key2", "value2"));
    Map map = new HashMap();
    map.put("package_definition", packageDefAttr);
    PackageDefinition actualPackageDefinition = packageRepository.findOrCreatePackageDefinition(map);
    assertThat(actualPackageDefinition).isEqualTo(PackageDefinitionMother.create(null, "package_name", new Configuration(create("key1", false, "value1"), create("key2", false, "value2")), packageRepository));
    assertThat(actualPackageDefinition.getRepository()).isEqualTo(packageRepository);
}
Also used : PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) HashMap(java.util.HashMap) ConfigurationHolder(com.thoughtworks.go.config.helper.ConfigurationHolder) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigurationHolder

use of com.thoughtworks.go.config.helper.ConfigurationHolder in project gocd by gocd.

the class PackageDefinitionTest method shouldSetConfigAttributes.

@Test
void shouldSetConfigAttributes() throws Exception {
    PackageDefinition definition = new PackageDefinition();
    String pluginId = "plugin";
    Map config = createPackageDefinitionConfiguration("package-name", pluginId, new ConfigurationHolder("key1", "value1"), new ConfigurationHolder("key2", "value2", "encrypted-value", true, "1"), new ConfigurationHolder("key3", "test", "encrypted-value", true, "0"));
    PackageConfigurations metadata = new PackageConfigurations();
    metadata.addConfiguration(new PackageConfiguration("key1"));
    metadata.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
    metadata.addConfiguration(new PackageConfiguration("key3").with(PackageConfiguration.SECURE, true));
    PackageMetadataStore.getInstance().addMetadataFor(pluginId, metadata);
    definition.setRepository(PackageRepositoryMother.create("1"));
    definition.setConfigAttributes(config);
    String encryptedValue = new GoCipher().encrypt("value2");
    assertThat(definition.getName()).isEqualTo("package-name");
    assertThat(definition.getConfiguration().size()).isEqualTo(3);
    assertThat(definition.getConfiguration().getProperty("key1").getConfigurationValue().getValue()).isEqualTo("value1");
    assertThat(definition.getConfiguration().getProperty("key1").getEncryptedConfigurationValue()).isNull();
    assertThat(definition.getConfiguration().getProperty("key2").getEncryptedValue()).isEqualTo(encryptedValue);
    assertThat(definition.getConfiguration().getProperty("key2").getConfigurationValue()).isNull();
    assertThat(definition.getConfiguration().getProperty("key3").getEncryptedValue()).isEqualTo("encrypted-value");
    assertThat(definition.getConfiguration().getProperty("key3").getConfigurationValue()).isNull();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationHolder(com.thoughtworks.go.config.helper.ConfigurationHolder) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationHolder

use of com.thoughtworks.go.config.helper.ConfigurationHolder in project gocd by gocd.

the class PackageRepositoryTest method shouldSetConfigAttributesAsAvailable.

@Test
void shouldSetConfigAttributesAsAvailable() throws Exception {
    // metadata setup
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.add(new PackageConfiguration("url"));
    repositoryConfiguration.add(new PackageConfiguration("username"));
    repositoryConfiguration.add(new PackageConfiguration("password").with(SECURE, true));
    repositoryConfiguration.add(new PackageConfiguration("secureKeyNotChanged").with(SECURE, true));
    RepositoryMetadataStore.getInstance().addMetadataFor("yum", repositoryConfiguration);
    String name = "go-server";
    String repoId = "repo-id";
    String pluginId = "yum";
    ConfigurationHolder url = new ConfigurationHolder("url", "http://test.com");
    ConfigurationHolder username = new ConfigurationHolder("username", "user");
    String oldEncryptedValue = "oldEncryptedValue";
    ConfigurationHolder password = new ConfigurationHolder("password", "pass", oldEncryptedValue, true, "1");
    ConfigurationHolder secureKeyNotChanged = new ConfigurationHolder("secureKeyNotChanged", "pass", oldEncryptedValue, true, "0");
    Map attributes = createPackageRepositoryConfiguration(name, pluginId, repoId, url, username, password, secureKeyNotChanged);
    PackageRepository packageRepository = new PackageRepository();
    Packages packages = new Packages();
    packageRepository.setPackages(packages);
    packageRepository.setConfigAttributes(attributes);
    assertThat(packageRepository.getName()).isEqualTo(name);
    assertThat(packageRepository.getId()).isEqualTo(repoId);
    assertThat(packageRepository.getPluginConfiguration().getId()).isEqualTo(pluginId);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName()).isEqualTo(url.name);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().getValue()).isEqualTo(url.value);
    assertThat(packageRepository.getConfiguration().get(1).getConfigurationKey().getName()).isEqualTo(username.name);
    assertThat(packageRepository.getConfiguration().get(1).getConfigurationValue().getValue()).isEqualTo(username.value);
    assertThat(packageRepository.getConfiguration().get(2).getConfigurationKey().getName()).isEqualTo(password.name);
    assertThat(packageRepository.getConfiguration().get(2).getEncryptedValue()).isEqualTo(new GoCipher().encrypt(password.value));
    assertThat(packageRepository.getConfiguration().get(2).getConfigurationValue()).isNull();
    assertThat(packageRepository.getConfiguration().get(3).getConfigurationKey().getName()).isEqualTo(secureKeyNotChanged.name);
    assertThat(packageRepository.getConfiguration().get(3).getEncryptedValue()).isEqualTo(oldEncryptedValue);
    assertThat(packageRepository.getConfiguration().get(3).getConfigurationValue()).isNull();
    assertThat(packages).isSameAs(packageRepository.getPackages());
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationHolder(com.thoughtworks.go.config.helper.ConfigurationHolder) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigurationHolder

use of com.thoughtworks.go.config.helper.ConfigurationHolder in project gocd by gocd.

the class PackageMaterialTestBase method createPackageConfigurationsFor.

protected void createPackageConfigurationsFor(Map attributes, ConfigurationHolder[] configurations) {
    Map configurationMap = new LinkedHashMap();
    for (int i = 0; i < configurations.length; i++) {
        ConfigurationHolder currentConfiguration = configurations[i];
        HashMap config = new HashMap();
        HashMap firstConfigKey = new HashMap();
        firstConfigKey.put(ConfigurationKey.NAME, currentConfiguration.name);
        config.put(ConfigurationProperty.CONFIGURATION_KEY, firstConfigKey);
        HashMap firstConfigValue = new HashMap();
        firstConfigValue.put(ConfigurationValue.VALUE, currentConfiguration.value);
        config.put(ConfigurationProperty.CONFIGURATION_VALUE, firstConfigValue);
        if (currentConfiguration.isChanged()) {
            config.put(ConfigurationProperty.IS_CHANGED, "1");
        }
        if (currentConfiguration.isSecure) {
            HashMap encryptedValue = new HashMap();
            encryptedValue.put(EncryptedConfigurationValue.VALUE, currentConfiguration.encryptedValue);
            config.put(ConfigurationProperty.ENCRYPTED_VALUE, encryptedValue);
        }
        configurationMap.put(String.valueOf(i), config);
    }
    attributes.put(Configuration.CONFIGURATION, configurationMap);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConfigurationHolder(com.thoughtworks.go.config.helper.ConfigurationHolder) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ConfigurationHolder (com.thoughtworks.go.config.helper.ConfigurationHolder)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)3 Test (org.junit.jupiter.api.Test)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)2 GoCipher (com.thoughtworks.go.security.GoCipher)2 LinkedHashMap (java.util.LinkedHashMap)1