public Map<String, Map<String, String>> getConfigWithErrorsAsMap() { Map<String, Map<String, String>> configMap = new HashMap<>(); for (ConfigurationProperty property : this) { Map<String, String> mapValue = new HashMap<>(); if (property.isSecure()) { mapValue.put(VALUE_KEY, property.getEncryptedValue()); } else { mapValue.put(VALUE_KEY, property.getConfigurationValue().getValue()); } if (!property.getAllErrors().isEmpty()) { mapValue.put(ERRORS_KEY, StringUtils.join(property.getAllErrors().stream().map(ConfigErrors::getAll).collect(toList()), ", ")); } configMap.put(property.getConfigKeyName(), mapValue); } return configMap; } }
public Map<String, Map<String, Object>> getPropertyMetadataAndValuesAsMap() { Map<String, Map<String, Object>> configMap = new HashMap<>(); for (ConfigurationProperty property : this) { Map<String, Object> mapValue = new HashMap<>(); mapValue.put("isSecure", property.isSecure()); if (property.isSecure()) { mapValue.put(VALUE_KEY, property.getEncryptedValue()); } else { mapValue.put(VALUE_KEY, property.getConfigurationValue().getValue()); } mapValue.put("displayValue", property.getDisplayValue()); configMap.put(property.getConfigKeyName(), mapValue); } return configMap; }
public static List<CRConfigurationProperty> getCrConfigurations(Configuration configuration) { List<CRConfigurationProperty> config = new ArrayList<>(); for (ConfigurationProperty prop : configuration) { String configKeyName = prop.getConfigKeyName(); if (!prop.isSecure()) config.add(new CRConfigurationProperty(configKeyName, prop.getValue(), null)); else { CRConfigurationProperty crProp = new CRConfigurationProperty(configKeyName, null, prop.getEncryptedValue()); config.add(crProp); } } return config; }
public void addConfigurations(PluginInfo pluginInfo, List<ConfigurationProperty> configurationProperties) { settingsMap.clear(); ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurationProperties) { ConfigurationProperty configurationProperty = builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), pluginInfo.isSecure(property.getConfigKeyName())); settingsMap.add(configurationProperty); } }
private List<CRConfigurationProperty> configurationToCRConfiguration(Configuration config) { ArrayList<CRConfigurationProperty> properties = new ArrayList(); if (config != null) { for (ConfigurationProperty p : config) { CRConfigurationProperty crProp = new CRConfigurationProperty(p.getKey().getName()); if (p.isSecure()) crProp.setEncryptedValue(p.getEncryptedValue()); else crProp.setValue(p.getValue()); properties.add(crProp); } } return properties; }
public static void toJSON(OutputWriter writer, ConfigurationProperty configurationProperty) { writer.add("key", configurationProperty.getKey().getName()); if (!configurationProperty.isSecure() && !isBlank(configurationProperty.getConfigValue())) { writer.add("value", configurationProperty.getConfigurationValue().getValue()); } if (configurationProperty.isSecure() && !isBlank(configurationProperty.getEncryptedValue())) { writer.add("encrypted_value", configurationProperty.getEncryptedValue()); } if (configurationProperty.hasErrors()) { writer.addChild("errors", errorWriter -> new ErrorGetter(new LinkedHashMap<String, String>() {{ put("encryptedValue", "encrypted_value"); put("configurationValue", "configuration_value"); put("configurationKey", "configuration_key"); }}).toJSON(errorWriter, configurationProperty)); } }
private void assertConfigProperty(Configuration configuration, String name, String plainTextValue, boolean shouldBeEncrypted) { assertThat(configuration.getProperty(name).getValue(), is(plainTextValue)); if (shouldBeEncrypted) { assertThat(configuration.getProperty(name).getEncryptedValue(), startsWith("AES")); } else { assertThat(configuration.getProperty(name).getEncryptedValue(), is(nullValue())); } } private void assertXsdFailureDuringLoad(String configXML, String... expectedMessages) {
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), isSecure(property.getConfigKeyName()))); } }
@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()); }
@Test public void shouldCreateWithErrorsInPresenceOfEncryptedTextInputForUnSecuredProperty() { Property key = new Property("key"); key.with(Property.SECURE, false); ConfigurationProperty property = new ConfigurationPropertyBuilder().create("key", null, "enc_value", false); assertThat(property.errors().get("encryptedValue").get(0), is("encrypted_value cannot be specified to a unsecured property.")); assertThat(property.getEncryptedValue(), is("enc_value")); }
@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 shouldCreateWithErrorsIfBothPlainAndEncryptedTextInputAreSpecifiedForSecureProperty() { Property key = new Property("key"); key.with(Property.SECURE, true); ConfigurationProperty property = new ConfigurationPropertyBuilder().create("key", "value", "enc_value", true); assertThat(property.errors().get("configurationValue").get(0), is("You may only specify `value` or `encrypted_value`, not both!")); assertThat(property.errors().get("encryptedValue").get(0), is("You may only specify `value` or `encrypted_value`, not both!")); assertThat(property.getConfigurationValue().getValue(), is("value")); assertThat(property.getEncryptedValue(), is("enc_value")); }
@Test public void shouldCreateWithErrorsIfBothPlainAndEncryptedTextInputAreSpecifiedForUnSecuredProperty() { Property key = new Property("key"); key.with(Property.SECURE, false); ConfigurationProperty property = new ConfigurationPropertyBuilder().create("key", "value", "enc_value", false); assertThat(property.errors().get("configurationValue").get(0), is("You may only specify `value` or `encrypted_value`, not both!")); assertThat(property.errors().get("encryptedValue").get(0), is("You may only specify `value` or `encrypted_value`, not both!")); assertThat(property.getConfigurationValue().getValue(), is("value")); assertThat(property.getEncryptedValue(), is("enc_value")); }
@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())); }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { if(isValidPluginConfiguration(property.getConfigKeyName())) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), pluginConfigurationFor(property.getConfigKeyName()).getOption(Property.SECURE))); } else { configuration.add(property); } } }
@Test public void shouldCreateConfigurationPropertyWithEncyrptedValueForSecureProperty() { Property key = new Property("key"); key.with(Property.SECURE, true); ConfigurationProperty property = new ConfigurationPropertyBuilder().create("key", null, "enc_value", true); assertThat(property.getConfigKeyName(), is("key")); assertThat(property.getEncryptedValue(), is("enc_value")); assertNull(property.getConfigurationValue()); }
@Test public void shouldCreateWithEncyrptedValueForOnlyPlainTextInputForSecureProperty() throws Exception { Property key = new Property("key"); key.with(Property.SECURE, true); ConfigurationProperty property = new ConfigurationPropertyBuilder().create("key", "value", null, true); assertThat(property.getConfigKeyName(), is("key")); assertThat(property.getEncryptedValue(), is(new GoCipher().encrypt("value"))); assertNull(property.getConfigurationValue()); }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { RepositoryConfiguration repositoryMetadata = RepositoryMetadataStore.getInstance().getRepositoryMetadata(pluginConfiguration.getId()); if (isValidPluginConfiguration(property.getConfigKeyName(), repositoryMetadata)) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), repositoryPropertyFor(property.getConfigKeyName(), repositoryMetadata).getOption(Property.SECURE))); } else { configuration.add(property); } } }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { SCMConfigurations scmConfigurations = SCMMetadataStore.getInstance().getConfigurationMetadata(getPluginId()); if (isValidPluginConfiguration(property.getConfigKeyName(), scmConfigurations)) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), scmConfigurationFor(property.getConfigKeyName(), scmConfigurations).getOption(SCMConfiguration.SECURE))); } else { configuration.add(property); } } }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { if (doesPluginExist()) { com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageMetadata = PackageMetadataStore.getInstance().getPackageMetadata(pluginId()); if (isValidConfiguration(property.getConfigKeyName(), packageMetadata)) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), packagePropertyFor(property.getConfigKeyName(), packageMetadata).getOption(Property.SECURE))); } else { configuration.add(property); } } else { configuration.add(property); } } }