2018-02-22 00:12:10 +02:00
|
|
|
// Copyright 2018 Drone.IO Inc
|
|
|
|
// Use of this software is governed by the Drone Enterpise License
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package vault
|
|
|
|
|
2018-04-27 23:22:20 +02:00
|
|
|
import "time"
|
2018-02-22 00:12:10 +02:00
|
|
|
|
|
|
|
// Opts sets custom options for the vault client.
|
|
|
|
type Opts func(v *vault)
|
|
|
|
|
|
|
|
// WithTTL returns an options that sets a TTL used to
|
|
|
|
// refresh periodic tokens.
|
|
|
|
func WithTTL(d time.Duration) Opts {
|
|
|
|
return func(v *vault) {
|
|
|
|
v.ttl = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRenewal returns an options that sets the renewal
|
|
|
|
// period used to refresh periodic tokens
|
|
|
|
func WithRenewal(d time.Duration) Opts {
|
|
|
|
return func(v *vault) {
|
|
|
|
v.renew = d
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:48:50 +02:00
|
|
|
|
2018-04-27 23:50:47 +02:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 23:22:20 +02:00
|
|
|
// WithKubernetes returns an options that sets
|
|
|
|
// kubernetes-auth parameters required to retrieve
|
2018-04-27 23:50:47 +02:00
|
|
|
// an initial vault token
|
2018-04-27 23:22:20 +02:00
|
|
|
func WithKubernetesAuth(addr, role, mount string) Opts {
|
2018-04-24 23:48:50 +02:00
|
|
|
return func(v *vault) {
|
2018-04-27 23:22:20 +02:00
|
|
|
v.kubeAuth.addr = addr
|
|
|
|
v.kubeAuth.role = role
|
|
|
|
v.kubeAuth.mount = mount
|
2018-04-24 23:48:50 +02:00
|
|
|
}
|
|
|
|
}
|