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));
}
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;
}
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));
}
Aggregations