config: expose viper policy hooks (#1947)

This commit is contained in:
Caleb Doxsey 2021-02-25 10:12:51 -07:00 committed by GitHub
parent 4f2bb60adb
commit e9083b6dad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -29,8 +29,8 @@ var (
var (
// viperPolicyHooks are used to decode options and policy coming from YAML and env vars
viperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
// ViperPolicyHooks are used to decode options and policy coming from YAML and env vars
ViperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToSliceHookFunc(","),
// decode policy including all protobuf-native notations - i.e. duration as `1s`

View file

@ -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)
}
@ -392,7 +392,7 @@ func optionsFromViper(configFile string) (*Options, error) {
// variables or from a file
func (o *Options) parsePolicy() error {
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
}
if len(policies) != 0 {

View file

@ -94,7 +94,7 @@ func Test_bindEnvs(t *testing.T) {
if err != nil {
t.Fatalf("failed to bind options to env vars: %s", err)
}
err = v.Unmarshal(o, viperPolicyHooks)
err = v.Unmarshal(o, ViperPolicyHooks)
if err != nil {
t.Errorf("Could not unmarshal %#v: %s", o, err)
}