Search in sources :

Example 21 with Metadata

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

the class PluggableTaskPluginInfoBuilderTest method shouldBuildPluginInfo.

@Test
public void shouldBuildPluginInfo() throws Exception {
    GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("plugin1").build();
    PluggableTaskPluginInfo pluginInfo = new PluggableTaskPluginInfoBuilder(extension).pluginInfoFor(descriptor);
    List<PluginConfiguration> pluginConfigurations = Arrays.asList(new PluginConfiguration("username", new Metadata(true, false)), new PluginConfiguration("password", new Metadata(true, true)));
    PluginView pluginView = new PluginView("some html");
    assertThat(pluginInfo.getDescriptor(), is(descriptor));
    assertThat(pluginInfo.getExtensionName(), is("task"));
    assertThat(pluginInfo.getDisplayName(), is("my task plugin"));
    assertThat(pluginInfo.getTaskSettings(), is(new PluggableInstanceSettings(pluginConfigurations, pluginView)));
    assertNull(pluginInfo.getPluginSettings());
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluggableTaskPluginInfo(com.thoughtworks.go.plugin.domain.pluggabletask.PluggableTaskPluginInfo) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) PluginView(com.thoughtworks.go.plugin.domain.common.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Example 22 with Metadata

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

the class ElasticAgentExtensionConverterV5Test method shouldGetTheElasticAgentInformationFromResponseBodyOfMigrateCall.

@Test
public void shouldGetTheElasticAgentInformationFromResponseBodyOfMigrateCall() throws CryptoException {
    String responseBody = "{" + "    \"plugin_settings\":{" + "        \"key2\":\"password\", " + "        \"key\":\"value\"" + "    }," + "    \"cluster_profiles\":[" + "        {" + "            \"id\":\"cluster_profile_id\"," + "            \"plugin_id\":\"plugin_id\"," + "            \"properties\":{" + "                \"some_key\":\"some_value\", " + "                \"some_key2\":\"some_value2\"" + "            }" + "         }" + "    ]," + "    \"elastic_agent_profiles\":[" + "        {" + "            \"id\":\"profile_id\"," + "            \"plugin_id\":\"plugin_id\"," + "            \"cluster_profile_id\":\"cluster_profile_id\"," + "            \"properties\":{" + "                \"some_key\":\"some_value\"," + "                \"some_key2\":\"some_value2\"" + "            }" + "        }" + "    ]" + "}\n";
    ElasticAgentMetadataStore store = ElasticAgentMetadataStore.instance();
    PluggableInstanceSettings elasticAgentProfileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("some_key", new Metadata(true, true))));
    PluggableInstanceSettings clusterProfileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("some_key2", new Metadata(true, true))));
    store.setPluginInfo(new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), elasticAgentProfileSettings, clusterProfileSettings, null, null, null));
    ElasticAgentInformation elasticAgentInformation = new ElasticAgentExtensionConverterV5().getElasticAgentInformationFromResponseBody(responseBody);
    ConfigurationProperty property1 = new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"));
    ConfigurationProperty property2 = new ConfigurationProperty(new ConfigurationKey("key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("password")));
    Configuration configuration = new Configuration();
    configuration.add(property1);
    configuration.add(property2);
    Map<String, String> pluginSettings = configuration.getConfigurationAsMap(true);
    List<ClusterProfile> clusterProfiles = new ArrayList<>();
    clusterProfiles.add(new ClusterProfile("cluster_profile_id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
    List<ElasticProfile> elasticAgentProfiles = new ArrayList<>();
    // do not worry about encryption, it is handled during config save (migrate-config) call
    elasticAgentProfiles.add(new ElasticProfile("profile_id", "cluster_profile_id", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new ConfigurationValue("some_value2"))));
    ElasticAgentInformation expectedElasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
    assertThat(elasticAgentInformation, is(expectedElasticAgentInformation));
}
Also used : ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) GoCipher(com.thoughtworks.go.security.GoCipher) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ElasticAgentMetadataStore(com.thoughtworks.go.plugin.access.elastic.ElasticAgentMetadataStore) ElasticAgentInformation(com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 23 with Metadata

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

the class ElasticAgentExtensionV4Test method shouldGetProfileMetadata.

@Test
public void shouldGetProfileMetadata() {
    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 = extensionV4.getElasticProfileMetadata(PLUGIN_ID);
    assertThat(metadata, hasSize(2));
    assertThat(metadata, containsInAnyOrder(new PluginConfiguration("Username", new Metadata(true, false)), new PluginConfiguration("Password", new Metadata(true, true))));
    assertExtensionRequest("4.0", REQUEST_GET_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 24 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata 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 25 with Metadata

use of com.thoughtworks.go.plugin.domain.common.Metadata 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)

Aggregations

Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)51 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)51 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)33 Test (org.junit.jupiter.api.Test)33 GoCipher (com.thoughtworks.go.security.GoCipher)13 ArrayList (java.util.ArrayList)13 PluginDescriptor (com.thoughtworks.go.plugin.api.info.PluginDescriptor)11 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)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 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)5 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)5 PluginView (com.thoughtworks.go.plugin.domain.common.PluginView)3