use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class PluggableArtifactConfigTest method addConfigurations_shouldSetUserSpecifiedConfigurationAsIs.
@Test
public void addConfigurations_shouldSetUserSpecifiedConfigurationAsIs() throws CryptoException {
ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true)));
pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true)));
pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false)));
when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "storeId");
ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password")));
configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
cruiseConfig.getArtifactStores().add(new ArtifactStore("storeId", "cd.go.s3"));
pluggableArtifactConfig.addConfigurations(configurationProperties);
assertThat(pluggableArtifactConfig.getConfiguration(), is(configurationProperties));
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class PluggableArtifactConfigTest method shouldHandleEncryptionOfConfigProperties.
@Test
public void shouldHandleEncryptionOfConfigProperties() throws CryptoException {
GoCipher goCipher = new GoCipher();
ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true)));
pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false)));
when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "store-id", secureProperty, nonSecureProperty);
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3"));
pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig);
assertThat(secureProperty.isSecure(), is(true));
assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
assertThat(nonSecureProperty.isSecure(), is(false));
assertThat(nonSecureProperty.getValue(), is("value2"));
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPackages.
@Test
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" + " <tasks>\n" + " <exec command=\"echo\">\n" + " <runif status=\"passed\" />\n" + " </exec>\n" + " </tasks>" + " </job>\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()).isEqualTo(packageDefinition);
Configuration repoConfig = packageMaterialConfig.getPackageDefinition().getRepository().getConfiguration();
assertThat(repoConfig.get(0).getConfigurationValue().getValue()).isEqualTo("value");
assertThat(repoConfig.get(1).getEncryptedValue()).startsWith("AES:");
assertThat(repoConfig.get(2).getEncryptedValue()).startsWith("AES:");
Configuration packageConfig = packageMaterialConfig.getPackageDefinition().getConfiguration();
assertThat(packageConfig.get(0).getConfigurationValue().getValue()).isEqualTo("value");
assertThat(packageConfig.get(1).getEncryptedValue()).startsWith("AES:");
assertThat(packageConfig.get(2).getEncryptedValue()).startsWith("AES:");
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldAllowPluggableTaskConfiguration.
@Test
void shouldAllowPluggableTaskConfiguration() {
String configString = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + " <pipelines>" + "<pipeline name='pipeline1'>" + " <materials>" + " <svn url='svnurl' username='admin' password='%s'/>" + " </materials>" + " <stage name='mingle'>" + " <jobs>" + " <job name='do-something'><tasks>" + " <task>" + " <pluginConfiguration id='plugin-id-1' version='1.0'/>" + " <configuration>" + " <property><key>url</key><value>http://fake-go-server</value></property>" + " <property><key>username</key><value>godev</value></property>" + " <property><key>password</key><value>password</value></property>" + " </configuration>" + " </task> </tasks>" + " </job>" + " </jobs>" + " </stage>" + "</pipeline></pipelines>" + "</cruise>";
CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(configString).configForEdit;
PipelineConfig pipelineConfig = cruiseConfig.getAllPipelineConfigs().get(0);
JobConfig jobConfig = pipelineConfig.getFirstStageConfig().getJobs().get(0);
Tasks tasks = jobConfig.getTasks();
assertThat(tasks.size()).isEqualTo(1);
assertThat(tasks.get(0) instanceof PluggableTask).isTrue();
PluggableTask task = (PluggableTask) tasks.get(0);
assertThat(task.getTaskType()).isEqualTo("pluggable_task_plugin_id_1");
assertThat(task.getTypeForDisplay()).isEqualTo("Pluggable Task");
final Configuration configuration = task.getConfiguration();
assertThat(configuration.listOfConfigKeys().size()).isEqualTo(3);
assertThat(configuration.listOfConfigKeys()).isEqualTo(asList("url", "username", "password"));
Collection<String> values = CollectionUtils.collect(configuration.listOfConfigKeys(), o -> {
ConfigurationProperty property = configuration.getProperty(o);
return property.getConfigurationValue().getValue();
});
assertThat(new ArrayList<>(values)).isEqualTo(asList("http://fake-go-server", "godev", "password"));
}
use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.
the class ElasticAgentPluginInfoBuilder method elasticElasticAgentProfileSettings.
private PluggableInstanceSettings elasticElasticAgentProfileSettings(String pluginId) {
List<PluginConfiguration> profileMetadata = extension.getProfileMetadata(pluginId);
String profileView = extension.getProfileView(pluginId);
return new PluggableInstanceSettings(profileMetadata, new PluginView(profileView));
}
Aggregations