mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
Parse ha_storage in config (#15900)
* parsing values in config ha_storage * adding changelog * adding test to parse storage
This commit is contained in:
3
changelog/15900.txt
Normal file
3
changelog/15900.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
core: Fixes parsing boolean values for ha_storage backends in config
|
||||||
|
```
|
||||||
@@ -802,11 +802,25 @@ func parseHAStorage(result *Config, list *ast.ObjectList, name string) error {
|
|||||||
key = item.Keys[0].Token.Value().(string)
|
key = item.Keys[0].Token.Value().(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
var m map[string]string
|
var config map[string]interface{}
|
||||||
if err := hcl.DecodeObject(&m, item.Val); err != nil {
|
if err := hcl.DecodeObject(&config, item.Val); err != nil {
|
||||||
return multierror.Prefix(err, fmt.Sprintf("%s.%s:", name, key))
|
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
|
// Pull out the redirect address since it's common to all backends
|
||||||
var redirectAddr string
|
var redirectAddr string
|
||||||
if v, ok := m["redirect_addr"]; ok {
|
if v, ok := m["redirect_addr"]; ok {
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ func TestParseSeals(t *testing.T) {
|
|||||||
testParseSeals(t)
|
testParseSeals(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseStorage(t *testing.T) {
|
||||||
|
testParseStorageTemplate(t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestUnknownFieldValidation(t *testing.T) {
|
func TestUnknownFieldValidation(t *testing.T) {
|
||||||
testUnknownFieldValidation(t)
|
testUnknownFieldValidation(t)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
func testParseSeals(t *testing.T) {
|
||||||
config, err := LoadConfigFile("./test-fixtures/config_seals.hcl")
|
config, err := LoadConfigFile("./test-fixtures/config_seals.hcl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1013,6 +1056,7 @@ func testLoadConfigFileLeaseMetrics(t *testing.T) {
|
|||||||
Config: map[string]string{
|
Config: map[string]string{
|
||||||
"bar": "baz",
|
"bar": "baz",
|
||||||
},
|
},
|
||||||
|
|
||||||
DisableClustering: true,
|
DisableClustering: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user