Skip to content

Commit

Permalink
Merge pull request #188 from scalecube/update-vault-config-source-beh…
Browse files Browse the repository at this point in the history
…avior

Changed behavior in VaultConfigSource when vault returns 404
  • Loading branch information
artem-v authored Mar 9, 2021
2 parents 2721622 + ee41e57 commit 752472f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 39 deletions.
19 changes: 4 additions & 15 deletions config-vault/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -11,9 +13,8 @@
<artifactId>config-vault</artifactId>

<properties>
<log4j.version>2.13.3</log4j.version>
<vault-java-driver.version>5.1.0</vault-java-driver.version>
<testcontainers.version>1.12.3</testcontainers.version>
<testcontainers.version>1.15.2</testcontainers.version>
</properties>

<dependencies>
Expand All @@ -33,17 +34,5 @@
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bettercloud.vault.EnvironmentLoader;
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import com.bettercloud.vault.response.LogicalResponse;
import io.scalecube.config.ConfigProperty;
import io.scalecube.config.ConfigSourceNotAvailableException;
Expand Down Expand Up @@ -55,8 +56,14 @@ public Map<String, ConfigProperty> loadConfig() {
.map(LoadedConfigProperty.Builder::build)
.collect(Collectors.toMap(LoadedConfigProperty::name, Function.identity()));
result.putAll(pathProps);
} catch (VaultException ex) {
if (ex.getHttpStatusCode() == 404) {
LOGGER.warn("Unable to load config properties from: {}", path);
} else {
throw new ConfigSourceNotAvailableException(ex);
}
} catch (Exception ex) {
LOGGER.warn("Unable to load config properties from {}", path, ex);
LOGGER.error("Unable to load config properties from: {}, cause:", path, ex);
throw new ConfigSourceNotAvailableException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,11 @@ void testMissingProperty() {

@Test
void testMissingTenant() {
VaultConfigSource vaultConfigSource =
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath("secrets/unknown/path")
.build();

assertThrows(ConfigSourceNotAvailableException.class, vaultConfigSource::loadConfig);
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath("secrets/unknown/path")
.build();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class VaultInstance implements AutoCloseable {

private static final Logger LOGGER = LoggerFactory.getLogger(VaultInstance.class);

private static final String VAULT_IMAGE_NAME = "vault:1.2.3";
private static final String VAULT_IMAGE_NAME = "vault:1.6.1";
private static final int VAULT_PORT = 8200;
private static final AtomicInteger PORT_COUNTER = new AtomicInteger(VAULT_PORT);
private static final String UNSEAL_KEY_LOG = "Unseal Key: ";
Expand Down
16 changes: 3 additions & 13 deletions config/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>io.scalecube</groupId>
Expand All @@ -21,18 +23,6 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
Expand Down
25 changes: 24 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -50,9 +52,12 @@
<jersey.version>2.26-b09</jersey.version>
<commons-io.version>2.6</commons-io.version>

<log4j.version>2.13.3</log4j.version>
<mockito-junit-jupiter.version>2.27.0</mockito-junit-jupiter.version>
<junit-jupiter.version>5.1.1</junit-jupiter.version>
<hamcrest.version>1.3</hamcrest.version>
<!-- TODO: remove explicit version of `jna` once testcontainers fixes dependencies conflict -->
<jna.version>5.5.0</jna.version>
</properties>

<modules>
Expand Down Expand Up @@ -107,6 +112,12 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${jna.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -142,6 +153,18 @@
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down

0 comments on commit 752472f

Please sign in to comment.