public List<PluggableArtifactConfig> findByStoreId(String storeId) { final ArrayList<PluggableArtifactConfig> pluggableArtifactConfigs = new ArrayList<>(); for (PluggableArtifactConfig artifact : getPluggableArtifactConfigs()) { if (artifact.getStoreId().equals(storeId)) { pluggableArtifactConfigs.add(artifact); } } return pluggableArtifactConfigs; }
public String toJSON() { final HashMap<String, Object> artifactStoreAsHashMap = new HashMap<>(); artifactStoreAsHashMap.put("id", getId()); artifactStoreAsHashMap.put("storeId", getStoreId()); artifactStoreAsHashMap.put("configuration", this.getConfiguration().getConfigurationAsMap(true)); return new Gson().toJson(artifactStoreAsHashMap); }
public void encryptSecureProperties(CruiseConfig preprocessedCruiseConfig, PluggableArtifactConfig preprocessedPluggableArtifactConfig) { if (storeId != null) { ArtifactStore artifactStore = preprocessedCruiseConfig.getArtifactStores().find(preprocessedPluggableArtifactConfig.getStoreId()); encryptSecureConfigurations(artifactStore); } }
public Map<String, Map> artifactIdToPluginIdForFetchPluggableArtifact(String stagePatent, String currentPipelineName, String currentStageName) { final List<PipelineConfig> pipelineConfigs = stagePatent.equals("templates") ? getAllPipelineConfigs() : pipelinesForFetchArtifacts(currentPipelineName); Map<String, Map> allArtifacts = new HashMap<>(); pipelineConfigs.forEach(pipelineConfig -> { final String pipelineName = pipelineConfig.getName().toString(); final HashMap<String, Map> artifactsInPipeline = new HashMap<>(); allArtifacts.put(pipelineName, artifactsInPipeline); final boolean isCurrentPipeline = pipelineName.equalsIgnoreCase(currentPipelineName); final List<StageConfig> stageConfigs = isCurrentPipeline ? pipelineConfig.allStagesBefore(new CaseInsensitiveString(currentStageName)) : pipelineConfig.getStages(); stageConfigs.forEach(stageConfig -> { final String stageName = stageConfig.name().toString(); artifactsInPipeline.put(stageName, new HashMap<String, Map>()); stageConfig.getJobs().forEach(jobConfig -> { artifactsInPipeline.get(stageName).put(jobConfig.name().toString(), jobConfig.artifactConfigs().getPluggableArtifactConfigs().stream().collect(toMap(PluggableArtifactConfig::getId, c -> { final ArtifactStore artifactStore = artifactStores().find(c.getStoreId()); return artifactStore == null ? null : artifactStore.getPluginId(); }))); }); }); }); return allArtifacts; }
@Override public void validateUniqueness(List<ArtifactConfig> existingArtifactConfigList) { for (ArtifactConfig existingArtifactConfig : existingArtifactConfigList) { if (existingArtifactConfig instanceof PluggableArtifactConfig) { final PluggableArtifactConfig pluggableArtifactConfig = (PluggableArtifactConfig) existingArtifactConfig; if (this.getId().equalsIgnoreCase(pluggableArtifactConfig.getId())) { this.addError("id", String.format("Duplicate pluggable artifacts with id `%s` defined.", getId())); existingArtifactConfig.addError("id", String.format("Duplicate pluggable artifacts with id `%s` defined.", getId())); } if (this.getStoreId().equalsIgnoreCase(pluggableArtifactConfig.getStoreId())) { if (configuration.size() == pluggableArtifactConfig.getConfiguration().size() && this.configuration.containsAll(pluggableArtifactConfig.getConfiguration())) { this.addError("id", "Duplicate pluggable artifacts configuration defined."); existingArtifactConfig.addError("id", "Duplicate pluggable artifacts configuration defined."); } } return; } } existingArtifactConfigList.add(this); }
private ArtifactStore getArtifactStoreFor(FetchPluggableArtifactTask task, JobIdentifier fetchFrom) { final JobConfig job = goConfigService.getCurrentConfig().findJob(fetchFrom.getPipelineName(), fetchFrom.getStageName(), fetchFrom.getBuildName()); final PluggableArtifactConfig artifactConfig = job.artifactConfigs().findByArtifactId(task.getArtifactId()); if (artifactConfig == null) { throw new RuntimeException(format("Pluggable artifact with id `%s` does not exist.", task.getArtifactId())); } final ArtifactStore artifactStore = goConfigService.artifactStores().find(artifactConfig.getStoreId()); if (artifactStore == null) { throw new RuntimeException(format("Artifact store with id `%s` does not exist.", task.getArtifactId())); } return artifactStore; }
public static void toJSON(OutputWriter jsonWriter, PluggableArtifactConfig pluggableArtifactConfig) { jsonWriter.add("artifact_id", pluggableArtifactConfig.getId()); jsonWriter.add("store_id", pluggableArtifactConfig.getStoreId()); jsonWriter.addChildList("configuration", configurationWriter -> ConfigurationPropertyRepresenter.toJSON(configurationWriter, pluggableArtifactConfig.getConfiguration())); }
public static void toJSON(OutputWriter jsonWriter, PluggableArtifactConfig pluggableArtifactConfig) { jsonWriter.add("artifact_id", pluggableArtifactConfig.getId()); jsonWriter.add("store_id", pluggableArtifactConfig.getStoreId()); jsonWriter.addChildList("configuration", configurationWriter -> ConfigurationPropertyRepresenter.toJSON(configurationWriter, pluggableArtifactConfig.getConfiguration())); }
void validatePublishAndFetchExternalConfigs(PipelineConfig pipelineConfig, CruiseConfig preprocessedConfig) { for (PluggableArtifactConfig pluggableArtifactConfig : pipelineConfig.getExternalArtifactConfigs()) { externalArtifactsService.validateExternalArtifactConfig(pluggableArtifactConfig, goConfigService.artifactStores().find(pluggableArtifactConfig.getStoreId()), true); } for (FetchPluggableArtifactTask fetchPluggableArtifactTask : pipelineConfig.getFetchExternalArtifactTasks()) { externalArtifactsService.validateFetchExternalArtifactTask(fetchPluggableArtifactTask, pipelineConfig, preprocessedConfig); } } }
private CRArtifact artifactConfigToCRArtifact(ArtifactConfig artifactConfig) { if (artifactConfig instanceof BuildArtifactConfig) { BuildArtifactConfig buildArtifact = (BuildArtifactConfig) artifactConfig; return new CRBuiltInArtifact(buildArtifact.getSource(), buildArtifact.getDestination()); } else if (artifactConfig instanceof TestArtifactConfig) { TestArtifactConfig testArtifact = (TestArtifactConfig) artifactConfig; return new CRBuiltInArtifact(testArtifact.getSource(), testArtifact.getDestination(), CRArtifactType.test); } else if (artifactConfig instanceof PluggableArtifactConfig) { PluggableArtifactConfig pluggableArtifact = (PluggableArtifactConfig) artifactConfig; List<CRConfigurationProperty> crConfigurationProperties = configurationToCRConfiguration(pluggableArtifact.getConfiguration()); return new CRPluggableArtifact(pluggableArtifact.getId(), pluggableArtifact.getStoreId(), crConfigurationProperties); } else { throw new RuntimeException(String.format("Unsupported Artifact Type: %s.", artifactConfig.getArtifactType())); } }
void validatePublishAndFetchExternalConfigs(PipelineTemplateConfig pipelineTemplateConfig, CruiseConfig preprocessedConfig) { List<PipelineConfig> associatedPipelineConfigs = preprocessedConfig.pipelineConfigsAssociatedWithTemplate(templateConfig.name()); for (PipelineConfig associatedPipelineConfig : associatedPipelineConfigs) { for (PluggableArtifactConfig pluggableArtifactConfig : associatedPipelineConfig.getExternalArtifactConfigs()) { externalArtifactsService.validateExternalArtifactConfig(pluggableArtifactConfig, preprocessedConfig.getArtifactStores().find(pluggableArtifactConfig.getStoreId()), true); if (!pluggableArtifactConfig.getAllErrors().isEmpty()) { pipelineTemplateConfig.addError("pipeline", String.format("Error validating publish config on associated pipeline `%s`: %s", associatedPipelineConfig.name(), pluggableArtifactConfig.getAllErrors())); } } for (FetchPluggableArtifactTask fetchPluggableArtifactTask : associatedPipelineConfig.getFetchExternalArtifactTasks()) { externalArtifactsService.validateFetchExternalArtifactTask(fetchPluggableArtifactTask, pipelineTemplateConfig, preprocessedConfig); if (!fetchPluggableArtifactTask.getAllErrors().isEmpty()) { pipelineTemplateConfig.addError("pipeline", String.format("Error validating publish config on associated pipeline `%s`: %s", associatedPipelineConfig.name(), fetchPluggableArtifactTask.getAllErrors())); } } } }
@Test public void setConfigAttributes_shouldSetConfigurationAsIsIfPluginIdIsBlank() throws CryptoException { HashMap<Object, Object> imageMap = new HashMap<>(); imageMap.put("value", new GoCipher().encrypt("some-encrypted-value")); imageMap.put("isSecure", "true"); HashMap<Object, Object> tagMap = new HashMap<>(); tagMap.put("value", "18.6.0"); tagMap.put("isSecure", "false"); HashMap<Object, Object> configurationMap1 = new HashMap<>(); configurationMap1.put("Image", imageMap); configurationMap1.put("Tag", tagMap); HashMap<String, Object> artifactPlan1 = new HashMap<>(); artifactPlan1.put("artifactTypeValue", "Pluggable Artifact"); artifactPlan1.put("id", "artifactId"); artifactPlan1.put("storeId", "storeId"); artifactPlan1.put("pluginId", ""); artifactPlan1.put("configuration", configurationMap1); List<Map> artifactPlansList = new ArrayList<>(); artifactPlansList.add(artifactPlan1); ArtifactConfigs artifactConfigs = new ArtifactConfigs(); artifactConfigs.setConfigAttributes(artifactPlansList); assertThat(artifactConfigs.size(), is(1)); PluggableArtifactConfig artifactConfig = (PluggableArtifactConfig) artifactConfigs.get(0); assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external)); assertThat(artifactConfig.getId(), is("artifactId")); assertThat(artifactConfig.getStoreId(), is("storeId")); assertThat(artifactConfig.getConfiguration().getProperty("Image").getValue(), is("some-encrypted-value")); assertThat(artifactConfig.getConfiguration().getProperty("Tag").getValue(), is("18.6.0")); }
private void validateFetchTasks(FetchPluggableArtifactTask preprocessedFetchPluggableArtifactTask, CruiseConfig preprocessedConfig, PluggableArtifactConfig specifiedExternalArtifact) { if (specifiedExternalArtifact != null) { ArtifactStore artifactStore = preprocessedConfig.getArtifactStores().find(specifiedExternalArtifact.getStoreId()); if (specifiedExternalArtifact.hasValidPluginAndStore(artifactStore)) { try { ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(artifactStore.getPluginId(), preprocessedFetchPluggableArtifactTask.getConfiguration().getConfigurationAsMap(true)); mapErrorsToConfiguration(validationResult, preprocessedFetchPluggableArtifactTask.getConfiguration(), preprocessedFetchPluggableArtifactTask); } catch (PluginNotFoundException e) { preprocessedFetchPluggableArtifactTask.addError("pluginId", String.format("Plugin with id `%s` is not found.", artifactStore.getPluginId())); } } else { preprocessedFetchPluggableArtifactTask.addError("pluginId", "Could not determine the plugin to perform the plugin validations. Possible reasons: artifact store does not exist or plugin is not installed."); } } }
assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external)); assertThat(artifactConfig.getId(), is("artifactId")); assertThat(artifactConfig.getStoreId(), is("storeId")); assertThat(artifactConfig.getConfiguration().getProperty("Image").isSecure(), is(false));
@Test public void shouldCreatePluggableArtifact() { final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID", create("Foo", false, "Bar")); assertThat(artifactConfig.getId(), is("Artifact-ID")); assertThat(artifactConfig.getStoreId(), is("Store-ID")); assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external)); assertThat(artifactConfig.getArtifactTypeValue(), is("Pluggable Artifact")); assertThat(artifactConfig.getConfiguration().get(0), is(create("Foo", false, "Bar"))); }
private void encryptSecurePluginConfiguration(CruiseConfig preprocessedCruiseConfig, PluggableArtifactConfig externalArtifact) { if (externalArtifact != null) { ArtifactStore artifactStore = preprocessedCruiseConfig.getArtifactStores().find(externalArtifact.getStoreId()); if (artifactStore != null) { ArtifactPluginInfo pluginInfo = ArtifactMetadataStore.instance().getPluginInfo(artifactStore.getPluginId()); if (pluginInfo == null || pluginInfo.getFetchArtifactSettings() == null) { return; } for (ConfigurationProperty configurationProperty : getConfiguration()) { configurationProperty.handleSecureValueConfiguration(isSecure(configurationProperty.getConfigKeyName(), pluginInfo.getFetchArtifactSettings())); } } } }