package basic import ( "forge.cadoles.com/cadoles/bouncer/internal/proxy/director/layer/authn" "forge.cadoles.com/cadoles/bouncer/internal/store" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" ) type LayerOptions struct { authn.LayerOptions Users []User `mapstructure:"users"` Realm string `mapstructure:"realm"` } type User struct { Username string `mapstructure:"username"` PasswordHash string `mapstructure:"passwordHash"` Attributes map[string]any `mapstructure:"attributes"` } func fromStoreOptions(storeOptions store.LayerOptions) (*LayerOptions, error) { layerOptions := LayerOptions{ LayerOptions: authn.DefaultLayerOptions(), Realm: "Restricted area", Users: make([]User, 0), } config := mapstructure.DecoderConfig{ Result: &layerOptions, } decoder, err := mapstructure.NewDecoder(&config) if err != nil { return nil, err } if err := decoder.Decode(storeOptions); err != nil { return nil, errors.WithStack(err) } return &layerOptions, nil }