aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/defhandler.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-11-20 14:32:50 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-11-21 11:36:41 -0800
commitf54fee24c32465478e2c6fc4cd6fc6bfb44fe096 (patch)
treeebe95c5f51972d2cacb8c304abace2423b7952db /src/k8splugin/api/defhandler.go
parent3f780f7973081903f1ab6ea01a855fb6c5512a48 (diff)
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 <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/api/defhandler.go')
-rw-r--r--src/k8splugin/api/defhandler.go25
1 files changed, 23 insertions, 2 deletions
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