From 187d1d65bbba6afb541484e94a169f81a4ccc874 Mon Sep 17 00:00:00 2001 From: Matt Leung Date: Fri, 27 Apr 2018 14:50:47 -0700 Subject: [PATCH] add additional opt to set v.auth --- cmd/drone-server/server.go | 2 +- plugins/secrets/vault/opts.go | 10 +++++++++- plugins/secrets/vault/opts_test.go | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/drone-server/server.go b/cmd/drone-server/server.go index 2729e6a43..fa689212e 100644 --- a/cmd/drone-server/server.go +++ b/cmd/drone-server/server.go @@ -179,7 +179,7 @@ var flags = []cli.Flag{ EnvVar: "DRONE_VAULT_AUTH_TYPE", Name: "drone-vault-auth-type", Usage: "auth backend type used for connecting to vault", - Value: "token", + Value: "", }, cli.StringFlag{ EnvVar: "DRONE_VAULT_AUTH_MOUNT_POINT", diff --git a/plugins/secrets/vault/opts.go b/plugins/secrets/vault/opts.go index 081857854..7b4eaa7eb 100644 --- a/plugins/secrets/vault/opts.go +++ b/plugins/secrets/vault/opts.go @@ -25,9 +25,17 @@ func WithRenewal(d time.Duration) Opts { } } +// WithAuth returns an options that sets the vault +// method to use for authentication +func WithAuth(method string) Opts { + return func(v *vault) { + v.auth = method + } +} + // WithKubernetes returns an options that sets // kubernetes-auth parameters required to retrieve -// an initial Vault token +// an initial vault token func WithKubernetesAuth(addr, role, mount string) Opts { return func(v *vault) { v.kubeAuth.addr = addr diff --git a/plugins/secrets/vault/opts_test.go b/plugins/secrets/vault/opts_test.go index 79f01160f..873907151 100644 --- a/plugins/secrets/vault/opts_test.go +++ b/plugins/secrets/vault/opts_test.go @@ -27,6 +27,16 @@ func TestWithRenewal(t *testing.T) { } } +func TestWithAuth(t *testing.T) { + v := new(vault) + method := "kubernetes" + opt := WithAuth(method) + opt(v) + if got, want := v.auth, method; got != want { + t.Errorf("Want auth %v, got %v", want, got) + } +} + func TestWithKubernetesAuth(t *testing.T) { v := new(vault) addr := "https://address.fake"