public Map<String, String> storeIdToPluginId() { HashMap<String, String> artifactStoreToPluginId = new HashMap<>(); for (ArtifactStore artifactStore : getPluginProfiles()) { artifactStoreToPluginId.put(artifactStore.getId(), artifactStore.getPluginId()); } return artifactStoreToPluginId; } }
public boolean hasValidPluginAndStore(ArtifactStore artifactStore) { if (artifactStore == null) { return false; } ArtifactPluginInfo pluginInfo = ArtifactMetadataStore.instance().getPluginInfo(artifactStore.getPluginId()); return pluginInfo != null; }
@Override protected boolean hasPluginInfo() { return metadataStore().getPluginInfo(getPluginId()) != null; } }
private ArtifactPluginInfo getPluginInfo(ArtifactStore artifactStore) { return ArtifactMetadataStore.instance().getPluginInfo(artifactStore.getPluginId()); }
private void publishPluggableArtifact(PluggableArtifactMetadata pluggableArtifactMetadata, ArtifactPlan artifactPlan, ArtifactStore artifactStore, EnvironmentVariableContext environmentVariableContext) { try { final String pluginId = artifactStore.getPluginId(); final String message = format("[%s] Start to upload pluggable artifact using plugin `%s`.", PRODUCT_NAME, pluginId); goPublisher.taggedConsumeLine(GoPublisher.PUBLISH, message); LOGGER.info(message); final PublishArtifactResponse publishArtifactResponse = artifactExtension.publishArtifact(pluginId, artifactPlan, artifactStore, workingDirectory.getAbsolutePath(), environmentVariableContext); if (!publishArtifactResponse.getMetadata().isEmpty()) { final String artifactId = (String) artifactPlan.getPluggableArtifactConfiguration().get("id"); pluggableArtifactMetadata.addMetadata(pluginId, artifactId, publishArtifactResponse.getMetadata()); } } catch (RuntimeException e) { failedArtifact.add(artifactPlan); goPublisher.taggedConsumeLine(GoPublisher.ERR, format("[%s] %s", PRODUCT_NAME, e.getMessage())); LOGGER.error(e.getMessage(), e); } }
@Override public void build(DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, TaskExtension taskExtension, ArtifactExtension artifactExtension, PluginRequestProcessorRegistry pluginRequestProcessorRegistry, String consoleLogCharset) { downloadMetadataFile(publisher); try { pluginRequestProcessorRegistry.registerProcessorFor(CONSOLE_LOG.requestName(), ArtifactRequestProcessor.forFetchArtifact(publisher, environmentVariableContext)); final String message = format("[%s] Fetching pluggable artifact using plugin %s.", GoConstants.PRODUCT_NAME, artifactStore.getPluginId()); LOGGER.info(message); publisher.taggedConsumeLine(TaggedStreamConsumer.OUT, message); List<FetchArtifactEnvironmentVariable> newEnvironmentVariables = artifactExtension.fetchArtifact( artifactStore.getPluginId(), artifactStore, configuration, getMetadataFromFile(artifactId), agentWorkingDirectory()); updateEnvironmentVariableContextWith(publisher, environmentVariableContext, newEnvironmentVariables); } catch (Exception e) { publisher.taggedConsumeLine(TaggedStreamConsumer.ERR, e.getMessage()); LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } finally { pluginRequestProcessorRegistry.removeProcessorFor(CONSOLE_LOG.requestName()); } }
private Builder createPluggableFetchTaskBuilder(FetchPluggableArtifactTask task, Pipeline pipeline, JobIdentifier fetchFrom, Builder cancelBuilder, ChecksumFileHandler checksumHandler) { final ArtifactStore artifactStore = getArtifactStoreFor(task, fetchFrom); final String fileName = format("%s.json", artifactStore.getPluginId()); final String metadataFileLocationOnServer = format("%s/%s", PLUGGABLE_ARTIFACT_METADATA_FOLDER, fileName); final File metadataFileDest = task.artifactDest(pipeline.getName(), fileName); return new FetchPluggableArtifactBuilder(task.getConditions(), cancelBuilder, task.describe(), fetchFrom, artifactStore, task.getConfiguration(), task.getArtifactId(), metadataFileLocationOnServer, metadataFileDest, checksumHandler); }
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; }
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."); } } }
public void validateExternalArtifactConfig(PluggableArtifactConfig preprocessedPluggableArtifactConfig, ArtifactStore artifactStore, boolean addPluginIdError) { if (preprocessedPluggableArtifactConfig.hasValidPluginAndStore(artifactStore)) { String pluginId = artifactStore.getPluginId(); try { ValidationResult validationResult = artifactExtension.validatePluggableArtifactConfig(pluginId, preprocessedPluggableArtifactConfig.getConfiguration().getConfigurationAsMap(true)); mapErrorsToConfiguration(validationResult, preprocessedPluggableArtifactConfig.getConfiguration(), preprocessedPluggableArtifactConfig); } catch (PluginNotFoundException e) { preprocessedPluggableArtifactConfig.addError("pluginId", String.format("Plugin with id `%s` is not found.", pluginId)); } } else { if (addPluginIdError) { preprocessedPluggableArtifactConfig.addError("pluginId", "Could not determine the plugin to perform the plugin validations. Possible reasons: artifact store does not exist or plugin is not installed."); } } }
@Override protected boolean isSecure(String key) { ArtifactPluginInfo pluginInfo = metadataStore().getPluginInfo(getPluginId()); if (pluginInfo == null || pluginInfo.getStoreConfigSettings() == null || pluginInfo.getStoreConfigSettings().getConfiguration(key) == null) { return false; } return pluginInfo.getStoreConfigSettings().getConfiguration(key).isSecure(); }
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())); } } } }
public static void toJSON(OutputWriter outputWriter, ArtifactStore store) { outputWriter .addLinks(linksWriter -> linksWriter .addLink("self", Routes.ArtifactStoreConfig.id(store.getId())) .addAbsoluteLink("doc", Routes.ArtifactStoreConfig.DOC) .addLink("find", Routes.ArtifactStoreConfig.find())) .add("id", store.getId()) .add("plugin_id", store.getPluginId()) .addChildList("properties", listWriter -> store.forEach(property -> listWriter.addChild(propertyWriter -> ConfigurationPropertyRepresenter.toJSON(propertyWriter, property)))); if (store.hasErrors()) { Map<String, String> fieldMapping = Collections.singletonMap("pluginId", "plugin_id"); outputWriter.addChild("errors", errorWriter -> new ErrorGetter(fieldMapping).toJSON(errorWriter, store)); } }