From 412d02f7bd53a9e810be2c17d1c391c9bc6dda13 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Thu, 18 Jul 2019 14:49:25 -0700 Subject: Add list api for profiles Add a list api for profiles for a specific definition and version. GET /v1/rb/definition/name/version/profile will list all the profiles. Issue-ID: MULTICLOUD-730 Change-Id: If1b8e6910c276a0f7139ab13340721c6ec8a49e8 Signed-off-by: Kiran Kamineni --- src/k8splugin/internal/rb/profile.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/k8splugin/internal/rb/profile.go') diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go index 64449ebd..49768d4b 100644 --- a/src/k8splugin/internal/rb/profile.go +++ b/src/k8splugin/internal/rb/profile.go @@ -20,6 +20,7 @@ import ( "bytes" "encoding/base64" "encoding/json" + "log" "path/filepath" "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" @@ -44,6 +45,7 @@ type Profile struct { type ProfileManager interface { Create(def Profile) (Profile, error) Get(rbName, rbVersion, prName string) (Profile, error) + List(rbName, rbVersion string) ([]Profile, error) Delete(rbName, rbVersion, prName string) error Upload(rbName, rbVersion, prName string, inp []byte) error } @@ -148,6 +150,38 @@ func (v *ProfileClient) Get(rbName, rbVersion, prName string) (Profile, error) { return Profile{}, pkgerrors.New("Error getting Resource Bundle Profile") } +// List returns the Resource Bundle Profile for corresponding ID +func (v *ProfileClient) List(rbName, rbVersion string) ([]Profile, error) { + + //Get all profiles + dbres, err := db.DBconn.ReadAll(v.storeName, v.tagMeta) + if err != nil || len(dbres) == 0 { + return []Profile{}, pkgerrors.Wrap(err, "No Profiles Found") + } + + var results []Profile + for key, value := range dbres { + //value is a byte array + if value != nil { + pr := Profile{} + err = db.DBconn.Unmarshal(value, &pr) + if err != nil { + log.Printf("[Profile] Error: %s Unmarshaling value for: %s", err.Error(), key) + continue + } + if pr.RBName == rbName && pr.RBVersion == rbVersion { + results = append(results, pr) + } + } + } + + if len(results) == 0 { + return results, pkgerrors.New("No Profiles Found for Definition and Version") + } + + return results, nil +} + // Delete the Resource Bundle Profile from database func (v *ProfileClient) Delete(rbName, rbVersion, prName string) error { key := ProfileKey{ -- cgit 1.2.3-korg