2024-05-23 15:17:05 +02:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2024-06-05 15:46:59 +02:00
|
|
|
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/authn"
|
2024-05-23 15:17:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
HTTPTransport *http.Transport
|
|
|
|
HTTPClientTimeout time.Duration
|
2024-06-05 15:46:59 +02:00
|
|
|
AuthnOptions []authn.OptionFunc
|
2024-05-23 15:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type OptionFunc func(opts *Options)
|
|
|
|
|
|
|
|
func WithHTTPTransport(transport *http.Transport) OptionFunc {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.HTTPTransport = transport
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithHTTPClientTimeout(timeout time.Duration) OptionFunc {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.HTTPClientTimeout = timeout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-05 15:46:59 +02:00
|
|
|
func WithAuthnOptions(funcs ...authn.OptionFunc) OptionFunc {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.AuthnOptions = funcs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-23 15:17:05 +02:00
|
|
|
func NewOptions(funcs ...OptionFunc) *Options {
|
|
|
|
opts := &Options{
|
|
|
|
HTTPTransport: http.DefaultTransport.(*http.Transport),
|
|
|
|
HTTPClientTimeout: 30 * time.Second,
|
2024-06-05 15:46:59 +02:00
|
|
|
AuthnOptions: make([]authn.OptionFunc, 0),
|
2024-05-23 15:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, fn := range funcs {
|
|
|
|
fn(opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|