mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-05 10:58:11 +02:00
core/config: add support for maps in environments
This commit is contained in:
parent
ffca3b36a9
commit
ead090d9ce
3 changed files with 25 additions and 0 deletions
|
@ -39,4 +39,5 @@ var ViperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
|
||||||
decodeCodecTypeHookFunc(),
|
decodeCodecTypeHookFunc(),
|
||||||
decodePPLPolicyHookFunc(),
|
decodePPLPolicyHookFunc(),
|
||||||
decodeSANMatcherHookFunc(),
|
decodeSANMatcherHookFunc(),
|
||||||
|
decodeStringToMapHookFunc(),
|
||||||
))
|
))
|
||||||
|
|
|
@ -528,6 +528,21 @@ func decodeSANMatcherHookFunc() mapstructure.DecodeHookFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeStringToMapHookFunc() mapstructure.DecodeHookFunc {
|
||||||
|
return mapstructure.DecodeHookFuncValue(func(f, t reflect.Value) (any, error) {
|
||||||
|
if f.Kind() != reflect.String || t.Kind() != reflect.Map {
|
||||||
|
return f.Interface(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(f.Interface().(string)), t.Addr().Interface())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.Interface(), 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) {
|
||||||
|
|
|
@ -1263,6 +1263,15 @@ func TestOptions_RequestParams(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOptions_RequestParamsFromEnv(t *testing.T) {
|
||||||
|
t.Setenv("IDP_REQUEST_PARAMS", `{"x":"y"}`)
|
||||||
|
|
||||||
|
options, err := newOptionsFromConfig("")
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Equal(t, map[string]string{"x": "y"}, options.RequestParams)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func encodeCert(cert *tls.Certificate) []byte {
|
func encodeCert(cert *tls.Certificate) []byte {
|
||||||
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Certificate[0]})
|
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Certificate[0]})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue