Search in sources :

Example 21 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPackages.

@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPackages() throws Exception {
    String encryptedValue = new GoCipher().encrypt("secure-two");
    String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + "    <repository id='repo-id' name='name'>\n" + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>plain</key>\n" + "          <value>value</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>secure-one</key>\n" + "          <value>secure-value</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>secure-two</key>\n" + "          <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id' name='name'>\n" + "          <configuration>\n" + "              <property>\n" + "                <key>plain</key>\n" + "                <value>value</value>\n" + "              </property>\n" + "              <property>\n" + "                <key>secure-one</key>\n" + "                <value>secure-value</value>\n" + "              </property>\n" + "              <property>\n" + "                <key>secure-two</key>\n" + "                <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + "              </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "  </repositories>" + "<pipelines group=\"group_name\">\n" + "  <pipeline name=\"new_name\">\n" + "    <materials>\n" + "      <package ref='package-id' />\n" + "    </materials>\n" + "    <stage name=\"stage_name\">\n" + "      <jobs>\n" + "        <job name=\"job_name\" />\n" + "      </jobs>\n" + "    </stage>\n" + "  </pipeline>\n" + "</pipelines></cruise>";
    //meta data of package
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("plain"));
    packageConfigurations.addConfiguration(new PackageConfiguration("secure-one").with(PackageConfiguration.SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("secure-two").with(PackageConfiguration.SECURE, true));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PackageMaterialConfig packageMaterialConfig = (PackageMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(packageMaterialConfig.getPackageDefinition(), is(packageDefinition));
    Configuration repoConfig = packageMaterialConfig.getPackageDefinition().getRepository().getConfiguration();
    assertThat(repoConfig.get(0).getConfigurationValue().getValue(), is("value"));
    assertThat(repoConfig.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
    assertThat(repoConfig.get(2).getEncryptedValue(), is(encryptedValue));
    Configuration packageConfig = packageMaterialConfig.getPackageDefinition().getConfiguration();
    assertThat(packageConfig.get(0).getConfigurationValue().getValue(), is("value"));
    assertThat(packageConfig.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
    assertThat(packageConfig.get(2).getEncryptedValue(), is(encryptedValue));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Matchers.containsString(org.hamcrest.Matchers.containsString) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 22 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class GoConfigMother method configWithPackageRepo.

public static CruiseConfig configWithPackageRepo(String... ids) throws Exception {
    final CruiseConfig config = new BasicCruiseConfig();
    PackageConfigurations configuration = new PackageConfigurations();
    configuration.addConfiguration(new PackageConfiguration("key1"));
    configuration.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", configuration);
    for (String id : ids) {
        PackageRepository packageRepository = new PackageRepository();
        packageRepository.setId(id);
        packageRepository.setName("name" + id);
        packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-1", "1.0.0"));
        packageRepository.setPackages(new Packages(PackageDefinitionMother.create(id + "-pkg-1", packageRepository), PackageDefinitionMother.create(id + "-pkg-2", packageRepository)));
        GoCipher cipher = new GoCipher();
        ConfigurationProperty p1 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"));
        ConfigurationProperty p2 = new ConfigurationProperty(new ConfigurationKey("key2"), null, new EncryptedConfigurationValue(cipher.encrypt("value2")), cipher);
        packageRepository.setConfiguration(new Configuration(p1, p2));
        config.setPackageRepositories(new PackageRepositories(packageRepository));
    }
    return config;
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)

Example 23 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class PackageConfigurationTest method shouldGetOptionIfAvailable.

@Test
public void shouldGetOptionIfAvailable() {
    PackageConfiguration packageConfiguration = new PackageConfiguration("key");
    packageConfiguration.with(PackageConfiguration.REQUIRED, true);
    assertThat(packageConfiguration.hasOption(PackageConfiguration.REQUIRED), is(true));
    assertThat(packageConfiguration.hasOption(PackageConfiguration.SECURE), is(false));
}
Also used : PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) Test(org.junit.Test)

Aggregations

PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)23 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)19 Test (org.junit.Test)15 Configuration (com.thoughtworks.go.domain.config.Configuration)9 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 GoCipher (com.thoughtworks.go.security.GoCipher)6 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)4 HashMap (java.util.HashMap)3 ConfigurationHolder (com.thoughtworks.go.config.helper.ConfigurationHolder)2 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)2 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)2 SecureKeyInfoProvider (com.thoughtworks.go.domain.config.SecureKeyInfoProvider)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)2 Map (java.util.Map)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Before (org.junit.Before)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1