Search in sources :

Example 26 with PluginConfiguration

use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.

the class ElasticAgentExtensionV5Test method shouldGetClusterProfileMetadata.

@Test
public void shouldGetClusterProfileMetadata() {
    String responseBody = "[{\"key\":\"Username\",\"metadata\":{\"required\":true,\"secure\":false}},{\"key\":\"Password\",\"metadata\":{\"required\":true,\"secure\":true}}]";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    final List<PluginConfiguration> metadata = extensionV5.getClusterProfileMetadata(PLUGIN_ID);
    assertThat(metadata, hasSize(2));
    assertThat(metadata, containsInAnyOrder(new PluginConfiguration("Username", new Metadata(true, false)), new PluginConfiguration("Password", new Metadata(true, true))));
    assertExtensionRequest("5.0", REQUEST_GET_CLUSTER_PROFILE_METADATA, null);
}
Also used : Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 27 with PluginConfiguration

use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.

the class PluginSettingsTest method shouldAddConfigurationsToSettingsMapCorrectly.

@Test
public void shouldAddConfigurationsToSettingsMapCorrectly() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("k1", new Metadata(true, false)));
    pluginConfigurations.add(new PluginConfiguration("k2", new Metadata(true, true)));
    ConfigRepoPluginInfo pluginInfo = new ConfigRepoPluginInfo(null, null, new PluggableInstanceSettings(pluginConfigurations), new Capabilities());
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("k2"), new EncryptedConfigurationValue(new GoCipher().encrypt("v2"))));
    PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
    pluginSettings.addConfigurations(pluginInfo, configurationProperties);
    PluginSettingsConfiguration pluginSettingsProperties = pluginSettings.toPluginSettingsConfiguration();
    assertThat(pluginSettingsProperties.size(), is(2));
    assertThat(pluginSettingsProperties.get("k1").getValue(), is("v1"));
    assertThat(pluginSettingsProperties.get("k2").getValue(), is("v2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.jupiter.api.Test)

Example 28 with PluginConfiguration

use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.

the class PluginSettingsTest method shouldEncryptedValuesForSecureProperties.

@Test
public void shouldEncryptedValuesForSecureProperties() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("k1", new Metadata(true, false)));
    pluginConfigurations.add(new PluginConfiguration("k2", new Metadata(true, true)));
    ConfigRepoPluginInfo pluginInfo = new ConfigRepoPluginInfo(null, null, new PluggableInstanceSettings(pluginConfigurations), new Capabilities());
    ConfigurationProperty configProperty1 = new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"));
    ConfigurationProperty configProperty2 = new ConfigurationProperty(new ConfigurationKey("k2"), new EncryptedConfigurationValue(new GoCipher().encrypt("v2")));
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(configProperty1);
    configurationProperties.add(configProperty2);
    PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
    pluginSettings.addConfigurations(pluginInfo, configurationProperties);
    List<ConfigurationProperty> pluginSettingsProperties = pluginSettings.getPluginSettingsProperties();
    assertThat(pluginSettingsProperties.size(), is(2));
    assertThat(pluginSettingsProperties.get(0), is(configProperty1));
    assertThat(pluginSettingsProperties.get(1), is(configProperty2));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Capabilities(com.thoughtworks.go.plugin.domain.configrepo.Capabilities) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) Test(org.junit.jupiter.api.Test)

Example 29 with PluginConfiguration

use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldEncryptPluggablePublishArtifactProperties.

