From 4c5867f6d5b49fac790bc199046da2d6584b67e7 Mon Sep 17 00:00:00 2001 From: francoispqt Date: Wed, 22 May 2019 13:25:58 +0800 Subject: [PATCH 1/2] fix vault kv version 2 check on version type --- loader/klvault/vaultloader.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/loader/klvault/vaultloader.go b/loader/klvault/vaultloader.go index e6fd6fd4..552348da 100644 --- a/loader/klvault/vaultloader.go +++ b/loader/klvault/vaultloader.go @@ -1,6 +1,7 @@ package klvault import ( + "encoding/json" "errors" "fmt" "net/url" @@ -184,8 +185,12 @@ func (vl *Loader) Load(cs konfig.Values) error { // confirming version exists on metadata and it is an int if m, ok := s.Data["metadata"].(map[string]interface{}); ok { kvData, dataOK := s.Data["data"].(map[string]interface{}) - _, versionOK := m["version"].(int) - if versionOK && dataOK { + _, versionJSONNumberOK := m["version"].(json.Number) + if versionJSONNumberOK && dataOK { + sData = kvData + } + _, versionIntOK := m["version"].(int) + if versionIntOK && dataOK { sData = kvData } } else { From 113e94f2582da0dfd3469092d2dcf97a0bdf9789 Mon Sep 17 00:00:00 2001 From: francoispqt Date: Wed, 22 May 2019 13:36:46 +0800 Subject: [PATCH 2/2] fix kv vault2 check version type is json.Number --- loader/klvault/vaultloader.go | 4 ---- loader/klvault/vaultloader_test.go | 5 +++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/loader/klvault/vaultloader.go b/loader/klvault/vaultloader.go index 552348da..66f546e4 100644 --- a/loader/klvault/vaultloader.go +++ b/loader/klvault/vaultloader.go @@ -189,10 +189,6 @@ func (vl *Loader) Load(cs konfig.Values) error { if versionJSONNumberOK && dataOK { sData = kvData } - _, versionIntOK := m["version"].(int) - if versionIntOK && dataOK { - sData = kvData - } } else { sData = s.Data } diff --git a/loader/klvault/vaultloader_test.go b/loader/klvault/vaultloader_test.go index 31ba03cc..d03ffbd6 100644 --- a/loader/klvault/vaultloader_test.go +++ b/loader/klvault/vaultloader_test.go @@ -1,6 +1,7 @@ package klvault import ( + "encoding/json" "errors" "sync" "testing" @@ -75,7 +76,7 @@ func TestVaultLoader(t *testing.T) { "created_time": "2018-03-22T02:24:06.945319214Z", "deletion_time": "", "destroyed": false, - "version": 1, + "version": json.Number("1"), }, }, LeaseDuration: int(1 * time.Hour / time.Second), @@ -92,7 +93,7 @@ func TestVaultLoader(t *testing.T) { "created_time": "2018-03-22T02:24:06.945319214Z", "deletion_time": "", "destroyed": false, - "version": 1, + "version": json.Number("1"), }, }, LeaseDuration: int(1 * time.Hour / time.Second),