@PostConstruct public void encryptSecureConfigurations() { if (hasPluginInfo()) { for (ConfigurationProperty configuration : this) { configuration.handleSecureValueConfiguration(isSecure(configuration.getConfigKeyName())); } } }
private void encryptSecureConfigurations(ArtifactStore artifactStore) { if (artifactStore != null && hasPluginInfo(artifactStore)) { for (ConfigurationProperty configuration : getConfiguration()) { configuration.handleSecureValueConfiguration(isSecure(configuration.getConfigKeyName(), artifactStore)); } } }
@PostConstruct public void applyPluginMetadata() { if (taskPreference() != null) { for (ConfigurationProperty configurationProperty : configuration) { if (isValidPluginConfiguration(configurationProperty.getConfigKeyName())) { Boolean isSecure = pluginConfigurationFor(configurationProperty.getConfigKeyName()).getOption(Property.SECURE); configurationProperty.handleSecureValueConfiguration(isSecure); } } } }
@PostConstruct public void applyPluginMetadata() { String pluginId = getPluginId(); for (ConfigurationProperty configurationProperty : configuration) { SCMMetadataStore scmMetadataStore = SCMMetadataStore.getInstance(); if (scmMetadataStore.getConfigurationMetadata(pluginId) != null) { boolean isSecureProperty = scmMetadataStore.hasOption(pluginId, configurationProperty.getConfigurationKey().getName(), SCMConfiguration.SECURE); configurationProperty.handleSecureValueConfiguration(isSecureProperty); } } }
public void applyPackagePluginMetadata(String pluginId) { for (ConfigurationProperty configurationProperty : configuration) { PackageMetadataStore packageMetadataStore = PackageMetadataStore.getInstance(); if (packageMetadataStore.getMetadata(pluginId) != null) { boolean isSecureProperty = packageMetadataStore.hasOption(pluginId, configurationProperty.getConfigurationKey().getName(), PackageConfiguration.SECURE); configurationProperty.handleSecureValueConfiguration(isSecureProperty); } } }
@PostConstruct public void applyPackagePluginMetadata() { String pluginId = pluginConfiguration.getId(); for (ConfigurationProperty configurationProperty : configuration) { RepositoryMetadataStore repositoryMetadataStore = RepositoryMetadataStore.getInstance(); if (repositoryMetadataStore.getMetadata(pluginId) != null) { boolean isSecureProperty = repositoryMetadataStore.hasOption(pluginId, configurationProperty.getConfigurationKey().getName(), PackageConfiguration.SECURE); configurationProperty.handleSecureValueConfiguration(isSecureProperty); } } for (PackageDefinition packageDefinition : packages) { packageDefinition.applyPackagePluginMetadata(pluginId); } }
protected void setPluginConfigurationAttributes(Map attributes) { SCMConfigurations scmConfigurations = SCMMetadataStore.getInstance().getConfigurationMetadata(pluginConfiguration.getId()); if (scmConfigurations == null) { throw new RuntimeException("metadata unavailable for plugin: " + pluginConfiguration.getId()); } for (SCMConfiguration scmConfiguration : scmConfigurations.list()) { String key = scmConfiguration.getKey(); if (attributes.containsKey(key)) { if (configuration.getProperty(key) == null) { configuration.addNewConfiguration(scmConfiguration.getKey(), scmConfiguration.getOption(Property.SECURE)); } configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key))); configuration.getProperty(key).handleSecureValueConfiguration(scmConfiguration.getOption(Property.SECURE)); } } }
@Test public void shouldSetEmptyEncryptedValueWhenValueIsEmptyAndSecure() throws Exception { GoCipher goCipher = mock(GoCipher.class); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), new ConfigurationValue(""), new EncryptedConfigurationValue("old"), goCipher); property.handleSecureValueConfiguration(true); assertThat(property.getEncryptedValue(), is("")); verify(cipher, never()).decrypt(anyString()); }
@Override protected void setTaskConfigAttributes(Map attributes) { TaskConfig taskConfig = PluggableTaskConfigStore.store().preferenceFor(pluginConfiguration.getId()).getConfig(); for (Property property : taskConfig.list()) { String key = property.getKey(); if (attributes.containsKey(key)) { Boolean isSecure = property.getOption(Property.SECURE); if (configuration.getProperty(key) == null) { configuration.addNewConfiguration(property.getKey(), isSecure); } configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key))); configuration.getProperty(key).handleSecureValueConfiguration(isSecure); } } }
private PluggableSCMMaterial createPluggableSCMMaterialWithSecureConfiguration() { PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial(); material.getScmConfig().getConfiguration().get(1).handleSecureValueConfiguration(true); return material; } }
@Test public void shouldNotClearEncryptedValueWhenWhenNewValueNotProvided() { GoCipher goCipher = mock(GoCipher.class); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), null, new EncryptedConfigurationValue("secureValue"), goCipher); property.handleSecureValueConfiguration(true); assertThat(property.isSecure(), is(true)); assertThat(property.getConfigurationKey().getName(), is("secureKey")); assertThat(property.getConfigurationValue(), is(nullValue())); assertThat(property.getEncryptedConfigurationValue(), is(notNullValue())); assertThat(property.getEncryptedValue(), is("secureValue")); }
@Test public void shouldGetEncryptValueWhenConstructedAsSecure() throws CryptoException { GoCipher goCipher = mock(GoCipher.class); String encryptedText = "encryptedValue"; when(goCipher.encrypt("secureValue")).thenReturn(encryptedText); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), new ConfigurationValue("secureValue"), new EncryptedConfigurationValue("old-encrypted-text"), goCipher); property.handleSecureValueConfiguration(true); assertThat(property.isSecure(), is(true)); assertThat(property.getEncryptedValue(), is(encryptedText)); assertThat(property.getConfigurationKey().getName(), is("secureKey")); assertThat(property.getConfigurationValue(), is(nullValue())); }
@Test public void shouldNotEncryptWhenWhenConstructedAsNotSecure() { GoCipher goCipher = mock(GoCipher.class); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), new ConfigurationValue("secureValue"), null, goCipher); property.handleSecureValueConfiguration(false); assertThat(property.isSecure(), is(false)); assertThat(property.getConfigurationKey().getName(), is("secureKey")); assertThat(property.getConfigurationValue().getValue(), is("secureValue")); assertThat(property.getEncryptedConfigurationValue(), is(nullValue())); }
private PackageMaterial createPackageMaterialWithSecureConfiguration() { PackageMaterial material = MaterialsMother.packageMaterial(); material.getPackageDefinition().getRepository().getConfiguration().get(1).handleSecureValueConfiguration(true); material.getPackageDefinition().getConfiguration().addNewConfigurationWithValue("k4", "package-v2", false); material.getPackageDefinition().getConfiguration().get(1).handleSecureValueConfiguration(true); return material; }
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 ConfigurationProperty create(String key, boolean isSecure, String value) { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value), null, new GoCipher()); property.handleSecureValueConfiguration(isSecure); return property; }
private ConfigurationProperty getConfigurationProperty(String key, boolean isSecure, String value) { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value), null, new GoCipher()); property.handleSecureValueConfiguration(isSecure); return property; }
private ConfigurationProperty getConfigurationProperty(String key, boolean isSecure, String value) { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value), null, new GoCipher()); property.handleSecureValueConfiguration(isSecure); return property; }
private Pipeline createPipeline() throws Exception { Pipeline pipeline = PipelineMother.pipelineWithAllTypesOfMaterials("pipeline-name", "stage-name", "job-name", "1"); List<MaterialRevision> materialRevisions = pipeline.getMaterialRevisions().getRevisions(); PackageDefinition packageDefinition = ((PackageMaterial) materialRevisions.get(6).getMaterial()).getPackageDefinition(); packageDefinition.getRepository().getConfiguration().get(1).handleSecureValueConfiguration(true); packageDefinition.getConfiguration().addNewConfigurationWithValue("k4", "package-v2", false); packageDefinition.getConfiguration().get(1).handleSecureValueConfiguration(true); SCM scm = ((PluggableSCMMaterial) materialRevisions.get(7).getMaterial()).getScmConfig(); scm.getConfiguration().get(1).handleSecureValueConfiguration(true); Stage stage = pipeline.getFirstStage(); stage.setId(1L); stage.setPipelineId(1L); stage.setCreatedTime(new Timestamp(getFixedDate().getTime())); stage.setLastTransitionedTime(new Timestamp(getFixedDate().getTime())); JobInstance job = stage.getJobInstances().get(0); job.setScheduledDate(getFixedDate()); job.getTransition(JobState.Completed).setStateChangeTime(getFixedDate()); return pipeline; } }
private Pipeline createPipeline() throws Exception { Pipeline pipeline = PipelineMother.pipelineWithAllTypesOfMaterials("pipeline-name", "stage-name", "job-name", "1"); List<MaterialRevision> materialRevisions = pipeline.getMaterialRevisions().getRevisions(); PackageDefinition packageDefinition = ((PackageMaterial) materialRevisions.get(6).getMaterial()).getPackageDefinition(); packageDefinition.getRepository().getConfiguration().get(1).handleSecureValueConfiguration(true); packageDefinition.getConfiguration().addNewConfigurationWithValue("k4", "package-v2", false); packageDefinition.getConfiguration().get(1).handleSecureValueConfiguration(true); SCM scm = ((PluggableSCMMaterial) materialRevisions.get(7).getMaterial()).getScmConfig(); scm.getConfiguration().get(1).handleSecureValueConfiguration(true); Stage stage = pipeline.getFirstStage(); stage.setId(1L); stage.setPipelineId(1L); stage.setCreatedTime(new Timestamp(getFixedDate().getTime())); stage.setLastTransitionedTime(new Timestamp(getFixedDate().getTime())); JobInstance job = stage.getJobInstances().get(0); job.setScheduledDate(getFixedDate()); job.getTransition(JobState.Assigned).setStateChangeTime(getFixedDate()); job.getTransition(JobState.Completed).setStateChangeTime(getFixedDate()); return pipeline; } }