add additional opt to set v.auth

This commit is contained in:
Matt Leung 2018-04-27 14:50:47 -07:00
parent db698f9ef4
commit 187d1d65bb
3 changed files with 20 additions and 2 deletions

View file

@ -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",

View file

@ -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

View file

@ -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"