From 8f115a99049870785e1a11504c98cf49746433ff Mon Sep 17 00:00:00 2001 From: akshya96 <87045294+akshya96@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:55:49 -0700 Subject: [PATCH] Parse ha_storage in config (#15900) * parsing values in config ha_storage * adding changelog * adding test to parse storage --- changelog/15900.txt | 3 ++ command/server/config.go | 18 +++++++++-- command/server/config_test.go | 4 +++ command/server/config_test_helpers.go | 44 +++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 changelog/15900.txt diff --git a/changelog/15900.txt b/changelog/15900.txt new file mode 100644 index 000000000..ec1e8b66c --- /dev/null +++ b/changelog/15900.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: Fixes parsing boolean values for ha_storage backends in config +``` \ No newline at end of file diff --git a/command/server/config.go b/command/server/config.go index a3526e16e..1199989c6 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -802,11 +802,25 @@ func parseHAStorage(result *Config, list *ast.ObjectList, name string) error { key = item.Keys[0].Token.Value().(string) } - var m map[string]string - if err := hcl.DecodeObject(&m, item.Val); err != nil { + var config map[string]interface{} + if err := hcl.DecodeObject(&config, item.Val); err != nil { return multierror.Prefix(err, fmt.Sprintf("%s.%s:", name, key)) } + m := make(map[string]string) + for key, val := range config { + valStr, ok := val.(string) + if ok { + m[key] = valStr + continue + } + valBytes, err := json.Marshal(val) + if err != nil { + return err + } + m[key] = string(valBytes) + } + // Pull out the redirect address since it's common to all backends var redirectAddr string if v, ok := m["redirect_addr"]; ok { diff --git a/command/server/config_test.go b/command/server/config_test.go index d24608703..e8e80cc99 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -48,6 +48,10 @@ func TestParseSeals(t *testing.T) { testParseSeals(t) } +func TestParseStorage(t *testing.T) { + testParseStorageTemplate(t) +} + func TestUnknownFieldValidation(t *testing.T) { testUnknownFieldValidation(t) } diff --git a/command/server/config_test_helpers.go b/command/server/config_test_helpers.go index 4cde9b115..c45919826 100644 --- a/command/server/config_test_helpers.go +++ b/command/server/config_test_helpers.go @@ -900,6 +900,49 @@ EOF } } +func testParseStorageTemplate(t *testing.T) { + config, err := ParseConfig(` +storage "consul" { + + disable_registration = false + path = "tmp/" + +} +ha_storage "consul" { + tls_skip_verify = true + scheme = "http" + max_parallel = 128 +} + +`, "") + if err != nil { + t.Fatal(err) + } + + expected := &Config{ + Storage: &Storage{ + Type: "consul", + Config: map[string]string{ + "disable_registration": "false", + "path": "tmp/", + }, + }, + HAStorage: &Storage{ + Type: "consul", + Config: map[string]string{ + "tls_skip_verify": "true", + "scheme": "http", + "max_parallel": "128", + }, + }, + SharedConfig: &configutil.SharedConfig{}, + } + config.Prune() + if diff := deep.Equal(config, expected); diff != nil { + t.Fatal(diff) + } +} + func testParseSeals(t *testing.T) { config, err := LoadConfigFile("./test-fixtures/config_seals.hcl") if err != nil { @@ -1013,6 +1056,7 @@ func testLoadConfigFileLeaseMetrics(t *testing.T) { Config: map[string]string{ "bar": "baz", }, + DisableClustering: true, },