88 lines
1.9 KiB
Go
88 lines
1.9 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
|
|
PrivateKey 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: "",
|
|
PrivateKey: "",
|
|
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 WithPrivateKey(privateKeyFile string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.PrivateKey = privateKeyFile
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|