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