Search in sources :

Example 41 with PluginConfiguration

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));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 42 with PluginConfiguration

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"));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 43 with PluginConfiguration

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:");
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GoCipher(com.thoughtworks.go.security.GoCipher) 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) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.jupiter.api.Test)

Example 44 with PluginConfiguration

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"));
}
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) ArrayList(java.util.ArrayList) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.jupiter.api.Test)

Example 45 with PluginConfiguration

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));
}
Also used : PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) PluginView(com.thoughtworks.go.plugin.domain.common.PluginView)

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