From b2b175eae0f4e8b5b0cb9ccbeeca1e98065feeb5 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Fri, 15 Mar 2019 15:18:12 -0700 Subject: Update definition and profile to latest spec Bringing all the definition and profile code upto the latest spec. Integrated the end to end instance code changes that were made. P9: Added updated plugin.sh with updated uri paths based on spec Issue-ID: MULTICLOUD-291 Change-Id: Id6e3c6bc2cd02cfb7005e203ccf03e0793b97e95 Signed-off-by: Kiran Kamineni --- src/k8splugin/api/profilehandler.go | 57 +++++++++++-------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) (limited to 'src/k8splugin/api/profilehandler.go') diff --git a/src/k8splugin/api/profilehandler.go b/src/k8splugin/api/profilehandler.go index 267dae0e..2c15a440 100644 --- a/src/k8splugin/api/profilehandler.go +++ b/src/k8splugin/api/profilehandler.go @@ -36,9 +36,9 @@ type rbProfileHandler struct { // createHandler handles creation of the definition entry in the database func (h rbProfileHandler) createHandler(w http.ResponseWriter, r *http.Request) { - var v rb.Profile + var p rb.Profile - err := json.NewDecoder(r.Body).Decode(&v) + err := json.NewDecoder(r.Body).Decode(&p) switch { case err == io.EOF: http.Error(w, "Empty body", http.StatusBadRequest) @@ -49,18 +49,12 @@ func (h rbProfileHandler) createHandler(w http.ResponseWriter, r *http.Request) } // Name is required. - if v.Name == "" { + if p.Name == "" { http.Error(w, "Missing name in POST request", http.StatusBadRequest) return } - // Definition ID is required - if v.RBDID == "" { - http.Error(w, "Missing Resource Bundle Definition ID in POST request", http.StatusBadRequest) - return - } - - ret, err := h.client.Create(v) + ret, err := h.client.Create(p) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -78,7 +72,9 @@ func (h rbProfileHandler) createHandler(w http.ResponseWriter, r *http.Request) // uploadHandler handles upload of the bundle tar file into the database func (h rbProfileHandler) uploadHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - uuid := vars["rbpID"] + rbName := vars["rbname"] + rbVersion := vars["rbversion"] + prName := vars["prname"] inpBytes, err := ioutil.ReadAll(r.Body) if err != nil { @@ -91,37 +87,12 @@ func (h rbProfileHandler) uploadHandler(w http.ResponseWriter, r *http.Request) return } - err = h.client.Upload(uuid, inpBytes) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusOK) -} - -// listHandler handles GET (list) operations on the endpoint -// Returns a list of rb.Definitions -func (h rbProfileHandler) listHandler(w http.ResponseWriter, r *http.Request) { - ret, err := h.client.List() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - err = json.NewEncoder(w).Encode(ret) + err = h.client.Upload(rbName, rbVersion, prName, inpBytes) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } -} -// helpHandler handles GET (list) operations on the endpoint -// Returns a list of rb.Definitions -func (h rbProfileHandler) helpHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/html") w.WriteHeader(http.StatusOK) } @@ -129,9 +100,11 @@ func (h rbProfileHandler) helpHandler(w http.ResponseWriter, r *http.Request) { // Returns a rb.Definition func (h rbProfileHandler) getHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - id := vars["rbpID"] + rbName := vars["rbname"] + rbVersion := vars["rbversion"] + prName := vars["prname"] - ret, err := h.client.Get(id) + ret, err := h.client.Get(rbName, rbVersion, prName) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -149,9 +122,11 @@ func (h rbProfileHandler) getHandler(w http.ResponseWriter, r *http.Request) { // deleteHandler handles DELETE operations on a particular bundle definition id func (h rbProfileHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - id := vars["rbpID"] + rbName := vars["rbname"] + rbVersion := vars["rbversion"] + prName := vars["prname"] - err := h.client.Delete(id) + err := h.client.Delete(rbName, rbVersion, prName) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return -- cgit 1.2.3-korg