Search in sources :

Example 16 with PluggableSCMMaterialConfig

use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.

the class SCMConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForSCMs.

@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForSCMs() throws Exception {
    String encryptedValue = new GoCipher().encrypt("secure-two");
    String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + "    <scm id='scm-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" + "    </scm>\n" + "  </scms>" + "<pipelines group=\"group_name\">\n" + "  <pipeline name=\"new_name\">\n" + "    <materials>\n" + "      <scm ref='scm-id' />\n" + "    </materials>\n" + "    <stage name=\"stage_name\">\n" + "      <jobs>\n" + "        <job name=\"job_name\">\n" + "           <tasks><ant /></tasks>\n" + "        </job>\n" + "      </jobs>\n" + "    </stage>\n" + "  </pipeline>\n" + "</pipelines></cruise>";
    // meta data of scm
    SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration();
    scmConfiguration.add(new SCMProperty("plain"));
    scmConfiguration.add(new SCMProperty("secure-one").with(SCMConfiguration.SECURE, true));
    scmConfiguration.add(new SCMProperty("secure-two").with(SCMConfiguration.SECURE, true));
    SCMMetadataStore.getInstance().addMetadataFor("plugin-id", new SCMConfigurations(scmConfiguration), null);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    SCM scmConfig = goConfigHolder.config.getSCMs().first();
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(pluggableSCMMaterialConfig.getSCMConfig(), is(scmConfig));
    Configuration configuration = pluggableSCMMaterialConfig.getSCMConfig().getConfiguration();
    assertThat(configuration.get(0).getConfigurationValue().getValue(), is("value"));
    assertThat(configuration.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
    assertThat(configuration.get(2).getEncryptedValue(), is(encryptedValue));
}
Also used : GoConfigHolder(com.thoughtworks.go.config.GoConfigHolder) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SCM(com.thoughtworks.go.domain.scm.SCM) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 17 with PluggableSCMMaterialConfig

use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.

the class ConfigConverterTest method shouldFailToConvertConfigMaterialWhenPluggableScmMaterialWithWhitelist.

@Test
public void shouldFailToConvertConfigMaterialWhenPluggableScmMaterialWithWhitelist() {
    SCM myscm = new SCM("scmid", new PluginConfiguration(), new Configuration());
    SCMs scms = new SCMs(myscm);
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setSCMs(scms);
    when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
    PluggableSCMMaterialConfig configRepoMaterial = new PluggableSCMMaterialConfig(new CaseInsensitiveString("scmid"), myscm, null, null);
    when(context.configMaterial()).thenReturn(configRepoMaterial);
    CRConfigMaterial crConfigMaterial = new CRConfigMaterial("example", "dest1", new CRFilter(filter, true));
    try {
        configConverter.toMaterialConfig(crConfigMaterial, context);
        fail("should have thrown");
    } catch (ConfigConvertionException ex) {
        assertThat(ex.getMessage(), is("Plugable SCMs do not support whitelisting"));
    }
}
Also used : SCMs(com.thoughtworks.go.domain.scm.SCMs) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCM(com.thoughtworks.go.domain.scm.SCM) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.Test)

Example 18 with PluggableSCMMaterialConfig

use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.

the class PipelineGroups method getPluggableSCMMaterialUsageInPipelines.

public Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> getPluggableSCMMaterialUsageInPipelines() {
    if (pluggableSCMMaterialToPipelineMap == null) {
        synchronized (this) {
            if (pluggableSCMMaterialToPipelineMap == null) {
                pluggableSCMMaterialToPipelineMap = new HashMap<>();
                for (PipelineConfigs pipelineConfigs : this) {
                    for (PipelineConfig pipelineConfig : pipelineConfigs) {
                        for (PluggableSCMMaterialConfig pluggableSCMMaterialConfig : pipelineConfig.pluggableSCMMaterialConfigs()) {
                            String scmId = pluggableSCMMaterialConfig.getScmId();
                            if (!pluggableSCMMaterialToPipelineMap.containsKey(scmId)) {
                                pluggableSCMMaterialToPipelineMap.put(scmId, new ArrayList<>());
                            }
                            pluggableSCMMaterialToPipelineMap.get(scmId).add(new Pair<>(pipelineConfig, pipelineConfigs));
                        }
                    }
                }
            }
        }
    }
    return pluggableSCMMaterialToPipelineMap;
}
Also used : PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)

Example 19 with PluggableSCMMaterialConfig

use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.

the class GoConfigGraphWalkerTest method shouldNotWalkSCMMaterialWhileTraversingPluggableSCMMaterial.

@Test
public void shouldNotWalkSCMMaterialWhileTraversingPluggableSCMMaterial() {
    SCM scmConfig = mock(SCM.class);
    when(scmConfig.getName()).thenReturn("scm");
    when(scmConfig.getId()).thenReturn("scm-id");
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = new PluggableSCMMaterialConfig("scm-id");
    setField(pluggableSCMMaterialConfig, "scmConfig", scmConfig);
    BasicCruiseConfig config = new BasicCruiseConfig();
    config.getSCMs().add(scmConfig);
    final ConfigSaveValidationContext context = new ConfigSaveValidationContext(config);
    new GoConfigGraphWalker(pluggableSCMMaterialConfig).walk(new GoConfigGraphWalker.Handler() {

        @Override
        public void handle(Validatable validatable, ValidationContext ctx) {
            validatable.validate(context);
        }
    });
    verify(scmConfig, never()).validate(any(ValidationContext.class));
}
Also used : SCM(com.thoughtworks.go.domain.scm.SCM) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 20 with PluggableSCMMaterialConfig

use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.

the class PipelineConfigTest method shouldGetPluggableSCMMaterialConfigs.

@Test
public void shouldGetPluggableSCMMaterialConfigs() throws Exception {
    SvnMaterialConfig svn = svn("svn", false);
    PluggableSCMMaterialConfig pluggableSCMMaterialOne = new PluggableSCMMaterialConfig("scm-id-1");
    PluggableSCMMaterialConfig pluggableSCMMaterialTwo = new PluggableSCMMaterialConfig("scm-id-2");
    PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(svn, pluggableSCMMaterialOne, pluggableSCMMaterialTwo));
    List<PluggableSCMMaterialConfig> pluggableSCMMaterialConfigs = pipelineConfig.pluggableSCMMaterialConfigs();
    assertThat(pluggableSCMMaterialConfigs.size(), is(2));
    assertThat(pluggableSCMMaterialConfigs, hasItems(pluggableSCMMaterialOne, pluggableSCMMaterialTwo));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)36 Test (org.junit.jupiter.api.Test)25 SCM (com.thoughtworks.go.domain.scm.SCM)14 SCMs (com.thoughtworks.go.domain.scm.SCMs)11 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)9 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)8 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)7 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)6 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)5 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)4 GoConfigHolder (com.thoughtworks.go.config.GoConfigHolder)3 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)3 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)3 ErrorGetter (com.thoughtworks.go.api.representers.ErrorGetter)2 Filter (com.thoughtworks.go.config.materials.Filter)2