Skip to content

Commit

Permalink
allow to read integer
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-slava committed May 28, 2020
1 parent 0980c50 commit d491db4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions it/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func TestMigrator__integration(t *testing.T) {
for i := range data {
m := make(map[string]interface{})

switch data[i].value.(type) {
switch d := data[i].value.(type) {
case int:
m[data[i].key] = data[i].value.(int)
m[data[i].key] = d
case string:
m[data[i].key] = data[i].value.(string)
m[data[i].key] = d
default:
t.Fatal("Error: unsupported data type")
}
Expand Down
19 changes: 15 additions & 4 deletions vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func (v *Vault) Read(path string) map[string]interface{} {
for k, v := range s.Data {
switch t := v.(type) {
case json.Number:
if n, err := v.(json.Number).Int64(); err == nil {
if n, err := t.Int64(); err == nil {
out[k] = n
} else if f, err := v.(json.Number).Float64(); err == nil {
} else if f, err := t.Float64(); err == nil {
out[k] = f
} else {
out[k] = v
Expand All @@ -92,8 +92,19 @@ func (v *Vault) Read(path string) map[string]interface{} {
case map[string]interface{}:
if k == "data" {
for x, y := range t {
if z, ok := y.(string); ok {
out[x] = base64.StdEncoding.EncodeToString([]byte(z))
switch t := y.(type) {
case json.Number:
if n, err := t.Int64(); err == nil {
out[k] = n
} else if f, err := t.Float64(); err == nil {
out[k] = f
} else {
out[k] = y
}
case string:
out[x] = base64.StdEncoding.EncodeToString([]byte(t))
default:
fmt.Printf("error reading value at %s, key=%s, type=%T\n", path, k, v)
}
}
}
Expand Down

0 comments on commit d491db4

Please sign in to comment.