Files
threshold/internal/servers/controller/handlers/options.go
T
Jeff Mitchell 604d642e1e Restrict auth method listing for u_anon (#1122)
This keeps only essential information in list output for auth methods
when the user is u_anon. Boundary's default is to allow listing of
auth methods for anonymous users to allow discovery of authentication
points, but there's no need to return more information about internal
configuration than necessary.
2021-04-14 16:49:08 -04:00

53 lines
1.4 KiB
Go

package handlers
import "github.com/hashicorp/go-hclog"
// GetOpts - iterate the inbound Options and return a struct
func GetOpts(opt ...Option) options {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// Option - how Options are passed as arguments. Some of these are used for
// types within the handlers package, and some are for handlers to re-use across
// the various handler types.
type Option func(*options)
// options = how options are represented
type options struct {
withDiscardUnknownFields bool
WithLogger hclog.Logger
WithAnonymousListing bool
}
func getDefaultOptions() options {
return options{}
}
// WithDiscardUnknownFields provides an option to cause StructToProto to ignore
// unknown fields. This is useful in some instances when we need to unmarshal a
// value from a pb.Struct after we've added some custom extra fields.
func WithDiscardUnknownFields(discard bool) Option {
return func(o *options) {
o.withDiscardUnknownFields = discard
}
}
// WithLogger provides an option include a logger
func WithLogger(logger hclog.Logger) Option {
return func(o *options) {
o.WithLogger = logger
}
}
// WithAnonymousListing provides an option when creating responses to only include those
// desired for listing to anonymous users.
func WithAnonymousListing(anonListing bool) Option {
return func(o *options) {
o.WithAnonymousListing = anonListing
}
}