oauth2-proxy
oauth2-proxy copied to clipboard
structured config #1: introduce mapstructure decoder for yaml parsing
Description
This PR introduces mapstructure for decoding and encoding the yaml files. Mapstructure is a defacto standard library used by many libraries like spf13/viper for more dynamic data loading between different interfaces.
Just using the golang json / yaml encoding / decoding would lead to overwriting the default set before loading the config file. Trying to load the default configs afterwards would be rather hard or impossible.
Motivation and Context
Cases to consider:
- When directly loading into a struct you cannot identify if the user explicitly set a boolean to
false
in the config file or if it was set to the boolean default of false. This is problematic as we have boolean likeCookie.Secure
that are supposed to be set totrue
by default. - For better readability we might want to squash elements in the yaml like
HeaderValues
either being aSecretSource
orClaimSource
. Which isn't supported by the default json / yaml parser
# non-squashed
headers:
- name: X-Forwarded-User
values:
- claimSource:
claim: user
# squashed
headers:
- name: X-Forwarded-User
values:
- claim: user
- Parsing of
time
primitives likeDuration
orTime
through strings. If you want to be able to configureDuration
types with values like2h
. You need to implement a custom wrapper type and Marshal and Unmarshal method. Mapstructure allows for decoding hooks through the usage of relection.
How Has This Been Tested?
- Test cases have been extend / adapted.
- Starting the application with toml config file
- Using the conversion function from toml to yaml
- Starting the application with yaml config file
Checklist:
- [ ] My change requires a change to the documentation or CHANGELOG.
- [x] I have updated the documentation/CHANGELOG accordingly.
- [x] I have created a feature (non-master) branch for my PR.
- [x] I have written tests for my code changes.