Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17 from Nike-Inc/update-java-client
Browse files Browse the repository at this point in the history
Update Cerberus Java Client Version
  • Loading branch information
sdford authored May 11, 2018
2 parents c7d4bad + 91d3e1d commit ae4a18f
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 134 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@ 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() {
/*
* 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
* the path we looked up above. This factory will attempt to resolve cerberus configuration detailts,
* like the URL and token from Archaius properties.
*/
final NamespacedCerberusConfigurationSource namespacedCerberusConfigurationSource = new NamespacedCerberusConfigurationSource(
ArchaiusCerberusClientFactory.getClient(), vaultPath);
ArchaiusCerberusClientFactory.getClient(), cerberusPath);

/*
* Read secrets from Cerberus.
Expand All @@ -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");
}
}
Expand All @@ -122,31 +122,31 @@ 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() {
/*
* 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
* the path we looked up above. This factory will attempt to resolve cerberus configuration detailts,
* 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.
Expand All @@ -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");
}
}
Expand All @@ -188,31 +188,31 @@ 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() {
/*
* 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
* the path we looked up above. This factory will attempt to resolve cerberus configuration detailts,
* 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.
Expand All @@ -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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

version=5.2.0
version=6.0.0
groupId=com.nike
artifactId=cerberus-archaius-client

Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,7 +29,7 @@
*/
public abstract class BaseCerberusConfigurationSource implements PolledConfigurationSource {

private final VaultClient vaultClient;
private final CerberusClient cerberusClient;

private final Set<String> paths;

Expand All @@ -38,45 +38,45 @@ public abstract class BaseCerberusConfigurationSource implements PolledConfigura
/**
* Constructor that accepts a Set&lt;String&gt; for paths.
*
* @param vaultClient Instance of {@link VaultClient}
* @param paths Set&lt;String&gt; 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&lt;String&gt; containing cerberus paths where configuration is stored
* @throws IllegalArgumentException if cerberusClient is null or if paths is null/empty
*/
public BaseCerberusConfigurationSource(VaultClient vaultClient, Set<String> paths) {
public BaseCerberusConfigurationSource(CerberusClient cerberusClient, Set<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.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());
}

/**
* 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<String> getPaths() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,23 +40,23 @@ public class CerberusConfigurationSource extends BaseCerberusConfigurationSource
/**
* Constructor that accepts a Set&lt;String&gt; for paths.
*
* @param vaultClient Instance of {@link VaultClient}
* @param paths Set&lt;String&gt; 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&lt;String&gt; 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<String> paths) {
super(vaultClient, paths);
public CerberusConfigurationSource(final CerberusClient cerberusClient, final Set<String> 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);
}

/**
Expand All @@ -81,9 +81,9 @@ public AbstractConfiguration getConfig(){
private Map<String, Object> getMap() {
final Map<String, Object> 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;
}
Expand Down
Loading

0 comments on commit ae4a18f

Please sign in to comment.