William Petit
7de166765b
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
96 lines
2.1 KiB
Go
96 lines
2.1 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"time"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/lock"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/lock/memory"
|
|
)
|
|
|
|
type Options struct {
|
|
WriterTokenSecret string
|
|
WriterTokenSecretNamespace string
|
|
ReaderTokenSecret string
|
|
ReaderTokenSecretNamespace string
|
|
PrivateKeySecret string
|
|
PrivateKeySecretNamespace string
|
|
Issuer string
|
|
Locker lock.Locker
|
|
LockTimeout time.Duration
|
|
}
|
|
|
|
type OptionFunc func(opts *Options)
|
|
|
|
func NewOptions(funcs ...OptionFunc) *Options {
|
|
opts := &Options{
|
|
WriterTokenSecret: "",
|
|
WriterTokenSecretNamespace: "",
|
|
ReaderTokenSecret: "",
|
|
ReaderTokenSecretNamespace: "",
|
|
PrivateKeySecret: "",
|
|
PrivateKeySecretNamespace: "",
|
|
Issuer: "",
|
|
Locker: memory.NewLocker(),
|
|
LockTimeout: 30 * time.Second,
|
|
}
|
|
for _, fn := range funcs {
|
|
fn(opts)
|
|
}
|
|
|
|
return opts
|
|
}
|
|
|
|
func WithWriterTokenSecret(secretName string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.WriterTokenSecret = secretName
|
|
}
|
|
}
|
|
|
|
func WithWriterTokenSecretNamespace(namespace string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.WriterTokenSecretNamespace = namespace
|
|
}
|
|
}
|
|
|
|
func WithReaderTokenSecret(secretName string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.ReaderTokenSecret = secretName
|
|
}
|
|
}
|
|
|
|
func WithReaderTokenSecretNamespace(namespace string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.ReaderTokenSecretNamespace = namespace
|
|
}
|
|
}
|
|
|
|
func WithPrivateKeySecret(secretName string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.PrivateKeySecret = secretName
|
|
}
|
|
}
|
|
|
|
func WithPrivateKeySecretNamespace(namespace string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.PrivateKeySecretNamespace = namespace
|
|
}
|
|
}
|
|
|
|
func WithIssuer(issuer string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.Issuer = issuer
|
|
}
|
|
}
|
|
|
|
func WithLocker(locker lock.Locker) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.Locker = locker
|
|
}
|
|
}
|
|
|
|
func WithLockTimeout(timeout time.Duration) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.LockTimeout = timeout
|
|
}
|
|
}
|