From 4fab7c035798c5b646b20b38cc7ac6338b618e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Thu, 15 Jul 2021 12:56:10 +0200 Subject: [PATCH] Allow to override some nested values in config. --- configx/koanf_env.go | 12 ++++++++++-- configx/provider_test.go | 1 + configx/stub/kratos/expected.json | 13 ++++++++++++- configx/stub/kratos/kratos.yaml | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/configx/koanf_env.go b/configx/koanf_env.go index 0ab635c6..0129ab40 100644 --- a/configx/koanf_env.go +++ b/configx/koanf_env.go @@ -42,8 +42,16 @@ func NewKoanfEnv(prefix string, schema []byte) (*env.Env, error) { } decode := func(value string) (v interface{}) { - _ = json.Unmarshal([]byte(value), v) - return v + b := []byte(value) + var arr []interface{} + if err := json.Unmarshal(b, &arr); err == nil { + return &arr + } + h := map[string]interface{}{} + if err := json.Unmarshal(b, &h); err == nil { + return &h + } + return nil } return env.ProviderWithValue(prefix, ".", func(key string, value string) (string, interface{}) { diff --git a/configx/provider_test.go b/configx/provider_test.go index 53e4191b..56ab9cfd 100644 --- a/configx/provider_test.go +++ b/configx/provider_test.go @@ -109,6 +109,7 @@ func TestAdvancedConfigs(t *testing.T) { stub: "kratos", configs: []string{"stub/kratos/kratos.yaml"}, isValid: true, envs: [][2]string{ + {"SELFSERVICE_METHODS_OIDC_CONFIG_PROVIDERS", `[{"id":"google","provider":"google","mapper_url":"file:///etc/config/kratos/oidc.google.jsonnet","client_id":"client@example.com","client_secret":"secret"}]`}, {"DSN", "sqlite:///var/lib/sqlite/db.sqlite?_fk=true"}, }}, { diff --git a/configx/stub/kratos/expected.json b/configx/stub/kratos/expected.json index 57a6a8e3..1e666e6d 100644 --- a/configx/stub/kratos/expected.json +++ b/configx/stub/kratos/expected.json @@ -81,7 +81,18 @@ "enabled": true }, "oidc": { - "enabled": false + "enabled": true, + "config": { + "providers": [ + { + "id": "google", + "provider": "google", + "mapper_url": "file:///etc/config/kratos/oidc.google.jsonnet", + "client_id": "client@example.com", + "client_secret": "secret" + } + ] + } }, "password": { "enabled": true diff --git a/configx/stub/kratos/kratos.yaml b/configx/stub/kratos/kratos.yaml index 1e0bdb78..9848e3b2 100644 --- a/configx/stub/kratos/kratos.yaml +++ b/configx/stub/kratos/kratos.yaml @@ -18,6 +18,8 @@ selfservice: methods: password: enabled: true + oidc: + enabled: true flows: error: