From 1ce7f1b2d0c983f8cfef0aacf3b92a97ccb9630b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 13 Mar 2019 10:29:39 +0000 Subject: [PATCH] fix(backend): workaround viper map key parsing This is a workaround until this issue is fixed upstream. Fixes #507 --- internal/config/config.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index c2cab219a..91454aa4e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,6 +3,7 @@ package config import ( "bufio" "bytes" + "io/ioutil" "os" "strings" "time" @@ -184,6 +185,28 @@ func (config *configSchema) Read() { log.Fatalf("Invalid grid.sorting.order value '%s', allowed options: disabled, startsAt, label", config.Grid.Sorting.Order) } + // FIXME workaround for https://github.com/prymitive/karma/issues/507 + // until https://github.com/spf13/viper/pull/635 is merged + // read in raw config file if it's used and override maps where keys are label + // names so we can't enforce parsed config key names + if v.ConfigFileUsed() != "" { + raw := configSchema{} + + var rawConfigFile []byte + rawConfigFile, err = ioutil.ReadFile(v.ConfigFileUsed()) + if err != nil { + log.Fatal(err) + } + + err = yaml.Unmarshal(rawConfigFile, &raw) + if err != nil { + log.Fatal(err) + } + + config.Labels.Color.Custom = raw.Labels.Color.Custom + config.Grid.Sorting.CustomValues.Labels = raw.Grid.Sorting.CustomValues.Labels + } + // accept single Alertmanager server from flag/env if nothing is set yet if len(config.Alertmanager.Servers) == 0 && v.GetString("alertmanager.uri") != "" { log.Info("Using simple config with a single Alertmanager server")