Skip to content

Commit

Permalink
Merge pull request #187 from scalecube/add-vault-timeouts
Browse files Browse the repository at this point in the history
Add vault timeouts
  • Loading branch information
artem-v authored Dec 29, 2020
2 parents ddf5211 + cb15f23 commit a79cef5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions config-vault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

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

<dependencies>
Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>vault</artifactId>
<version>${org.testcontainers.vault.version}</version>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.slf4j.LoggerFactory;

/**
* This class is a {@link ConfigSource} implemented for Vault.
* This class is an implementation of {@link ConfigSource} for Vault.
*
* @see <a href="https://www.vaultproject.io/">Vault Project</a>
*/
Expand Down Expand Up @@ -69,7 +69,8 @@ public static Builder builder() {

public static final class Builder {

private Function<VaultInvoker.Builder, VaultInvoker.Builder> builderFunction = b -> b;
private Function<VaultInvoker.Builder, VaultInvoker.Builder> builderFunction =
Function.identity();

private VaultInvoker invoker;

Expand Down Expand Up @@ -114,7 +115,7 @@ public Builder addSecretsPath(String... secretsPath) {
* Setter for {@code secretsPaths}.
*
* @param secretsPaths collection of secretsPath\es (each value may contain paths separated by
* {@code :})
* colon)
* @return this builder
*/
public Builder secretsPaths(Collection<String> secretsPaths) {
Expand All @@ -133,18 +134,18 @@ public Builder invoker(VaultInvoker invoker) {
return this;
}

public Builder vault(UnaryOperator<VaultInvoker.Builder> config) {
this.builderFunction = this.builderFunction.andThen(config);
public Builder vault(UnaryOperator<VaultInvoker.Builder> opts) {
this.builderFunction = this.builderFunction.andThen(opts);
return this;
}

public Builder config(UnaryOperator<VaultConfig> vaultConfig) {
this.builderFunction = this.builderFunction.andThen(c -> c.options(vaultConfig));
this.builderFunction = this.builderFunction.andThen(b -> b.options(vaultConfig));
return this;
}

public Builder tokenSupplier(VaultTokenSupplier supplier) {
this.builderFunction = this.builderFunction.andThen(c -> c.tokenSupplier(supplier));
this.builderFunction = this.builderFunction.andThen(b -> b.tokenSupplier(supplier));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.scalecube.config.utils.ThrowableUtil;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Optional;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -211,7 +212,15 @@ public void run() {

public static class Builder {

private Function<VaultConfig, VaultConfig> options = Function.identity();
private static final int OPEN_TIMEOUT_SEC =
Optional.ofNullable(System.getenv("VAULT_OPEN_TIMEOUT")).map(Integer::parseInt).orElse(10);

private static final int READ_TIMEOUT_SEC =
Optional.ofNullable(System.getenv("VAULT_READ_TIMEOUT")).map(Integer::parseInt).orElse(10);

private Function<VaultConfig, VaultConfig> options =
config -> config.openTimeout(OPEN_TIMEOUT_SEC).readTimeout(READ_TIMEOUT_SEC);

private VaultTokenSupplier tokenSupplier = new EnvironmentVaultTokenSupplier();

public Builder options(UnaryOperator<VaultConfig> config) {
Expand Down

0 comments on commit a79cef5

Please sign in to comment.