From f54fee24c32465478e2c6fc4cd6fc6bfb44fe096 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Tue, 20 Nov 2018 14:32:50 -0800 Subject: Add upload backend implementation Upload is a seperate API where it takes a binary stream and stores it. The api supports tar.gz file format only. P2: Check if ID is valid before trying upload Add test with an invalid ID Issue-ID: MULTICLOUD-393 Change-Id: Id636a95823a046e1795d3be72d0214e953a8c5fc Signed-off-by: Kiran Kamineni --- src/k8splugin/api/defhandler.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/k8splugin/api/defhandler.go') diff --git a/src/k8splugin/api/defhandler.go b/src/k8splugin/api/defhandler.go index c8c03496..222baaee 100644 --- a/src/k8splugin/api/defhandler.go +++ b/src/k8splugin/api/defhandler.go @@ -18,9 +18,9 @@ package api import ( "encoding/json" - "net/http" - + "io/ioutil" "k8splugin/rb" + "net/http" "github.com/gorilla/mux" ) @@ -72,6 +72,27 @@ func (h rbDefinitionHandler) createHandler(w http.ResponseWriter, r *http.Reques // uploadHandler handles upload of the bundle tar file into the database // Note: This will be implemented in a different patch func (h rbDefinitionHandler) uploadHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + uuid := vars["rbdID"] + + if r.Body == nil { + http.Error(w, "Empty Body", http.StatusBadRequest) + return + } + + inpBytes, err := ioutil.ReadAll(r.Body) + if err != nil { + http.Error(w, "Unable to read body", http.StatusBadRequest) + 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 -- cgit 1.2.3-korg