Class VaultContainer<SELF extends VaultContainer<SELF>>

java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<SELF>
org.testcontainers.vault.VaultContainer<SELF>
All Implemented Interfaces:
AutoCloseable, org.junit.rules.TestRule, org.testcontainers.containers.Container<SELF>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class VaultContainer<SELF extends VaultContainer<SELF>> extends org.testcontainers.containers.GenericContainer<SELF>
Testcontainers implementation for Vault.

Supported image: hashicorp/vault, vault

Exposure ports: 8200

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    VaultContainer(String dockerImageName)
     
    VaultContainer(org.testcontainers.utility.DockerImageName dockerImageName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
     
     
    withInitCommand(String... commands)
    Run initialization commands using the vault cli.
    Deprecated.
    use GenericContainer.withEnv(String, String) instead
    withSecretInVault(String path, String firstSecret, String... remainingSecrets)
    Deprecated.
    withVaultPort(int port)
    Deprecated.
    the exposed port will be randomized automatically.
    Sets the Vault root token for the container so application tests can source secrets using the token

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, configure, containerIsCreated, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, failed, finished, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, starting, stop, succeeded, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Constructor Details

    • VaultContainer

      @Deprecated public VaultContainer()
      Deprecated.
    • VaultContainer

      public VaultContainer(String dockerImageName)
    • VaultContainer

      public VaultContainer(org.testcontainers.utility.DockerImageName dockerImageName)
  • Method Details

    • getHttpHostAddress

      public String getHttpHostAddress()
    • containerIsStarted

      protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
      Overrides:
      containerIsStarted in class org.testcontainers.containers.GenericContainer<SELF extends VaultContainer<SELF>>
    • withVaultToken

      public SELF withVaultToken(String token)
      Sets the Vault root token for the container so application tests can source secrets using the token
      Parameters:
      token - the root token value to set for Vault.
      Returns:
      this
    • withVaultPort

      @Deprecated public SELF withVaultPort(int port)
      Deprecated.
      the exposed port will be randomized automatically. As calling this method provides no additional value, you are recommended to remove the call. getFirstMappedPort() may be used to obtain the listening vault port.
      Sets the Vault port in the container as well as the port bindings for the host to reach the container over HTTP.
      Parameters:
      port - the port number you want to have the Vault container listen on for tests.
      Returns:
      this
    • withLogLevel

      @Deprecated public SELF withLogLevel(VaultLogLevel level)
      Deprecated.
      use GenericContainer.withEnv(String, String) instead
      Sets the logging level for the Vault server in the container. Logs can be consumed through GenericContainer.withLogConsumer(Consumer).
      Parameters:
      level - the logging level to set for Vault.
      Returns:
      this
    • withSecretInVault

      @Deprecated public SELF withSecretInVault(String path, String firstSecret, String... remainingSecrets)
      Deprecated.
      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.

      The secrets are added to vault directly after the container is up via the addSecrets, called from containerIsStarted

      Parameters:
      path - specific Vault path to store specified secrets
      firstSecret - first secret to add to specified path
      remainingSecrets - var args list of secrets to add to specified path
      Returns:
      this
    • withInitCommand

      public SELF withInitCommand(String... commands)
      Run initialization commands using the vault cli.

      Useful for enabling more secret engines like:

           .withInitCommand("secrets enable pki")
           .withInitCommand("secrets enable transit")
       
      Parameters:
      commands - The commands to send to the vault cli
      Returns:
      this