Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithInitCommand ¶
func WithInitCommand(commands ...string) testcontainers.CustomizeRequestOption
WithInitCommand is an option function that adds a set of initialization commands to the Vault's configuration
Types ¶
type VaultContainer ¶
type VaultContainer struct {
testcontainers.Container
}
VaultContainer represents the vault container type used in the module
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error)
Run creates an instance of the Vault container type
Example ¶
// runVaultContainer { ctx := context.Background() vaultContainer, err := vault.Run(ctx, "hashicorp/vault:1.13.0") defer func() { if err := testcontainers.TerminateContainer(vaultContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := vaultContainer.State(ctx) if err != nil { log.Printf("failed to get container state: %s", err) return } fmt.Println(state.Running)
Output: true
Example (WithInitCommand) ¶
// runVaultContainerWithInitCommand { ctx := context.Background() vaultContainer, err := vault.Run(ctx, "hashicorp/vault:1.13.0", vault.WithToken("MyToKeN"), vault.WithInitCommand( "auth enable approle", // Enable the approle auth method "secrets disable secret", // Disable the default secret engine "secrets enable -version=1 -path=secret kv", // Enable the kv secret engine at version 1 "write --force auth/approle/role/myrole", // Create a role "write secret/testing top_secret=password123", // Create a secret )) defer func() { if err := testcontainers.TerminateContainer(vaultContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := vaultContainer.State(ctx) if err != nil { log.Printf("failed to get container state: %s", err) return } fmt.Println(state.Running)
Output: true
Example (WithToken) ¶
// runVaultContainerWithToken { ctx := context.Background() vaultContainer, err := vault.Run(ctx, "hashicorp/vault:1.13.0", vault.WithToken("MyToKeN")) defer func() { if err := testcontainers.TerminateContainer(vaultContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := vaultContainer.State(ctx) if err != nil { log.Printf("failed to get container state: %s", err) return } fmt.Println(state.Running) cmds := []string{ "vault", "kv", "put", "secret/test", "value=123", } exitCode, _, err := vaultContainer.Exec(ctx, cmds, exec.Multiplexed()) if err != nil { log.Printf("failed to execute command: %s", err) return } fmt.Println(exitCode)
Output: true 0
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Vault container type
func (*VaultContainer) HttpHostAddress ¶
func (v *VaultContainer) HttpHostAddress(ctx context.Context) (string, error)
HttpHostAddress returns the http host address of Vault. It returns a string with the format http://<host>:<port>
Click to show internal directories.
Click to hide internal directories.