mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-23 19:49:13 +02:00
config: add decode hook for the SANMatcher type
This commit is contained in:
parent
a2539839d3
commit
23e8b3ae6d
3 changed files with 42 additions and 0 deletions
|
@ -38,4 +38,5 @@ var ViperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
||||||
decodeJWTClaimHeadersHookFunc(),
|
decodeJWTClaimHeadersHookFunc(),
|
||||||
decodeCodecTypeHookFunc(),
|
decodeCodecTypeHookFunc(),
|
||||||
decodePPLPolicyHookFunc(),
|
decodePPLPolicyHookFunc(),
|
||||||
|
decodeSANMatcherHookFunc(),
|
||||||
))
|
))
|
||||||
|
|
|
@ -508,6 +508,26 @@ func parseJSONPB(src map[string]interface{}, dst proto.Message, opts protojson.U
|
||||||
return opts.Unmarshal(data, dst)
|
return opts.Unmarshal(data, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decodeSANMatcherHookFunc returns a decode hook for the SANMatcher type.
|
||||||
|
func decodeSANMatcherHookFunc() mapstructure.DecodeHookFunc {
|
||||||
|
return func(f, t reflect.Type, data interface{}) (interface{}, error) {
|
||||||
|
if t != reflect.TypeOf(SANMatcher{}) {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var m SANMatcher
|
||||||
|
if err := json.Unmarshal(b, &m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// serializable converts mapstructure nested map into map[string]interface{} that is serializable to JSON
|
// serializable converts mapstructure nested map into map[string]interface{} that is serializable to JSON
|
||||||
func serializable(in interface{}) (interface{}, error) {
|
func serializable(in interface{}) (interface{}, error) {
|
||||||
switch typed := in.(type) {
|
switch typed := in.(type) {
|
||||||
|
|
|
@ -341,6 +341,27 @@ func Test_parsePolicyFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_decodeSANMatcher(t *testing.T) {
|
||||||
|
// Verify that config file parsing will decode the SANMatcher type.
|
||||||
|
const yaml = `
|
||||||
|
downstream_mtls:
|
||||||
|
match_subject_alt_names:
|
||||||
|
- dns: 'example-1\..*'
|
||||||
|
- dns: '.*\.example-2'
|
||||||
|
`
|
||||||
|
cfg := filepath.Join(t.TempDir(), "config.yaml")
|
||||||
|
err := os.WriteFile(cfg, []byte(yaml), 0644)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
o, err := optionsFromViper(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, []SANMatcher{
|
||||||
|
{Type: SANTypeDNS, Pattern: `example-1\..*`},
|
||||||
|
{Type: SANTypeDNS, Pattern: `.*\.example-2`},
|
||||||
|
}, o.DownstreamMTLS.MatchSubjectAltNames)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_Checksum(t *testing.T) {
|
func Test_Checksum(t *testing.T) {
|
||||||
o := NewDefaultOptions()
|
o := NewDefaultOptions()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue