public void addConfigurations(List<ConfigurationProperty> configurationProperties) { this.getConfiguration().addAll(configurationProperties); } }
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 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."); } } }
private void encryptSecureConfigurations(ArtifactStore artifactStore) { if (artifactStore != null && hasPluginInfo(artifactStore)) { for (ConfigurationProperty configuration : getConfiguration()) { configuration.handleSecureValueConfiguration(isSecure(configuration.getConfigKeyName(), artifactStore)); } } }
Configuration configuration = pluggableArtifactConfig.getConfiguration(); pluggableArtifactConfig.getConfiguration().addNewConfigurationWithValue(configuration.getKey(), String.valueOf(configuration.getValue()), false);
@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); }
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())); }
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())); } }
@Test public void addConfigurations_shouldLeaveUserEnteredValuesAsIsIfArtifactStoreIsNull() throws CryptoException { PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "non-existent-store-id"); ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>(); configurationProperties.add(ConfigurationPropertyMother.create("plain", false, "plain")); configurationProperties.add(ConfigurationPropertyMother.create("secure", true, new GoCipher().encrypt("password"))); pluggableArtifactConfig.addConfigurations(configurationProperties); assertThat(pluggableArtifactConfig.getConfiguration(), is(configurationProperties)); }
@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")); }
@Test public void validate_shouldValidateArtifactPropertiesConfigurationKeyUniqueness() { final ValidationContext validationContext = mock(ValidationContext.class); final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID", create("Foo", false, "Bar"), create("Foo", true, "Bar")); final ArtifactStores artifactStores = mock(ArtifactStores.class); assertFalse(artifactConfig.hasErrors()); when(validationContext.artifactStores()).thenReturn(artifactStores); when(artifactStores.find("Store-ID")).thenReturn(new ArtifactStore("Store-ID", "pluginId")); artifactConfig.validate(validationContext); Configuration configuration = artifactConfig.getConfiguration(); assertThat(configuration.get(0).errors().getAllOn("configurationKey"), is(Arrays.asList("Duplicate key 'Foo' found for Pluggable Artifact"))); assertThat(configuration.get(1).errors().getAllOn("configurationKey"), is(Arrays.asList("Duplicate key 'Foo' found for Pluggable Artifact"))); }
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"))); }
@Test public void addConfigurations_shouldLeaveUserEnteredValuesAsIsIfPluginIsMissing() throws CryptoException { ArtifactMetadataStore.instance().remove("cd.go.s3"); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "storeId"); ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>(); configurationProperties.add(ConfigurationPropertyMother.create("plain", false, "plain")); configurationProperties.add(ConfigurationPropertyMother.create("secure", true, new GoCipher().encrypt("password"))); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("storeId", "cd.go.s3")); pluggableArtifactConfig.addConfigurations(configurationProperties); assertThat(pluggableArtifactConfig.getConfiguration(), is(configurationProperties)); }
@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)); }
PipelineConfig child = config.pipelineConfigByName(new CaseInsensitiveString("child")); Configuration ancestorPublishArtifactConfig = ancestor.getStage("stage1").jobConfigByConfigName("job1").artifactConfigs().getPluggableArtifactConfigs().get(0).getConfiguration(); GoCipher goCipher = new GoCipher(); assertThat(ancestorPublishArtifactConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
PluggableArtifactConfig fromPluggableArtifactConfig = fromPluggableArtifactConfigs.get(i); PluggableArtifactConfig toPluggableArtifactConfig = toPluggableArtifactConfigs.get(i); copyCollectionErrors(fromPluggableArtifactConfig.getConfiguration(), toPluggableArtifactConfig.getConfiguration());
PipelineConfig child = config.pipelineConfigByName(new CaseInsensitiveString("child")); Configuration ancestorPublishArtifactConfig = ancestor.get(0).getJobs().first().artifactConfigs().getPluggableArtifactConfigs().get(0).getConfiguration(); Configuration parentPublishArtifactConfig = parent.get(0).getJobs().first().artifactConfigs().getPluggableArtifactConfigs().get(0).getConfiguration(); Configuration childFetchArtifactFromAncestorConfig = ((FetchPluggableArtifactTask) child.get(0).getJobs().first().tasks().get(0)).getConfiguration(); Configuration childFetchArtifactFromParentConfig = ((FetchPluggableArtifactTask) child.get(0).getJobs().first().tasks().get(1)).getConfiguration();