From e64db24003e05a642b5f3d8ce0cb084fc6ac7adb Mon Sep 17 00:00:00 2001 From: Or Noyman Date: Fri, 30 Oct 2020 18:23:55 +0200 Subject: [PATCH] Vault: add a fluent API for configuring Vault's logging level (#2231) --- .../org/testcontainers/vault/VaultContainer.java | 12 ++++++++++++ .../org/testcontainers/vault/VaultLogLevel.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 modules/vault/src/main/java/org/testcontainers/vault/VaultLogLevel.java diff --git a/modules/vault/src/main/java/org/testcontainers/vault/VaultContainer.java b/modules/vault/src/main/java/org/testcontainers/vault/VaultContainer.java index b0c8a2a40e3..f47818d8c7d 100644 --- a/modules/vault/src/main/java/org/testcontainers/vault/VaultContainer.java +++ b/modules/vault/src/main/java/org/testcontainers/vault/VaultContainer.java @@ -10,6 +10,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import static com.github.dockerjava.api.model.Capability.IPC_LOCK; @@ -106,6 +107,17 @@ public SELF withVaultPort(int port) { return self(); } + /** + * Sets the logging level for the Vault server in the container. + * Logs can be consumed through {@link #withLogConsumer(Consumer)}. + * + * @param level the logging level to set for Vault. + * @return this + */ + public SELF withLogLevel(VaultLogLevel level) { + return withEnv("VAULT_LOG_LEVEL", level.config); + } + /** * Pre-loads secrets into Vault container. User may specify one or more secrets and all will be added to each path * that is specified. Thus this can be called more than once for multiple paths to be added to Vault. diff --git a/modules/vault/src/main/java/org/testcontainers/vault/VaultLogLevel.java b/modules/vault/src/main/java/org/testcontainers/vault/VaultLogLevel.java new file mode 100644 index 00000000000..58b22f975ff --- /dev/null +++ b/modules/vault/src/main/java/org/testcontainers/vault/VaultLogLevel.java @@ -0,0 +1,14 @@ +package org.testcontainers.vault; + +/** + * Vault preset of logging levels. + */ +public enum VaultLogLevel { + Trace("trace"), Debug("debug"), Info("info"), Warn("warn"), Error("err"); + + public final String config; + + VaultLogLevel(String config) { + this.config = config; + } +}