Skip to content

Commit

Permalink
remove dependency on vault import
Browse files Browse the repository at this point in the history
  • Loading branch information
lingrino committed Mar 11, 2024
1 parent c13e75f commit 80fc2df
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 1,887 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.7.0 - 2024-03-11

### Changed

- GEN: Remove dependency on Vault import
- GEN: Update dependencies

## 2.6.3 - 2024-02-19

### Changed
Expand Down
47 changes: 26 additions & 21 deletions api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"math/rand/v2"
"os"
"path"
"strconv"
Expand All @@ -14,17 +15,17 @@ import (

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/vault"
"github.com/hashicorp/vault/sdk/helper/testcluster"
"github.com/hashicorp/vault/sdk/helper/testcluster/docker"
"github.com/stretchr/testify/assert"

kv "github.com/hashicorp/vault-plugin-secrets-kv"
vl "github.com/hashicorp/vault/sdk/logical"
)

// mountless, when passed in tests, will not be prefixed with a mount.
const mountless = "mountless"

// cleanupFns is a list of cleanup functions to run at the end of our test run.
var cleanupFns []func()

// sharedVaku for most vaku tests. Tests isolate by path on each mount.
var sharedVaku *Client

Expand Down Expand Up @@ -66,30 +67,34 @@ var seeds = map[string]map[string]any{
// TestMain prepares the test run.
func TestMain(m *testing.M) {
hclog.DefaultOutput = io.Discard
os.Exit(m.Run())

code := m.Run()

for _, cleanup := range cleanupFns {
cleanup()
}

os.Exit(code)
}

// testServer creates a new vault server and returns a vault API client that points to it.
// Pass an empty &testing.T{} to vt if you're initializing a long-lived client so that
// vt.Cleanup() does not shutdown your shared client.
func testServer(t *testing.T, vt *testing.T) *api.Client {
func testServer(t *testing.T) *api.Client {
t.Helper()

// create vault core
core, _, token := vault.TestCoreUnsealedWithConfig(vt, &vault.CoreConfig{
// Must be provided for v1/v2 path differences to work.
LogicalBackends: map[string]vl.Factory{
"kv": kv.Factory,
cluster, err := docker.NewDockerCluster(context.Background(), &docker.DockerClusterOptions{
ImageRepo: "hashicorp/vault",
ImageTag: "latest",
ClusterOptions: testcluster.ClusterOptions{
ClusterName: strconv.Itoa(rand.IntN(1000000000)),
NumCores: 1,
},
Logger: hclog.NewNullLogger(),
})
_, addr := http.TestServer(t, core)

// create client that points at core
client, err := api.NewClient(api.DefaultConfig())
cleanupFns = append(cleanupFns, cluster.Cleanup)
assert.NoError(t, err)
client.SetToken(token)
assert.NoError(t, client.SetAddress(addr))

client := cluster.Nodes()[0].APIClient()

// mount all mount versions
for _, ver := range mountVersions {
Expand All @@ -109,8 +114,8 @@ func testServer(t *testing.T, vt *testing.T) *api.Client {
func initSharedVaku(t *testing.T) {
t.Helper()

srcClient := testServer(t, &testing.T{})
dstClient := testServer(t, &testing.T{})
srcClient := testServer(t)
dstClient := testServer(t)

client, err := NewClient(
WithVaultSrcClient(srcClient),
Expand Down
4 changes: 2 additions & 2 deletions api/mounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestMountInfo(t *testing.T) {
t.Run(tt.give, func(t *testing.T) {
t.Parallel()

client, err := NewClient(WithVaultClient(testServer(t, t)))
client, err := NewClient(WithVaultClient(testServer(t)))
assert.NoError(t, err)

path, vers, err := client.mountInfo(tt.give)
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestRewritePath(t *testing.T) {
t.Run(tt.give, func(t *testing.T) {
t.Parallel()

client, err := NewClient(WithVaultClient(testServer(t, t)))
client, err := NewClient(WithVaultClient(testServer(t)))
assert.NoError(t, err)

path, vers, err := client.rewritePath(tt.give, tt.giveOp)
Expand Down
2 changes: 1 addition & 1 deletion api/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package vaku

// Version gives the current Vaku API version.
func Version() string {
return "2.6.3"
return "2.7.0"
}
2 changes: 1 addition & 1 deletion api/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (

func TestVersion(t *testing.T) {
t.Parallel()
assert.Equal(t, "2.6.3", Version())
assert.Equal(t, "2.7.0", Version())
}
4 changes: 2 additions & 2 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"os"

"github.com/hashicorp/vault/command/config"
"github.com/hashicorp/vault/api/cliconfig"
"github.com/spf13/cobra"

vault "github.com/hashicorp/vault/api"
Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *cli) setVaultToken(vc *vault.Client, token string) error {
return nil
}

helper, err := config.DefaultTokenHelper()
helper, err := cliconfig.DefaultTokenHelper()
if err != nil || c.fail == "config.DefaultTokenHelper" {
return c.combineErr(errVaultTokenHelper, err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func TestVersion(t *testing.T) {
{
name: "version test",
giveVersion: "test",
wantOut: "API: 2.6.3\nCLI: test\n",
wantOut: "API: 2.7.0\nCLI: test\n",
},
{
name: "version version",
giveVersion: "version",
wantOut: "API: 2.6.3\nCLI: version\n",
wantOut: "API: 2.7.0\nCLI: version\n",
},
{
name: "args",
Expand Down
Loading

0 comments on commit 80fc2df

Please sign in to comment.