diff options
author | Ritu Sood <ritu.sood@intel.com> | 2021-08-04 02:41:53 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-08-04 02:41:53 +0000 |
commit | df4c908a455a4e073fc8cb9b37304e164cebe234 (patch) | |
tree | 9a2df5cb1581748bd993efbae901f5a06078b78f /src/k8splugin/internal/db/etcd.go | |
parent | 57745be5310a5f676dcbe656e62d9cfdb8603c74 (diff) | |
parent | 4544d8a6e5e86b082eca9ed605327e58cb3e9d85 (diff) |
Merge "Config List handler added to Config API" into honolulu
Diffstat (limited to 'src/k8splugin/internal/db/etcd.go')
-rw-r--r-- | src/k8splugin/internal/db/etcd.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/k8splugin/internal/db/etcd.go b/src/k8splugin/internal/db/etcd.go index 97771a07..a435b435 100644 --- a/src/k8splugin/internal/db/etcd.go +++ b/src/k8splugin/internal/db/etcd.go @@ -36,6 +36,7 @@ type EtcdConfig struct { // EtcdStore Interface needed for mocking type EtcdStore interface { Get(key string) ([]byte, error) + GetAll(key string) ([][]byte, error) Put(key, value string) error Delete(key string) error } @@ -114,7 +115,7 @@ func (e EtcdClient) Get(key string) ([]byte, error) { } getResp, err := e.cli.Get(context.Background(), key) if err != nil { - return nil, pkgerrors.Errorf("Error getitng etcd entry: %s", err.Error()) + return nil, pkgerrors.Errorf("Error getting etcd entry: %s", err.Error()) } if getResp.Count == 0 { return nil, pkgerrors.Errorf("Key doesn't exist") @@ -122,6 +123,22 @@ func (e EtcdClient) Get(key string) ([]byte, error) { return getResp.Kvs[0].Value, nil } +// GetAll sub values from Etcd DB +func (e EtcdClient) GetAll(key string) ([][]byte, error) { + if e.cli == nil { + return nil, pkgerrors.Errorf("Etcd Client not initialized") + } + getResp, err := e.cli.Get(context.Background(), key, clientv3.WithPrefix()) + if err != nil { + return nil, pkgerrors.Errorf("Error getting etcd entry: %s", err.Error()) + } + result := make([][]byte, 0) + for _, v := range getResp.Kvs { + result = append(result, v.Value) + } + return result, nil +} + // Delete values from Etcd DB func (e EtcdClient) Delete(key string) error { |