@Test
void shouldEncryptPluggablePublishArtifactProperties() throws Exception {
    PluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id("cd.go.artifact.docker.registry").version("1.0").build();
    PluginConfiguration buildFile = new PluginConfiguration("BuildFile", new Metadata(false, false));
    PluginConfiguration image = new PluginConfiguration("Image", new Metadata(false, true));
    PluginConfiguration tag = new PluginConfiguration("Tag", new Metadata(false, false));
    PluginConfiguration fetchProperty = new PluginConfiguration("FetchProperty", new Metadata(false, true));
    PluginConfiguration fetchTag = new PluginConfiguration("Tag", new Metadata(false, false));
    PluginConfiguration registryUrl = new PluginConfiguration("RegistryURL", new Metadata(true, false));
    PluginConfiguration username = new PluginConfiguration("Username", new Metadata(false, false));
    PluginConfiguration password = new PluginConfiguration("Password", new Metadata(false, true));
    PluggableInstanceSettings storeConfigSettings = new PluggableInstanceSettings(asList(registryUrl, username, password));
    PluggableInstanceSettings publishArtifactSettings = new PluggableInstanceSettings(asList(buildFile, image, tag));
    PluggableInstanceSettings fetchArtifactSettings = new PluggableInstanceSettings(asList(fetchProperty, fetchTag));
    ArtifactPluginInfo artifactPluginInfo = new ArtifactPluginInfo(pluginDescriptor, storeConfigSettings, publishArtifactSettings, fetchArtifactSettings, null, new Capabilities());
    ArtifactMetadataStore.instance().setPluginInfo(artifactPluginInfo);
    String content = goConfigMigration.upgradeIfNecessary(IOUtils.toString(getClass().getResource("/data/pluggable_artifacts_with_params.xml"), UTF_8));
    CruiseConfig config = xmlLoader.loadConfigHolder(content).configForEdit;
    PipelineConfig ancestor = config.pipelineConfigByName(new CaseInsensitiveString("ancestor"));
    PipelineConfig parent = config.pipelineConfigByName(new CaseInsensitiveString("parent"));
    PipelineConfig child = config.pipelineConfigByName(new CaseInsensitiveString("child"));
    Configuration ancestorPublishArtifactConfig = ancestor.get(0).getJobs().first().artifactTypeConfigs().getPluggableArtifactConfigs().get(0).getConfiguration();
    Configuration parentPublishArtifactConfig = parent.get(0).getJobs().first().artifactTypeConfigs().getPluggableArtifactConfigs().get(0).getConfiguration();
    Configuration childFetchArtifactFromAncestorConfig = ((FetchPluggableArtifactTask) child.get(0).getJobs().first().tasks().get(0)).getConfiguration();
    Configuration childFetchArtifactFromParentConfig = ((FetchPluggableArtifactTask) child.get(0).getJobs().first().tasks().get(1)).getConfiguration();
    ArtifactStore dockerhubStore = config.getArtifactStores().first();
    assertConfigProperty(ancestorPublishArtifactConfig, "Image", "IMAGE_SECRET", true);
    assertConfigProperty(ancestorPublishArtifactConfig, "Tag", "ancestor_tag_${GO_PIPELINE_COUNTER}", false);
    assertConfigProperty(parentPublishArtifactConfig, "Image", "IMAGE_SECRET", true);
    assertConfigProperty(parentPublishArtifactConfig, "Tag", "parent_tag_${GO_PIPELINE_COUNTER}", false);
    assertConfigProperty(childFetchArtifactFromAncestorConfig, "FetchProperty", "SECRET", true);
    assertConfigProperty(childFetchArtifactFromAncestorConfig, "Tag", "ancestor_tag", false);
    assertConfigProperty(childFetchArtifactFromParentConfig, "FetchProperty", "SECRET", true);
    assertConfigProperty(childFetchArtifactFromParentConfig, "Tag", "parent_tag", false);
    assertConfigProperty(dockerhubStore, "RegistryURL", "https://index.docker.io/v1/", false);
    assertConfigProperty(dockerhubStore, "Username", "docker-user", false);
    assertConfigProperty(dockerhubStore, "Password", "SECRET", true);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) ArtifactPluginInfo(com.thoughtworks.go.plugin.domain.artifact.ArtifactPluginInfo) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) Capabilities(com.thoughtworks.go.plugin.domain.artifact.Capabilities) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 30 with PluginConfiguration

use of com.thoughtworks.go.plugin.domain.common.PluginConfiguration in project gocd by gocd.

the class CachedGoConfigIntegrationTest method setupMetadataForPlugin.

private void setupMetadataForPlugin() {
    PluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id("cd.go.artifact.docker.registry").build();
    PluginConfiguration buildFile = new PluginConfiguration("BuildFile", new Metadata(false, false));
    PluginConfiguration image = new PluginConfiguration("Image", new Metadata(false, true));
    PluginConfiguration tag = new PluginConfiguration("Tag", new Metadata(false, false));
    PluginConfiguration fetchProperty = new PluginConfiguration("FetchProperty", new Metadata(false, true));
    PluginConfiguration fetchTag = new PluginConfiguration("Tag", new Metadata(false, false));
    PluginConfiguration registryUrl = new PluginConfiguration("RegistryURL", new Metadata(true, false));
    PluginConfiguration username = new PluginConfiguration("Username", new Metadata(false, false));
    PluginConfiguration password = new PluginConfiguration("Password", new Metadata(false, true));
    PluggableInstanceSettings storeConfigSettings = new PluggableInstanceSettings(asList(registryUrl, username, password));
    PluggableInstanceSettings publishArtifactSettings = new PluggableInstanceSettings(asList(buildFile, image, tag));
    PluggableInstanceSettings fetchArtifactSettings = new PluggableInstanceSettings(asList(fetchProperty, fetchTag));
    ArtifactPluginInfo artifactPluginInfo = new ArtifactPluginInfo(pluginDescriptor, storeConfigSettings, publishArtifactSettings, fetchArtifactSettings, null, new Capabilities());
    ArtifactMetadataStore.instance().setPluginInfo(artifactPluginInfo);
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) Capabilities(com.thoughtworks.go.plugin.domain.artifact.Capabilities) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ArtifactPluginInfo(com.thoughtworks.go.plugin.domain.artifact.ArtifactPluginInfo)

Aggregations

PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)58 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)51 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)38 Test (org.junit.jupiter.api.Test)36 GoCipher (com.thoughtworks.go.security.GoCipher)14 ArrayList (java.util.ArrayList)14 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 PluginDescriptor (com.thoughtworks.go.plugin.api.info.PluginDescriptor)11 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)9 Test (org.junit.Test)9 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)8 ArtifactPluginInfo (com.thoughtworks.go.plugin.domain.artifact.ArtifactPluginInfo)8 Capabilities (com.thoughtworks.go.plugin.domain.artifact.Capabilities)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)6 PluginView (com.thoughtworks.go.plugin.domain.common.PluginView)6 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)5 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)5