mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
config: expose viper policy hooks (#1947)
This commit is contained in:
parent
4f2bb60adb
commit
e9083b6dad
3 changed files with 5 additions and 5 deletions
|
@ -29,8 +29,8 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
||||||
// viperPolicyHooks are used to decode options and policy coming from YAML and env vars
|
// ViperPolicyHooks are used to decode options and policy coming from YAML and env vars
|
||||||
viperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
ViperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
||||||
mapstructure.StringToTimeDurationHookFunc(),
|
mapstructure.StringToTimeDurationHookFunc(),
|
||||||
mapstructure.StringToSliceHookFunc(","),
|
mapstructure.StringToSliceHookFunc(","),
|
||||||
// decode policy including all protobuf-native notations - i.e. duration as `1s`
|
// decode policy including all protobuf-native notations - i.e. duration as `1s`
|
||||||
|
|
|
@ -375,7 +375,7 @@ func optionsFromViper(configFile string) (*Options, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := v.Unmarshal(o, viperPolicyHooks); err != nil {
|
if err := v.Unmarshal(o, ViperPolicyHooks); err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ func optionsFromViper(configFile string) (*Options, error) {
|
||||||
// variables or from a file
|
// variables or from a file
|
||||||
func (o *Options) parsePolicy() error {
|
func (o *Options) parsePolicy() error {
|
||||||
var policies []Policy
|
var policies []Policy
|
||||||
if err := o.viper.UnmarshalKey("policy", &policies, viperPolicyHooks); err != nil {
|
if err := o.viper.UnmarshalKey("policy", &policies, ViperPolicyHooks); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(policies) != 0 {
|
if len(policies) != 0 {
|
||||||
|
|
|
@ -94,7 +94,7 @@ func Test_bindEnvs(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to bind options to env vars: %s", err)
|
t.Fatalf("failed to bind options to env vars: %s", err)
|
||||||
}
|
}
|
||||||
err = v.Unmarshal(o, viperPolicyHooks)
|
err = v.Unmarshal(o, ViperPolicyHooks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Could not unmarshal %#v: %s", o, err)
|
t.Errorf("Could not unmarshal %#v: %s", o, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue