From dfcd3b17c05da269ad70760b96d746e1b652a72d Mon Sep 17 00:00:00 2001 From: buildmaster Date: Tue, 12 Jan 2021 09:59:54 +0000 Subject: [PATCH] Bumping versions --- .../VaultEncryptionAutoConfiguration.java | 3 +- .../vault/VaultEnvironmentEncryptor.java | 18 ++-- .../PcfClientAuthenticationProvider.java | 9 +- .../server/support/AbstractScmAccessor.java | 1 - .../vault/VaultEnvironmentEncryptorTests.java | 95 ++++++++----------- .../JGitEnvironmentRepositoryTests.java | 34 +++---- 6 files changed, 63 insertions(+), 97 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/VaultEncryptionAutoConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/VaultEncryptionAutoConfiguration.java index 367740d6..bc7f3bad 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/VaultEncryptionAutoConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/VaultEncryptionAutoConfiguration.java @@ -37,8 +37,7 @@ public class VaultEncryptionAutoConfiguration { @Bean public VaultEnvironmentEncryptor vaultEnvironmentEncryptor( SpringVaultEnvironmentRepository vaultEnvironmentRepository) { - return new VaultEnvironmentEncryptor( - vaultEnvironmentRepository.getKeyValueTemplate()); + return new VaultEnvironmentEncryptor(vaultEnvironmentRepository.getKeyValueTemplate()); } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java index 65041ee1..5bb435cd 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java @@ -58,8 +58,7 @@ public class VaultEnvironmentEncryptor implements EnvironmentEncryptor { for (Map.Entry entry : new LinkedHashSet<>(map.entrySet())) { Object key = entry.getKey(); String name = key.toString(); - if (entry.getValue() != null - && entry.getValue().toString().startsWith("{vault}")) { + if (entry.getValue() != null && entry.getValue().toString().startsWith("{vault}")) { String value = entry.getValue().toString(); map.remove(key); try { @@ -81,8 +80,7 @@ public class VaultEnvironmentEncryptor implements EnvironmentEncryptor { throw new RuntimeException("Wrong format"); } - if (StringUtils.isEmpty(parts[0]) - || StringUtils.isEmpty(parts[1])) { + if (StringUtils.isEmpty(parts[0]) || StringUtils.isEmpty(parts[1])) { throw new RuntimeException("Wrong format"); } @@ -95,21 +93,19 @@ public class VaultEnvironmentEncryptor implements EnvironmentEncryptor { VaultResponse vaultResponse = loadedVaultKeys.get(vaultKey); - if (vaultResponse == null - || (vaultResponse.getData() == null || !vaultResponse - .getData().containsKey(vaultParamName))) { + if (vaultResponse == null || (vaultResponse.getData() == null + || !vaultResponse.getData().containsKey(vaultParamName))) { value = null; } else { - value = vaultResponse.getData().get(vaultParamName) - .toString(); + value = vaultResponse.getData().get(vaultParamName).toString(); } } catch (Exception e) { value = ""; name = "invalid." + name; - String message = "Cannot resolve key: " + key + " (" - + e.getClass() + ": " + e.getMessage() + ")"; + String message = "Cannot resolve key: " + key + " (" + e.getClass() + ": " + e.getMessage() + + ")"; if (logger.isDebugEnabled()) { logger.debug(message, e); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java index 6555b83c..ef4bc33f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java @@ -50,16 +50,14 @@ public class PcfClientAuthenticationProvider extends SpringVaultClientAuthentica builder.instanceCertificate(new ResourceCredentialSupplier(pcfProperties.getInstanceCertificate())); } else { - builder.instanceCertificate(new ResourceCredentialSupplier( - resolveEnvVariable("CF_INSTANCE_CERT"))); + builder.instanceCertificate(new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_CERT"))); } if (pcfProperties.getInstanceKey() != null) { builder.instanceKey(new ResourceCredentialSupplier(pcfProperties.getInstanceKey())); } else { - builder.instanceKey(new ResourceCredentialSupplier( - resolveEnvVariable("CF_INSTANCE_KEY"))); + builder.instanceKey(new ResourceCredentialSupplier(resolveEnvVariable("CF_INSTANCE_KEY"))); } return new PcfAuthentication(builder.build(), vaultRestOperations); @@ -70,8 +68,7 @@ public class PcfClientAuthenticationProvider extends SpringVaultClientAuthentica String value = System.getenv(name); if (StringUtils.isEmpty(value)) { - throw new IllegalStateException( - String.format("Environment variable %s not set", name)); + throw new IllegalStateException(String.format("Environment variable %s not set", name)); } return value; diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AbstractScmAccessor.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AbstractScmAccessor.java index aae8163a..341ef4d1 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AbstractScmAccessor.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/AbstractScmAccessor.java @@ -26,7 +26,6 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java index eaa89556..6ea60066 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java @@ -42,20 +42,18 @@ public class VaultEnvironmentEncryptorTests { String secret = "mysecret"; VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - when(keyValueTemplate.get("accounts/mypay")) - .thenReturn(withVaultResponse("access_key", secret)); + when(keyValueTemplate.get("accounts/mypay")).thenReturn(withVaultResponse("access_key", secret)); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", Collections.singletonMap( - environment.getName(), "{vault}:accounts/mypay#access_key"))); + environment.add(new PropertySource("a", + Collections.singletonMap(environment.getName(), "{vault}:accounts/mypay#access_key"))); // then - assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource() - .get(environment.getName())).isEqualTo(secret); + assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName())) + .isEqualTo(secret); } @Test @@ -64,20 +62,18 @@ public class VaultEnvironmentEncryptorTests { String secret = "mysecret"; VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - when(keyValueTemplate.get("accounts/mypay")) - .thenReturn(withVaultResponse("access_key", secret)); + when(keyValueTemplate.get("accounts/mypay")).thenReturn(withVaultResponse("access_key", secret)); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", Collections.singletonMap( - environment.getName(), "{vault}:accounts/mypay#another_key"))); + environment.add(new PropertySource("a", + Collections.singletonMap(environment.getName(), "{vault}:accounts/mypay#another_key"))); // then - assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource() - .get(environment.getName())).isNull(); + assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName())) + .isNull(); } @Test @@ -87,17 +83,16 @@ public class VaultEnvironmentEncryptorTests { VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", - Collections.singletonMap(environment.getName(), value))); + environment + .add(new PropertySource("a", Collections.singletonMap(environment.getName(), value))); // then - assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource() - .get(environment.getName())).isEqualTo(value); + assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName())) + .isEqualTo(value); } @Test @@ -107,21 +102,19 @@ public class VaultEnvironmentEncryptorTests { VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", - Collections.singletonMap(environment.getName(), value))); + environment + .add(new PropertySource("a", Collections.singletonMap(environment.getName(), value))); // then Environment processedEnvironment = encryptor.decrypt(environment); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get(environment.getName())).isNull(); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get("invalid." + environment.getName())).isEqualTo(""); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get(environment.getName())).isNull(); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get("invalid." + environment.getName())) + .isEqualTo(""); } @Test @@ -131,21 +124,19 @@ public class VaultEnvironmentEncryptorTests { VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", - Collections.singletonMap(environment.getName(), value))); + environment + .add(new PropertySource("a", Collections.singletonMap(environment.getName(), value))); // then Environment processedEnvironment = encryptor.decrypt(environment); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get(environment.getName())).isNull(); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get("invalid." + environment.getName())).isEqualTo(""); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get(environment.getName())).isNull(); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get("invalid." + environment.getName())) + .isEqualTo(""); } @Test @@ -155,21 +146,19 @@ public class VaultEnvironmentEncryptorTests { VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", - Collections.singletonMap(environment.getName(), value))); + environment + .add(new PropertySource("a", Collections.singletonMap(environment.getName(), value))); // then Environment processedEnvironment = encryptor.decrypt(environment); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get(environment.getName())).isNull(); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get("invalid." + environment.getName())).isEqualTo(""); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get(environment.getName())).isNull(); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get("invalid." + environment.getName())) + .isEqualTo(""); } @Test @@ -179,21 +168,19 @@ public class VaultEnvironmentEncryptorTests { VaultKeyValueOperations keyValueTemplate = mock(VaultKeyValueOperations.class); - VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor( - keyValueTemplate); + VaultEnvironmentEncryptor encryptor = new VaultEnvironmentEncryptor(keyValueTemplate); // when Environment environment = new Environment("name", "profile", "label"); - environment.add(new PropertySource("a", - Collections.singletonMap(environment.getName(), value))); + environment + .add(new PropertySource("a", Collections.singletonMap(environment.getName(), value))); // then Environment processedEnvironment = encryptor.decrypt(environment); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get(environment.getName())).isNull(); - assertThat(processedEnvironment.getPropertySources().get(0).getSource() - .get("invalid." + environment.getName())).isEqualTo(""); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get(environment.getName())).isNull(); + assertThat(processedEnvironment.getPropertySources().get(0).getSource().get("invalid." + environment.getName())) + .isEqualTo(""); } private VaultResponse withVaultResponse(String key, Object value) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index 5f7493d6..f442739a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -337,11 +337,8 @@ public class JGitEnvironmentRepositoryTests { when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); - when(storedConfig.getString("remote", "origin", "url")) - .thenReturn("http://example/git"); - when(statusCommand.call()) - .thenThrow(new JGitInternalException("Short read of block.")) - .thenReturn(status); + when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); + when(statusCommand.call()).thenThrow(new JGitInternalException("Short read of block.")).thenReturn(status); when(status.isClean()).thenReturn(true); when(git.reset()).thenReturn(resetCommand); when(resetCommand.setMode(any())).thenReturn(resetCommand); @@ -368,10 +365,8 @@ public class JGitEnvironmentRepositoryTests { when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); - when(storedConfig.getString("remote", "origin", "url")) - .thenReturn("http://example/git"); - when(statusCommand.call()) - .thenThrow(new JGitInternalException("Short read of block.")); + when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); + when(statusCommand.call()).thenThrow(new JGitInternalException("Short read of block.")); when(status.isClean()).thenReturn(true); JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment, @@ -383,8 +378,7 @@ public class JGitEnvironmentRepositoryTests { assertThat(shouldPull).as("shouldPull did not fail").isFalse(); } catch (JGitInternalException e) { - assertThat(e.getMessage()).as("shouldPull did not fail as expected") - .isEqualTo("Short read of block."); + assertThat(e.getMessage()).as("shouldPull did not fail as expected").isEqualTo("Short read of block."); } } @@ -402,10 +396,8 @@ public class JGitEnvironmentRepositoryTests { when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); - when(storedConfig.getString("remote", "origin", "url")) - .thenReturn("http://example/git"); - when(statusCommand.call()).thenThrow(new JGitInternalException(mockThrownMessage)) - .thenReturn(status); + when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); + when(statusCommand.call()).thenThrow(new JGitInternalException(mockThrownMessage)).thenReturn(status); when(status.isClean()).thenReturn(true); when(git.reset()).thenReturn(resetCommand); when(resetCommand.call()).thenThrow(new GitAPIException("") { @@ -419,8 +411,7 @@ public class JGitEnvironmentRepositoryTests { Assertions.fail("shouldPull did not fail"); } catch (JGitInternalException e) { - assertThat(e.getMessage()).as("shouldPull did not fail as expected") - .isEqualTo(mockThrownMessage); + assertThat(e.getMessage()).as("shouldPull did not fail as expected").isEqualTo(mockThrownMessage); } } @@ -437,10 +428,8 @@ public class JGitEnvironmentRepositoryTests { when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); - when(storedConfig.getString("remote", "origin", "url")) - .thenReturn("http://example/git"); - when(statusCommand.call()) - .thenThrow(new JGitInternalException(mockThrownMessage)); + when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); + when(statusCommand.call()).thenThrow(new JGitInternalException(mockThrownMessage)); when(status.isClean()).thenReturn(true); JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment, @@ -451,8 +440,7 @@ public class JGitEnvironmentRepositoryTests { Assertions.fail("shouldPull did not fail"); } catch (JGitInternalException e) { - assertThat(e.getMessage()).as("shouldPull did not fail as expected") - .isEqualTo(mockThrownMessage); + assertThat(e.getMessage()).as("shouldPull did not fail as expected").isEqualTo(mockThrownMessage); } }