Skip to content

Commit

Permalink
feat: add Vault Module (#942)
Browse files Browse the repository at this point in the history
* create couchbase module

* expose enabled service ports

* add wait until all nodes are healthy

* add cluster initialization functions

* refactor enabledServices for loop with contains method

* add configureExternalPorts

* refactor doHttpRequest to create new request with context

* add create buckets

* complete create bucket flow

* add docker image name to config

* fix port suffix, mapped port, enabled services and refactor checkAllServicesEnabled with gjson

* add initCluster method

* refactor bucket definition

* update module name

* add ConnectionString, Username, Password for test case and fix configure external port

* add test

* goimports and go mod tidy

* fix: use modules instead of example

* change WithBasicCredentials with WithBasicAuth

* add test for community edition

* fix eventing service with community container test

* update depandabot.yml and go.mod

* update couchbase doc

* reorder modules couchbase dependabot.yml

* Update modules/couchbase/go.mod

Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>

* add comments for public methods

* add option for index storage mode

* add comments for index storage modes

* create vault module using modulegen

* add vault config options

* update container request, impl add secret and init commands

* add addSecret and runInitCommands to StartContainer

* add tests

* add default log level

* add vault doc

* remove options and use ContainerRequest

* update docs and tests, export vault container type

* remove log level option

* update default image

* update docs

---------

Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
  • Loading branch information
alihanyalcin and mdelapenya committed Mar 23, 2023
1 parent 2de5486 commit 0c663fe
Show file tree
Hide file tree
Showing 10 changed files with 761 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ updates:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/vault
schedule:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
46 changes: 46 additions & 0 deletions .github/workflows/module-vault.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: vault module pipeline

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
test-vault:
strategy:
matrix:
go-version: [1.19.x, 1.x]
runs-on: "ubuntu-latest"
steps:

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: modVerify
working-directory: ./modules/vault
run: go mod verify

- name: modTidy
working-directory: ./modules/vault
run: make tools-tidy

- name: gotestsum
working-directory: ./modules/vault
run: make test-unit

- name: Run checker
run: |
./scripts/check_environment.sh
- name: Test Summary
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7
with:
paths: "**/TEST-vault*.xml"
if: always()
65 changes: 65 additions & 0 deletions docs/modules/vault.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Vault

<img src="https://cdn.worldvectorlogo.com/logos/vault-enterprise.svg" width="200" />

Testcontainers module for Vault. [Vault](https://www.vaultproject.io/) is an open-source tool designed for securely storing, accessing, and managing secrets and sensitive data such as passwords, certificates, API keys, and other confidential information.

## Adding this module to your project dependencies

Please run the following command to add the Vault module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/vault
```

## Usage example
The **StartContainer** function is the main entry point to create a new VaultContainer instance.
It takes a context and zero or more Option values to configure the container.
<!--codeinclude-->
[Creating a Vault container](../../modules/vault/vault_test.go) inside_block:StartContainer
<!--/codeinclude-->

### Use CLI to read data from Vault container:
<!--codeinclude-->
[Use CLI to read data](../../modules/vault/vault_test.go) inside_block:TestVaultGetSecretPathWithCLI
<!--/codeinclude-->

### Use HTTP API to read data from Vault container:
<!--codeinclude-->
[Use HTTP API to read data](../../modules/vault/vault_test.go) inside_block:TestVaultGetSecretPathWithHTTP
<!--/codeinclude-->

### Use client library to read data from Vault container:
Add Vault Client module to your Go dependencies:
```
go get -u github.com/hashicorp/vault-client-go
```
<!--codeinclude-->
[Use library to read data](../../modules/vault/vault_test.go) inside_block:TestVaultGetSecretPathWithClient
<!--/codeinclude-->

## Container Options

You can set below options to create Vault container.

### Image
If you need to set a different Vault image, you can use the `WithImageName`.

!!!info
Default image name is `hashicorp/vault:1.13.0`.

<!--codeinclude-->
[Set image name](../../modules/vault/vault_test.go) inside_block:WithImageName
<!--/codeinclude-->

### Token
If you need to add token authentication, you can use the `WithToken`.
<!--codeinclude-->
[Add token authentication](../../modules/vault/vault_test.go) inside_block:WithToken
<!--/codeinclude-->

### Command
If you need to run vault command in the container, you can use the `WithInitCommand`.
<!--codeinclude-->
[Run init command](../../modules/vault/vault_test.go) inside_block:WithInitCommand
<!--/codeinclude-->
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ nav:
- modules/localstack.md
- modules/postgres.md
- modules/pulsar.md
- modules/vault.md
- Examples:
- examples/index.md
- examples/bigtable.md
Expand Down
5 changes: 5 additions & 0 deletions modules/vault/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-vault
70 changes: 70 additions & 0 deletions modules/vault/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module github.com/testcontainers/testcontainers-go/modules/vault

go 1.19

require (
github.com/docker/docker v23.0.1+incompatible
github.com/docker/go-connections v0.4.0
github.com/stretchr/testify v1.8.2
github.com/testcontainers/testcontainers-go v0.19.0
github.com/tidwall/gjson v1.14.4
gotest.tools/gotestsum v1.9.0
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/containerd/containerd v1.6.19 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dnephin/pflag v1.0.7 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/vault-client-go v0.2.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.0.0-20221128092401-c43b287e0e0f // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.2.0 // indirect
google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.4.0 // indirect
)

replace github.com/testcontainers/testcontainers-go => ../..

0 comments on commit 0c663fe

Please sign in to comment.