public List<String> listOfConfigKeys() { ArrayList<String> list = new ArrayList<>(); for (ConfigurationProperty configurationProperty : this) { list.add(configurationProperty.getConfigurationKey().getName()); } return list; }
public void addErrorFor(String key, String message) { for (ConfigurationProperty configurationProperty : this) { if (configurationProperty.getConfigurationKey().getName().equals(key)) { configurationProperty.addErrorAgainstConfigurationValue(message); return; } } }
public String forDisplay(List<ConfigurationProperty> propertiesToDisplay) { ArrayList<String> list = new ArrayList<>(); for (ConfigurationProperty property : propertiesToDisplay) { if (!property.isSecure()) { list.add(format("%s=%s", property.getConfigurationKey().getName().toLowerCase(), property.getConfigurationValue().getValue())); } } return format("[%s]", StringUtils.join(list, ", ")); }
public static List<ConfigurationProperty> getConfigurationPropertiesToBeUsedForDisplay(PluginPreferenceStore metadataStore, String pluginId, final Configuration configuration) { List<ConfigurationProperty> keysForDisplay = new ArrayList<>(); boolean pluginDoesNotExist = !metadataStore.hasPreferenceFor(pluginId); for (ConfigurationProperty property : configuration) { boolean isNotASecureProperty = !property.isSecure(); boolean isPartOfIdentity = metadataStore.hasOption(pluginId, property.getConfigurationKey().getName(), PackageConfiguration.PART_OF_IDENTITY); if (isNotASecureProperty && !StringUtils.isBlank(property.getValue()) && (pluginDoesNotExist || isPartOfIdentity)) { keysForDisplay.add(property); } } return keysForDisplay; } }
private void handleProperty(List<String> list, PackageConfigurations metadata, ConfigurationProperty configurationProperty) { PackageConfiguration packageConfiguration = null; if (metadata != null) { packageConfiguration = metadata.get(configurationProperty.getConfigurationKey().getName()); } if (packageConfiguration == null || packageConfiguration.getOption(PackageConfiguration.PART_OF_IDENTITY)) { list.add(configurationProperty.forFingerprint()); } }
private void handleProperty(List<String> list, SCMConfigurations metadata, ConfigurationProperty configurationProperty) { SCMConfiguration scmConfiguration = null; if (metadata != null) { scmConfiguration = metadata.get(configurationProperty.getConfigurationKey().getName()); } if (scmConfiguration == null || scmConfiguration.getOption(SCMConfiguration.PART_OF_IDENTITY)) { list.add(configurationProperty.forFingerprint()); } }
private void populateConfiguration(Configuration configuration, com.thoughtworks.go.plugin.api.config.Configuration pluginConfiguration) { for (ConfigurationProperty configurationProperty : configuration) { pluginConfiguration.add(new SCMProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } } }
private void populateConfiguration(Configuration configuration, com.thoughtworks.go.plugin.api.config.Configuration pluginConfiguration) { for (ConfigurationProperty configurationProperty : configuration) { pluginConfiguration.add(new PackageMaterialProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } } }
private void populateConfiguration(Configuration configuration, com.thoughtworks.go.plugin.api.config.Configuration pluginConfiguration) { for (ConfigurationProperty configurationProperty : configuration) { pluginConfiguration.add(new PackageMaterialProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } }
private void populateConfiguration(Configuration configuration, com.thoughtworks.go.plugin.api.config.Configuration pluginConfiguration) { for (ConfigurationProperty configurationProperty : configuration) { pluginConfiguration.add(new SCMProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } }
@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); } } }
public TaskConfig toTaskConfig() { TaskConfig taskConfig = new TaskConfig(); for (ConfigurationProperty configurationProperty : configuration) { taskConfig.add(new TaskConfigProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } return taskConfig; }
private RepositoryConfiguration populateConfiguration(Configuration configuration) { RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration(); for (ConfigurationProperty configurationProperty : configuration) { String value = configurationProperty.getValue(); repositoryConfiguration.add(new PackageMaterialProperty(configurationProperty.getConfigurationKey().getName(), value)); } return repositoryConfiguration; } }
private SCMPropertyConfiguration getScmPropertyConfiguration(SCM scmConfig) { final SCMPropertyConfiguration configuration = new SCMPropertyConfiguration(); for (ConfigurationProperty configurationProperty : scmConfig.getConfiguration()) { configuration.add(new SCMProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } return configuration; } }
@Test public void shouldInitializeConfigValueToBlankWhenBothValueAndEncryptedValueIsNull() { ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("key"), (ConfigurationValue) null); configurationProperty.initialize(); assertThat(configurationProperty.getConfigurationKey().getName(), is("key")); assertThat(configurationProperty.getConfigurationValue(), is(notNullValue())); assertThat(configurationProperty.getConfigurationValue().getValue(), is("")); assertThat(configurationProperty.getEncryptedConfigurationValue(), is(nullValue())); Method initializeMethod = ReflectionUtils.findMethod(ConfigurationProperty.class, "initialize"); assertThat(initializeMethod.getAnnotation(PostConstruct.class), is(notNullValue())); }
@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 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())); }
@Test public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception { PackageDefinition packageDefinition = new PackageDefinition(); packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue())); packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue())); packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null)); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null); configurationProperty.addErrorAgainstConfigurationValue("error"); packageDefinition.getConfiguration().add(configurationProperty); packageDefinition.clearEmptyConfigurations(); assertThat(packageDefinition.getConfiguration().size(), is(1)); assertThat(packageDefinition.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four")); }
@Test public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception { SCM scm = new SCM(); scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue())); scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue())); scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null)); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null); configurationProperty.addErrorAgainstConfigurationValue("error"); scm.getConfiguration().add(configurationProperty); scm.clearEmptyConfigurations(); assertThat(scm.getConfiguration().size(), is(1)); assertThat(scm.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four")); }