Search in sources :

Example 26 with PackageConfigurations

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

the class PackageRepositoryTest method shouldSetConfigAttributesAsAvailable.

@Test
public 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(), is(name));
    assertThat(packageRepository.getId(), is(repoId));
    assertThat(packageRepository.getPluginConfiguration().getId(), is(pluginId));
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is(url.name));
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().getValue(), is(url.value));
    assertThat(packageRepository.getConfiguration().get(1).getConfigurationKey().getName(), is(username.name));
    assertThat(packageRepository.getConfiguration().get(1).getConfigurationValue().getValue(), is(username.value));
    assertThat(packageRepository.getConfiguration().get(2).getConfigurationKey().getName(), is(password.name));
    assertThat(packageRepository.getConfiguration().get(2).getEncryptedValue(), is(new GoCipher().encrypt(password.value)));
    assertThat(packageRepository.getConfiguration().get(2).getConfigurationValue(), is(nullValue()));
    assertThat(packageRepository.getConfiguration().get(3).getConfigurationKey().getName(), is(secureKeyNotChanged.name));
    assertThat(packageRepository.getConfiguration().get(3).getEncryptedValue(), is(oldEncryptedValue));
    assertThat(packageRepository.getConfiguration().get(3).getConfigurationValue(), is(nullValue()));
    assertSame(packageRepository.getPackages(), packages);
}
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.Test)

Example 27 with PackageConfigurations

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

the class PackageRepositoryTest method shouldConvertKeysToLowercaseInGetConfigForDisplay.

@Test
public void shouldConvertKeysToLowercaseInGetConfigForDisplay() throws Exception {
    RepositoryMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
    PackageMetadataStore.getInstance().addMetadataFor("some-plugin", new PackageConfigurations());
    Configuration configuration = new Configuration(create("kEY1", false, "vALue1"), create("KEY_MORE_2", false, "VALUE_2"), create("key_3", false, "value3"));
    PackageRepository repository = PackageRepositoryMother.create("repo1", "repo1-name", "some-plugin", "1", configuration);
    assertThat(repository.getConfigForDisplay(), is("Repository: [key1=vALue1, key_more_2=VALUE_2, key_3=value3]"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 28 with PackageConfigurations

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

the class MagicalGoConfigXmlLoaderTest method shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists.

@Test
public void shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists() throws Exception {
    com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("PKG-KEY1"));
    RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY1"));
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY3").with(REQUIRED, false).with(PART_OF_IDENTITY, false).with(SECURE, true));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(packageConfiguration));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(repositoryConfiguration));
    String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + "    <repository id='repo-id-1' name='name-1'>\n" + "		<pluginConfiguration id='plugin-1' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>REPO-KEY1</key>\n" + "          <value>repo-key1</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY2</key>\n" + "          <value>repo-key2</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY3</key>\n" + "          <value>repo-key3</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id-1' name='name-1'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>PKG-KEY1</key>\n" + "              <value>pkg-key1</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "    <repository id='repo-id-2' name='name-2'>\n" + "		<pluginConfiguration id='plugin-1' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>REPO-KEY1</key>\n" + "          <value>repo-key1</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY2</key>\n" + "          <value>another-repo-key2</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY3</key>\n" + "          <value>another-repo-key3</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id-2' name='name-2'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>PKG-KEY1</key>\n" + "              <value>pkg-key1</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "  </repositories>" + "</cruise>";
    assertFailureDuringLoad(xml, "Cannot save package or repo, found duplicate packages. [Repo Name: 'name-1', Package Name: 'name-1'], [Repo Name: 'name-2', Package Name: 'name-2']", GoConfigInvalidException.class);
}
Also used : PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 29 with PackageConfigurations

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

the class PackageMaterialTest method shouldReturnSomethingMoreSaneForToString.

@Test
public void shouldReturnSomethingMoreSaneForToString() throws Exception {
    PackageMaterial material = MaterialsMother.packageMaterial();
    RepositoryMetadataStore.getInstance().addMetadataFor(material.getPluginId(), new PackageConfigurations());
    PackageMetadataStore.getInstance().addMetadataFor(material.getPluginId(), new PackageConfigurations());
    assertThat(material.toString(), is("'PackageMaterial{Repository: [k1=repo-v1, k2=repo-v2] - Package: [k3=package-v1]}'"));
}
Also used : PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 30 with PackageConfigurations

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations 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 : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) 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) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Aggregations

PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)31 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)23 Test (org.junit.Test)23 Configuration (com.thoughtworks.go.domain.config.Configuration)14 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)13 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)6 GoCipher (com.thoughtworks.go.security.GoCipher)6 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)3 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)3 PackageMetadataStore (com.thoughtworks.go.plugin.access.packagematerial.PackageMetadataStore)3 RepositoryMetadataStore (com.thoughtworks.go.plugin.access.packagematerial.RepositoryMetadataStore)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 ConfigurationHolder (com.thoughtworks.go.config.helper.ConfigurationHolder)2 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)2 SecureKeyInfoProvider (com.thoughtworks.go.domain.config.SecureKeyInfoProvider)2