diff --git a/README.md b/README.md index ef1b998..65237c7 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ adds it to the existing ConfigurationManager. private final Logger logger = LoggerFactory.getLogger(getClass()); private static final String SECRETS_PATH_PROP_NAME = "cerberus.config.path"; - private static final String SECRETS_DEFAULT_VAULT_PATH = "app/cerberus-demo/config"; + private static final String SECRETS_DEFAULT_CERBERUS_PATH = "app/cerberus-demo/config"; @Override protected void configure() { @@ -68,15 +68,15 @@ adds it to the existing ConfigurationManager. * First let's look up the path for where to read in Cerberus. * This examples show us attempting to source it from an Archaius property, but defaulting if not found. */ - final String vaultPath = DynamicPropertyFactory.getInstance() - .getStringProperty(SECRETS_PATH_PROP_NAME, SECRETS_DEFAULT_VAULT_PATH) + final String cerberusPath = DynamicPropertyFactory.getInstance() + .getStringProperty(SECRETS_PATH_PROP_NAME, SECRETS_DEFAULT_CERBERUS_PATH) .get(); /* * So long as we've got a path, let's pull the config into Archaius from Cerberus. */ - if (vaultPath != null && !vaultPath.isEmpty()) { - logger.info("Adding Cerberus as Configuration source. Vault Path = " + vaultPath); + if (cerberusPath != null && !cerberusPath.isEmpty()) { + logger.info("Adding Cerberus as Configuration source. Cerberus Path = " + cerberusPath); /* * Create a configuration source passing in a Cerberus client using the ArchaiusCerberusClientFactory and @@ -84,7 +84,7 @@ adds it to the existing ConfigurationManager. * like the URL and token from Archaius properties. */ final NamespacedCerberusConfigurationSource namespacedCerberusConfigurationSource = new NamespacedCerberusConfigurationSource( - ArchaiusCerberusClientFactory.getClient(), vaultPath); + ArchaiusCerberusClientFactory.getClient(), cerberusPath); /* * Read secrets from Cerberus. @@ -101,7 +101,7 @@ adds it to the existing ConfigurationManager. configInstance.addConfiguration(cerberusConfig); } else { - logger.info("Property corresponding to the Vault path for secrets not found! " + logger.info("Property corresponding to the Cerberus path for secrets not found! " + "Cerberus not added as Configuration source"); } } @@ -122,7 +122,7 @@ adds it to the existing ConfigurationManager. private static final int POLL_INIT_DELAY = 1000; private static final int SECRETS_POLL_INTERVAL = (int) TimeUnit.HOURS.toMillis(1); private static final String SECRETS_PATH_PROP_NAME = "cerberus.config.path"; - private static final String SECRETS_DEFAULT_VAULT_PATH = "app/cerberus-demo/config"; + private static final String SECRETS_DEFAULT_CERBERUS_PATH = "app/cerberus-demo/config"; @Override protected void configure() { @@ -130,15 +130,15 @@ adds it to the existing ConfigurationManager. * First let's look up the path for where to read in Cerberus. * This examples show us attempting to source it from an Archaius property, but defaulting if not found. */ - final String vaultPath = DynamicPropertyFactory.getInstance() - .getStringProperty(SECRETS_PATH_PROP_NAME, SECRETS_DEFAULT_VAULT_PATH) + final String cerberusPath = DynamicPropertyFactory.getInstance() + .getStringProperty(SECRETS_PATH_PROP_NAME, SECRETS_DEFAULT_CERBERUS_PATH) .get(); /* * So long as we've got a path, let's configure the polling of config from Cerberus into Archaius. */ - if (vaultPath != null && !vaultPath.isEmpty()) { - logger.info("Adding Cerberus as Configuration source. Vault Path = " + vaultPath); + if (cerberusPath != null && !cerberusPath.isEmpty()) { + logger.info("Adding Cerberus as Configuration source. Cerberus Path = " + cerberusPath); /* * Create a configuration source passing in a Cerberus client using the ArchaiusCerberusClientFactory and @@ -146,7 +146,7 @@ adds it to the existing ConfigurationManager. * like the URL and token from Archaius properties. */ final PolledConfigurationSource polledConfigurationSource = new NamespacedCerberusConfigurationSource( - ArchaiusCerberusClientFactory.getClient(), vaultPath); + ArchaiusCerberusClientFactory.getClient(), cerberusPath); /* * Setup the scheduler for how often this configuration source should be refreshed. @@ -165,7 +165,7 @@ adds it to the existing ConfigurationManager. configInstance.addConfiguration(cerberusConfig); } else { - logger.info("Property corresponding to the Vault path for secrets not found! " + logger.info("Property corresponding to the Cerberus path for secrets not found! " + "Cerberus not added as Configuration source"); } } @@ -188,7 +188,7 @@ The code snippet shown below is an example of how this can be done. private static final int POLL_INIT_DELAY = 1000; private static final int SECRETS_POLL_INTERVAL = (int) TimeUnit.HOURS.toMillis(1); private static final String SECRETS_PATH_PROP_NAME = "cerberus.config.path"; - private static final String SECRETS_DEFAULT_VAULT_PATH = "app/cerberus-demo/config"; + private static final String SECRETS_DEFAULT_CERBERUS_PATH = "app/cerberus-demo/config"; @Override protected void configure() { @@ -196,15 +196,15 @@ The code snippet shown below is an example of how this can be done. * First let's look up the path for where to read in Cerberus. * This examples show us attempting to source it from an Archaius property, but defaulting if not found. */ - final String vaultPath = DynamicPropertyFactory.getInstance() - .getStringProperty(SECRETS_PATH_PROP_NAME, SECRETS_DEFAULT_VAULT_PATH) + final String cerberusPath = DynamicPropertyFactory.getInstance() + .getStringProperty(SECRETS_PATH_PROP_NAME, SECRETS_DEFAULT_CERBERUS_PATH) .get(); /* * So long as we've got a path, let's configure the polling of config from Cerberus into Archaius. */ - if (vaultPath != null && !vaultPath.isEmpty()) { - logger.info("Adding Cerberus as Configuration source. Vault Path = " + vaultPath); + if (cerberusPath != null && !cerberusPath.isEmpty()) { + logger.info("Adding Cerberus as Configuration source. Cerberus Path = " + cerberusPath); /* * Create a configuration source passing in a Cerberus client using the ArchaiusCerberusClientFactory and @@ -212,7 +212,7 @@ The code snippet shown below is an example of how this can be done. * like the URL and token from Archaius properties. */ final PolledConfigurationSource polledConfigurationSource = new NamespacedCerberusConfigurationSource( - ArchaiusCerberusClientFactory.getClient(), vaultPath); + ArchaiusCerberusClientFactory.getClient(), cerberusPath); /* * Setup the scheduler for how often this configuration source should be refreshed. @@ -233,7 +233,7 @@ The code snippet shown below is an example of how this can be done. .annotatedWith(Names.named("cerberus.config")) .toInstance(cerberusConfig); } else { - logger.info("Property corresponding to the Vault path for secrets not found! " + logger.info("Property corresponding to the Cerberus path for secrets not found! " + "Cerberus not added as Configuration source"); } } diff --git a/gradle.properties b/gradle.properties index e8e1bea..f038857 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ # limitations under the License. # -version=5.2.0 +version=6.0.0 groupId=com.nike artifactId=cerberus-archaius-client diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 563d95b..9aa0e2a 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -23,7 +23,7 @@ repositories { dependencies { compile 'com.netflix.archaius:archaius-aws:0.6.5' - compile 'com.nike:cerberus-client:4.3.0' + compile 'com.nike:cerberus-client:5.1.0' compile "org.apache.commons:commons-lang3:3.5" compile "com.squareup.okhttp3:okhttp:3.9.0" diff --git a/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactory.java b/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactory.java index cc1bfe6..fdf4064 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactory.java +++ b/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactory.java @@ -17,8 +17,8 @@ package com.nike.cerberus.archaius.client; import com.nike.cerberus.client.auth.DefaultCerberusCredentialsProviderChain; -import com.nike.vault.client.VaultClient; -import com.nike.vault.client.VaultClientFactory; +import com.nike.cerberus.client.CerberusClient; +import com.nike.cerberus.client.CerberusClientFactory; import java.util.HashMap; import java.util.Map; @@ -29,19 +29,19 @@ public class ArchaiusCerberusClientFactory { /** - * Resolves the Vault/Cerberus URL via the {@link ArchaiusCerberusUrlResolver} and creates a new {@link VaultClient} + * Resolves the Cerberus/Cerberus URL via the {@link ArchaiusCerberusUrlResolver} and creates a new {@link CerberusClient} * with the {@link DefaultCerberusCredentialsProviderChain}. * - * @return Vault client + * @return Cerberus client */ - public static VaultClient getClient() { + public static CerberusClient getClient() { final ArchaiusCerberusUrlResolver archaiusUrlResolver = new ArchaiusCerberusUrlResolver(); final Map defaultHeaders = new HashMap<>(); final String xCerberusClientHeaderValue = ClientVersion.getClientHeaderValue(); defaultHeaders.put(ClientVersion.CERBERUS_CLIENT_HEADER, xCerberusClientHeaderValue); - return VaultClientFactory.getClient( + return CerberusClientFactory.getClient( archaiusUrlResolver, // pass the client HTTP header value to be used in authenticate calls to Cerberus new DefaultCerberusCredentialsProviderChain(archaiusUrlResolver, xCerberusClientHeaderValue), diff --git a/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java b/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java index 12ef89c..89b38af 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java +++ b/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import com.netflix.config.ConfigurationManager; -import com.nike.vault.client.UrlResolver; +import com.nike.cerberus.client.UrlResolver; /** * Class for resolving the Cerberus URL via Archaius. @@ -40,9 +40,9 @@ public class ArchaiusCerberusUrlResolver implements UrlResolver { private final Logger logger = LoggerFactory.getLogger(getClass()); /** - * Attempts to acquire the Vault URL from Archaius. + * Attempts to acquire the Cerberus URL from Archaius. * - * @return Vault URL + * @return Cerberus URL */ @Nullable @Override diff --git a/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java b/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java index 81b3743..c189c28 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java +++ b/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java @@ -18,7 +18,7 @@ import com.google.common.collect.Sets; import com.netflix.config.PolledConfigurationSource; -import com.nike.vault.client.VaultClient; +import com.nike.cerberus.client.CerberusClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +29,7 @@ */ public abstract class BaseCerberusConfigurationSource implements PolledConfigurationSource { - private final VaultClient vaultClient; + private final CerberusClient cerberusClient; private final Set paths; @@ -38,19 +38,19 @@ public abstract class BaseCerberusConfigurationSource implements PolledConfigura /** * Constructor that accepts a Set<String> for paths. * - * @param vaultClient Instance of {@link VaultClient} - * @param paths Set<String> containing vault paths where configuration is stored - * @throws IllegalArgumentException if vaultClient is null or if paths is null/empty + * @param cerberusClient Instance of {@link CerberusClient} + * @param paths Set<String> containing cerberus paths where configuration is stored + * @throws IllegalArgumentException if cerberusClient is null or if paths is null/empty */ - public BaseCerberusConfigurationSource(VaultClient vaultClient, Set paths) { + public BaseCerberusConfigurationSource(CerberusClient cerberusClient, Set paths) { super(); - if (vaultClient == null) { - throw new IllegalArgumentException("vaultClient cannot be null"); + if (cerberusClient == null) { + throw new IllegalArgumentException("cerberusClient cannot be null"); } if (paths == null || paths.isEmpty()) { throw new IllegalArgumentException("paths cannot be null or empty"); } - this.vaultClient = vaultClient; + this.cerberusClient = cerberusClient; this.paths = Sets.newHashSet(paths); logger.info("paths={}", getPaths()); } @@ -58,25 +58,25 @@ public BaseCerberusConfigurationSource(VaultClient vaultClient, Set path /** * Constructor that accepts var args for paths. * - * @param vaultClient Instance of {@link VaultClient} - * @param paths one or more vault paths where configuration is stored - * @throws IllegalArgumentException if vaultClient is null or if paths is null/empty + * @param cerberusClient Instance of {@link CerberusClient} + * @param paths one or more cerberus paths where configuration is stored + * @throws IllegalArgumentException if cerberusClient is null or if paths is null/empty */ - public BaseCerberusConfigurationSource(VaultClient vaultClient, String... paths) { + public BaseCerberusConfigurationSource(CerberusClient cerberusClient, String... paths) { super(); - if (vaultClient == null) { - throw new IllegalArgumentException("vaultClient cannot be null"); + if (cerberusClient == null) { + throw new IllegalArgumentException("cerberusClient cannot be null"); } if (paths == null || paths.length == 0) { throw new IllegalArgumentException("paths cannot be null or empty"); } - this.vaultClient = vaultClient; + this.cerberusClient = cerberusClient; this.paths = Sets.newHashSet(paths); logger.info("paths={}", getPaths()); } - public VaultClient getVaultClient() { - return vaultClient; + public CerberusClient getCerberusClient() { + return cerberusClient; } public Set getPaths() { diff --git a/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java b/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java index 7155254..625abf5 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java +++ b/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java @@ -20,8 +20,8 @@ import com.netflix.config.ConcurrentMapConfiguration; import com.netflix.config.PollResult; import com.netflix.config.PolledConfigurationSource; -import com.nike.vault.client.VaultClient; -import com.nike.vault.client.model.VaultResponse; +import com.nike.cerberus.client.CerberusClient; +import com.nike.cerberus.client.model.CerberusResponse; import org.apache.commons.configuration.AbstractConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,23 +40,23 @@ public class CerberusConfigurationSource extends BaseCerberusConfigurationSource /** * Constructor that accepts a Set<String> for paths. * - * @param vaultClient Instance of {@link VaultClient} - * @param paths Set<String> containing vault paths where configuration is stored - * @throws IllegalArgumentException if vaultClient is null or if paths is null/empty + * @param cerberusClient Instance of {@link CerberusClient} + * @param paths Set<String> containing cerberus paths where configuration is stored + * @throws IllegalArgumentException if cerberusClient is null or if paths is null/empty */ - public CerberusConfigurationSource(final VaultClient vaultClient, final Set paths) { - super(vaultClient, paths); + public CerberusConfigurationSource(final CerberusClient cerberusClient, final Set paths) { + super(cerberusClient, paths); } /** * Constructor that accepts var args for paths. * - * @param vaultClient Instance of {@link VaultClient} - * @param paths one or more vault paths where configuration is stored - * @throws IllegalArgumentException if vaultClient is null or if paths is null/empty + * @param cerberusClient Instance of {@link CerberusClient} + * @param paths one or more cerberus paths where configuration is stored + * @throws IllegalArgumentException if cerberusClient is null or if paths is null/empty */ - public CerberusConfigurationSource(final VaultClient vaultClient, final String... paths) { - super(vaultClient, paths); + public CerberusConfigurationSource(final CerberusClient cerberusClient, final String... paths) { + super(cerberusClient, paths); } /** @@ -81,9 +81,9 @@ public AbstractConfiguration getConfig(){ private Map getMap() { final Map config = Maps.newHashMap(); for (final String path : getPaths()) { - logger.debug("poll: reading vault path '{}'...", path); - final VaultResponse vaultResponse = getVaultClient().read(path); - config.putAll(vaultResponse.getData()); + logger.debug("poll: reading cerberus path '{}'...", path); + final CerberusResponse cerberusResponse = getCerberusClient().read(path); + config.putAll(cerberusResponse.getData()); } return config; } diff --git a/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java b/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java index 47f7036..7145b5c 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java +++ b/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java @@ -20,9 +20,9 @@ import com.netflix.config.ConcurrentMapConfiguration; import com.netflix.config.PollResult; import com.netflix.config.PolledConfigurationSource; -import com.nike.vault.client.VaultClient; -import com.nike.vault.client.model.VaultListResponse; -import com.nike.vault.client.model.VaultResponse; +import com.nike.cerberus.client.CerberusClient; +import com.nike.cerberus.client.model.CerberusListResponse; +import com.nike.cerberus.client.model.CerberusResponse; import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -46,22 +46,22 @@ public class NamespacedCerberusConfigurationSource extends BaseCerberusConfigura /** * Constructor that accepts a Set<String> for paths - * @param vaultClient An already configured vault client. May not be null. - * @param paths Set containing vault paths where configuration is stored. May not be null. - * @throws IllegalArgumentException if vaultClient is null or if paths is null/empty + * @param cerberusClient An already configured cerberus client. May not be null. + * @param paths Set containing cerberus paths where configuration is stored. May not be null. + * @throws IllegalArgumentException if cerberusClient is null or if paths is null/empty */ - public NamespacedCerberusConfigurationSource(final VaultClient vaultClient, final Set paths) { - super(vaultClient, paths); + public NamespacedCerberusConfigurationSource(final CerberusClient cerberusClient, final Set paths) { + super(cerberusClient, paths); } /** * Constructor that accepts var args for paths - * @param vaultClient An already configured vault client. May not be null. - * @param paths One or more vault paths where configuration is stored. May not be null. - * @throws IllegalArgumentException If vaultClient is null or if paths is null/empty + * @param cerberusClient An already configured cerberus client. May not be null. + * @param paths One or more cerberus paths where configuration is stored. May not be null. + * @throws IllegalArgumentException If cerberusClient is null or if paths is null/empty */ - public NamespacedCerberusConfigurationSource(final VaultClient vaultClient, final String... paths) { - super(vaultClient, paths); + public NamespacedCerberusConfigurationSource(final CerberusClient cerberusClient, final String... paths) { + super(cerberusClient, paths); } /** @@ -84,13 +84,13 @@ public AbstractConfiguration getConfig() { } /** - * Returns true if a path meets the definition of a folder according to vault's convention (e.g. path ends with a + * Returns true if a path meets the definition of a folder according to cerberus's convention (e.g. path ends with a * forward slash). * - * See https://www.vaultproject.io/docs/secrets/generic/index.html under the List API documentation for details as - * to Vault's convention + * See https://www.cerberusproject.io/docs/secrets/generic/index.html under the List API documentation for details as + * to Cerberus's convention * - * @param path - The vault path we are checking to determine if it is a folder or a leaf. + * @param path - The cerberus path we are checking to determine if it is a folder or a leaf. * @return A boolean value, true if the path is a folder. */ private boolean isFolder(final String path) { @@ -116,7 +116,7 @@ private String getPathPrefix(final String path) { } /** - * Traverses the vault path from the provided path down through it's leaves. Places all properties into the map that + * Traverses the cerberus path from the provided path down through it's leaves. Places all properties into the map that * will be used to populate the Archaius configuration. * * @param path - The parent path, all properties under this path will be populated. @@ -125,15 +125,15 @@ private String getPathPrefix(final String path) { private Map buildEntriesMap(final String path) { final Map config = Maps.newHashMap(); if (isFolder(path)) { - final VaultListResponse listResponse = getVaultClient().list(path); + final CerberusListResponse listResponse = getCerberusClient().list(path); for(final String subpath : listResponse.getKeys()) { final String fullPath = path + subpath; config.putAll(buildEntriesMap(fullPath)); } } else { - final VaultResponse vaultResponse = getVaultClient().read(path); - final Map dataFromVault = vaultResponse.getData(); - for (final Map.Entry pair : dataFromVault.entrySet()) { + final CerberusResponse cerberusResponse = getCerberusClient().read(path); + final Map dataFromCerberus = cerberusResponse.getData(); + for (final Map.Entry pair : dataFromCerberus.entrySet()) { config.put(getPathPrefix(path) + pair.getKey(), pair.getValue()); } } @@ -143,7 +143,7 @@ private Map buildEntriesMap(final String path) { private Map getMap() { final Map config = Maps.newHashMap(); for (final String path : getPaths()) { - logger.debug("poll: reading vault path '{}'...", path); + logger.debug("poll: reading cerberus path '{}'...", path); config.putAll(buildEntriesMap(path)); } return config; diff --git a/src/test/java/com/nike/cerberus/archaius/client/ClientVersionTest.java b/src/test/java/com/nike/cerberus/archaius/client/ClientVersionTest.java index 866ed21..a18c8a8 100644 --- a/src/test/java/com/nike/cerberus/archaius/client/ClientVersionTest.java +++ b/src/test/java/com/nike/cerberus/archaius/client/ClientVersionTest.java @@ -43,6 +43,5 @@ public void test_that_header_value_includes_right_prefix() { String result = ClientVersion.getClientHeaderValue(); assertTrue(StringUtils.contains(result, ClientVersion.HEADER_VALUE_PREFIX)); assertTrue(StringUtils.contains(result, com.nike.cerberus.client.ClientVersion.getVersion())); - assertTrue(StringUtils.contains(result, com.nike.vault.client.ClientVersion.getVersion())); } } \ No newline at end of file diff --git a/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java b/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java index 4bd203e..d0dfd0d 100644 --- a/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java +++ b/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java @@ -20,9 +20,9 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.netflix.config.PollResult; -import com.nike.vault.client.VaultClient; -import com.nike.vault.client.VaultServerException; -import com.nike.vault.client.model.VaultResponse; +import com.nike.cerberus.client.CerberusClient; +import com.nike.cerberus.client.CerberusServerException; +import com.nike.cerberus.client.model.CerberusResponse; import org.apache.commons.configuration.AbstractConfiguration; import org.junit.Before; import org.junit.Test; @@ -41,7 +41,7 @@ public class CerberusConfigurationSourceTest { private CerberusConfigurationSource subject; - private VaultClient vaultClient; + private CerberusClient cerberusClient; private static final String PATH_1 = "app/foobinator/config"; @@ -57,8 +57,8 @@ public class CerberusConfigurationSourceTest { @Before public void setup(){ - vaultClient = mock(VaultClient.class); - subject = new CerberusConfigurationSource(vaultClient, PATH_1, PATH_2); + cerberusClient = mock(CerberusClient.class); + subject = new CerberusConfigurationSource(cerberusClient, PATH_1, PATH_2); } @Test @@ -70,11 +70,11 @@ public void poll_loads_both_paths_successfully() { final Map artemisMap = Maps.newHashMap(); artemisMap.put(ARTEMIS_CONFIG_KEY, ARTEMIS_CONFIG_VALUE); - final VaultResponse foobinatorResponse = new VaultResponse().setData(foobinatorMap); - final VaultResponse artemisResponse = new VaultResponse().setData(artemisMap); + final CerberusResponse foobinatorResponse = new CerberusResponse().setData(foobinatorMap); + final CerberusResponse artemisResponse = new CerberusResponse().setData(artemisMap); - when(vaultClient.read(PATH_1)).thenReturn(foobinatorResponse); - when(vaultClient.read(PATH_2)).thenReturn(artemisResponse); + when(cerberusClient.read(PATH_1)).thenReturn(foobinatorResponse); + when(cerberusClient.read(PATH_2)).thenReturn(artemisResponse); // call the method under test PollResult result = subject.poll(true, null); @@ -91,33 +91,33 @@ public void poll_loads_both_paths_successfully() { assertThat(config.getString(FOOBINATOR_CONFIG_KEY)).isEqualTo(FOOBINATOR_CONFIG_VALUE); } - @Test(expected = VaultServerException.class) + @Test(expected = CerberusServerException.class) public void poll_only_loads_data_for_path1() { // mock dependencies final Map foobinatorMap = Maps.newHashMap(); foobinatorMap.put(FOOBINATOR_CONFIG_KEY, FOOBINATOR_CONFIG_VALUE); - final VaultResponse foobinatorResponse = new VaultResponse().setData(foobinatorMap); - when(vaultClient.read(PATH_1)).thenReturn(foobinatorResponse); + final CerberusResponse foobinatorResponse = new CerberusResponse().setData(foobinatorMap); + when(cerberusClient.read(PATH_1)).thenReturn(foobinatorResponse); - when(vaultClient.read(PATH_2)).thenThrow(new VaultServerException(500, Lists.newArrayList("Internal error."))); + when(cerberusClient.read(PATH_2)).thenThrow(new CerberusServerException(500, Lists.newArrayList("Internal error."))); // call the method under test subject.poll(true, null); } @Test(expected = IllegalArgumentException.class) - public void test_constructor_validation_vault_client_cannot_be_null() { + public void test_constructor_validation_cerberus_client_cannot_be_null() { new CerberusConfigurationSource(null, Sets.newHashSet("/fake/path")); } @Test(expected = IllegalArgumentException.class) public void test_constructor_validation_paths_cannot_be_null() { - new CerberusConfigurationSource(vaultClient, (Set)null ); + new CerberusConfigurationSource(cerberusClient, (Set)null ); } @Test(expected = IllegalArgumentException.class) public void test_constructor_validation_paths_cannot_be_empty() { - new CerberusConfigurationSource(vaultClient, Sets.newHashSet()); + new CerberusConfigurationSource(cerberusClient, Sets.newHashSet()); } } diff --git a/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java b/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java index 0a39845..3aabbde 100644 --- a/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java +++ b/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java @@ -17,10 +17,10 @@ package com.nike.cerberus.archaius.client.provider; import com.netflix.config.PollResult; -import com.nike.vault.client.VaultClient; -import com.nike.vault.client.VaultServerException; -import com.nike.vault.client.model.VaultListResponse; -import com.nike.vault.client.model.VaultResponse; +import com.nike.cerberus.client.CerberusClient; +import com.nike.cerberus.client.CerberusServerException; +import com.nike.cerberus.client.model.CerberusListResponse; +import com.nike.cerberus.client.model.CerberusResponse; import org.apache.commons.configuration.AbstractConfiguration; import org.junit.Before; import org.junit.Test; @@ -40,7 +40,7 @@ public class NamespacedCerberusConfigurationSourceTest { private NamespacedCerberusConfigurationSource subject; - private VaultClient vaultClient; + private CerberusClient cerberusClient; private static final String PATH_1 = "app/foobinator/"; @@ -66,31 +66,31 @@ public class NamespacedCerberusConfigurationSourceTest { @Before public void setup(){ - vaultClient = mock(VaultClient.class); - subject = new NamespacedCerberusConfigurationSource(vaultClient, PATH_1, PATH_2); + cerberusClient = mock(CerberusClient.class); + subject = new NamespacedCerberusConfigurationSource(cerberusClient, PATH_1, PATH_2); } @Test public void poll_successfully_reads_all_paths() { // mock dependencies - final VaultListResponse path1ListResponse = new VaultListResponse() + final CerberusListResponse path1ListResponse = new CerberusListResponse() .setKeys(Collections.singletonList(PATH_1_SUBPATH_1)); - when(vaultClient.list(PATH_1)).thenReturn(path1ListResponse); + when(cerberusClient.list(PATH_1)).thenReturn(path1ListResponse); final Map path1Map = new HashMap<>(); path1Map.put(FOOBINATOR_CONFIG_KEY, FOOBINATOR_CONFIG_VALUE); - final VaultResponse path1Response = new VaultResponse().setData(path1Map); - when(vaultClient.read(PATH_1 + PATH_1_SUBPATH_1)).thenReturn(path1Response); + final CerberusResponse path1Response = new CerberusResponse().setData(path1Map); + when(cerberusClient.read(PATH_1 + PATH_1_SUBPATH_1)).thenReturn(path1Response); - final VaultListResponse path2FirstListResponse = new VaultListResponse() + final CerberusListResponse path2FirstListResponse = new CerberusListResponse() .setKeys(Collections.singletonList(PATH_2_SUBPATH_1)); - when(vaultClient.list(PATH_2)).thenReturn(path2FirstListResponse); - final VaultListResponse path2SecondListResponse = new VaultListResponse() + when(cerberusClient.list(PATH_2)).thenReturn(path2FirstListResponse); + final CerberusListResponse path2SecondListResponse = new CerberusListResponse() .setKeys(Collections.singletonList(PATH_2_SUBPATH_2)); - when(vaultClient.list(PATH_2 + PATH_2_SUBPATH_1)).thenReturn(path2SecondListResponse); + when(cerberusClient.list(PATH_2 + PATH_2_SUBPATH_1)).thenReturn(path2SecondListResponse); final Map path2Map = new HashMap<>(); path2Map.put(ARTEMIS_CONFIG_KEY, ARTEMIS_CONFIG_VALUE); - final VaultResponse path2Response = new VaultResponse().setData(path2Map); - when(vaultClient.read(PATH_2 + PATH_2_SUBPATH_1 + PATH_2_SUBPATH_2)).thenReturn(path2Response); + final CerberusResponse path2Response = new CerberusResponse().setData(path2Map); + when(cerberusClient.read(PATH_2 + PATH_2_SUBPATH_1 + PATH_2_SUBPATH_2)).thenReturn(path2Response); // call the method under test PollResult result = subject.poll(true, null); @@ -107,25 +107,25 @@ public void poll_successfully_reads_all_paths() { assertThat(config.getString(FOOBINATOR_CONFIG_NAMESPACED_KEY)).isEqualTo(FOOBINATOR_CONFIG_VALUE); } - @Test(expected = VaultServerException.class) + @Test(expected = CerberusServerException.class) public void poll_fails_to_read_path1_but_is_successful_on_path2() { // mock dependencies to ensure an error - final VaultListResponse path1ListResponse = new VaultListResponse() + final CerberusListResponse path1ListResponse = new CerberusListResponse() .setKeys(Collections.singletonList(PATH_1_SUBPATH_1)); - when(vaultClient.list(PATH_1)).thenReturn(path1ListResponse); - when(vaultClient.read(PATH_1 + PATH_1_SUBPATH_1)) - .thenThrow(new VaultServerException(500, Collections.singletonList("Internal error."))); + when(cerberusClient.list(PATH_1)).thenReturn(path1ListResponse); + when(cerberusClient.read(PATH_1 + PATH_1_SUBPATH_1)) + .thenThrow(new CerberusServerException(500, Collections.singletonList("Internal error."))); - final VaultListResponse path2FirstListResponse = new VaultListResponse() + final CerberusListResponse path2FirstListResponse = new CerberusListResponse() .setKeys(Collections.singletonList(PATH_2_SUBPATH_1)); - when(vaultClient.list(PATH_2)).thenReturn(path2FirstListResponse); - final VaultListResponse path2SecondListResponse = new VaultListResponse() + when(cerberusClient.list(PATH_2)).thenReturn(path2FirstListResponse); + final CerberusListResponse path2SecondListResponse = new CerberusListResponse() .setKeys(Collections.singletonList(PATH_2_SUBPATH_2)); - when(vaultClient.list(PATH_2 + PATH_2_SUBPATH_1)).thenReturn(path2SecondListResponse); + when(cerberusClient.list(PATH_2 + PATH_2_SUBPATH_1)).thenReturn(path2SecondListResponse); final Map path2Map = new HashMap<>(); path2Map.put(ARTEMIS_CONFIG_KEY, ARTEMIS_CONFIG_VALUE); - final VaultResponse path2Response = new VaultResponse().setData(path2Map); - when(vaultClient.read(PATH_2 + PATH_2_SUBPATH_1 + PATH_2_SUBPATH_2)).thenReturn(path2Response); + final CerberusResponse path2Response = new CerberusResponse().setData(path2Map); + when(cerberusClient.read(PATH_2 + PATH_2_SUBPATH_1 + PATH_2_SUBPATH_2)).thenReturn(path2Response); // call the method under test PollResult result = subject.poll(true, null);