Пример #1
0
 GoAcl readAclBy(String pipelineName, String stageName) {
   PipelineConfig pipelineConfig = pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
   StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName));
   AdminsConfig adminsConfig = stageConfig.getApproval().getAuthConfig();
   List<CaseInsensitiveString> users = getAuthorizedUsers(adminsConfig);
   return new GoAcl(users);
 }
Пример #2
0
 public List<CaseInsensitiveString> pipelines(String group) {
   PipelineConfigs configs = getCurrentConfig().pipelines(group);
   List<CaseInsensitiveString> pipelines = new ArrayList<>();
   for (PipelineConfig config : configs) {
     pipelines.add(config.name());
   }
   return pipelines;
 }
Пример #3
0
 public List<PipelineConfig> downstreamPipelinesOf(String pipelineName) {
   List<PipelineConfig> dependencies = new ArrayList<>();
   for (PipelineConfig config : getAllPipelineConfigs()) {
     if (config.dependsOn(new CaseInsensitiveString(pipelineName))) {
       dependencies.add(config);
     }
   }
   return dependencies;
 }
Пример #4
0
 private List<String> invertSelections(List<String> selectedPipelines) {
   List<String> unselectedPipelines = new ArrayList<>();
   List<PipelineConfig> pipelineConfigList = cruiseConfig().getAllPipelineConfigs();
   for (PipelineConfig pipelineConfig : pipelineConfigList) {
     String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
     if (!selectedPipelines.contains(pipelineName)) {
       unselectedPipelines.add(pipelineName);
     }
   }
   return unselectedPipelines;
 }
  @Test
  public void shouldGetGroupWithTemplatesAsXml() throws Exception {
    configHelper.addTemplate("template-1", "dev");
    configHelper.addPipelineWithGroup("group", "pipeline", "dev", "linux");
    PipelineConfig pipelineWithTemplate =
        configHelper.addPipelineWithTemplate("group", "pipeline-with-template", "template-1");
    assertThat(
        pipelineWithTemplate.size(),
        is(0)); // should not expect mutation of pipeline config passed in
    assertThat(
        configHelper
            .currentConfig()
            .pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template"))
            .size(),
        is(1));

    CruiseConfig config = goConfigService.currentCruiseConfig();
    PipelineConfig pipelineConfig =
        config.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template"));
    assertThat("Should not modify the original template", pipelineConfig.size(), is(1));

    controller.getGroupAsXmlPartial("group", null, response);
    String content =
        "<pipelines group=\"group\">\n"
            + "  <pipeline name=\"pipeline\">\n"
            + "    <materials>\n"
            + "      <svn url=\"svn:///user:pass@tmp/foo\" />\n"
            + "    </materials>\n"
            + "    <stage name=\"dev\">\n"
            + "      <jobs>\n"
            + "        <job name=\"linux\" />\n"
            + "      </jobs>\n"
            + "    </stage>\n"
            + "  </pipeline>\n"
            + "  <pipeline name=\"pipeline-with-template\" template=\"template-1\">\n"
            + "    <materials>\n"
            + "      <svn url=\"svn:///user:pass@tmp/foo\" />\n"
            + "    </materials>\n"
            + "  </pipeline>\n"
            + "</pipelines>";
    assertValidContentAndStatus(SC_OK, "text/xml", content);

    MockHttpServletResponse postResponse = new MockHttpServletResponse();
    controller.postGroupAsXmlPartial("group", content, null, postResponse);

    config = goConfigService.currentCruiseConfig();
    pipelineConfig =
        config.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template"));
    assertThat("Should not modify the original template", pipelineConfig.size(), is(1));
  }
Пример #6
0
  @Test
  public void shouldReadFolderAndFilterForPluggableSCMMaterialConfig() throws Exception {
    String xml =
        "<cruise schemaVersion='"
            + GoConstants.CONFIG_SCHEMA_VERSION
            + "'>\n"
            + "<scms>\n"
            + "    <scm id='scm-id' name='scm-name'>\n"
            + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n"
            + "      <configuration>\n"
            + "        <property>\n"
            + "          <key>url</key>\n"
            + "          <value>http://go</value>\n"
            + "        </property>\n"
            + "      </configuration>\n"
            + "    </scm>\n"
            + "  </scms>"
            + "<pipelines group=\"group_name\">\n"
            + "  <pipeline name=\"new_name\">\n"
            + "    <materials>\n"
            + "      <scm ref='scm-id' dest='dest'>\n"
            + "            <filter>\n"
            + "                <ignore pattern=\"x\"/>\n"
            + "                <ignore pattern=\"y\"/>\n"
            + "            </filter>\n"
            + "      </scm>\n"
            + "    </materials>\n"
            + "    <stage name=\"stage_name\">\n"
            + "      <jobs>\n"
            + "        <job name=\"job_name\" />\n"
            + "      </jobs>\n"
            + "    </stage>\n"
            + "  </pipeline>\n"
            + "</pipelines></cruise>";

    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    PipelineConfig pipelineConfig =
        goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig =
        (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(
        pluggableSCMMaterialConfig.getSCMConfig(), is(goConfigHolder.config.getSCMs().get(0)));
    assertThat(pluggableSCMMaterialConfig.getFolder(), is("dest"));
    assertThat(
        pluggableSCMMaterialConfig.filter(),
        is(new Filter(new IgnoredFiles("x"), new IgnoredFiles("y"))));
  }
Пример #7
0
 private PipelineConfigDependencyGraph findUpstream(PipelineConfig currentPipeline) {
   List<PipelineConfigDependencyGraph> graphs = new ArrayList<>();
   for (CaseInsensitiveString name : currentPipeline.upstreamPipelines()) {
     PipelineConfig pipelineConfig = getCurrentConfig().pipelineConfigByName(name);
     graphs.add(findUpstream(pipelineConfig));
   }
   return new PipelineConfigDependencyGraph(
       currentPipeline, graphs.toArray(new PipelineConfigDependencyGraph[0]));
 }
Пример #8
0
 public JobConfigIdentifier translateToActualCase(JobConfigIdentifier identifier) {
   PipelineConfig pipelineConfig =
       getCurrentConfig()
           .pipelineConfigByName(new CaseInsensitiveString(identifier.getPipelineName()));
   String translatedPipelineName = CaseInsensitiveString.str(pipelineConfig.name());
   StageConfig stageConfig =
       pipelineConfig.findBy(new CaseInsensitiveString(identifier.getStageName()));
   if (stageConfig == null) {
     throw new StageNotFoundException(
         new CaseInsensitiveString(identifier.getPipelineName()),
         new CaseInsensitiveString(identifier.getStageName()));
   }
   String translatedStageName = CaseInsensitiveString.str(stageConfig.name());
   JobConfig plan = stageConfig.jobConfigByInstanceName(identifier.getJobName(), true);
   if (plan == null) {
     throw new JobNotFoundException(
         identifier.getPipelineName(), identifier.getStageName(), identifier.getJobName());
   }
   String translatedJobName = plan.translatedName(identifier.getJobName());
   return new JobConfigIdentifier(translatedPipelineName, translatedStageName, translatedJobName);
 }
Пример #9
0
  @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"
            + "      </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().getValue(),
        is(new GoCipher().encrypt("secure-value")));
    assertThat(configuration.get(2).getEncryptedValue().getValue(), is(encryptedValue));
  }
Пример #10
0
 public boolean isPipelineEditableViaUI(String pipelineName) {
   PipelineConfig pipelineConfig =
       this.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
   if (pipelineConfig == null) return false;
   return isOriginLocal(pipelineConfig.getOrigin());
 }