summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/rb/definition.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/rb/definition.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/rb/definition.go')
-rw-r--r--src/k8splugin/rb/definition.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/k8splugin/rb/definition.go b/src/k8splugin/rb/definition.go
index 03fffdda..2d1c2cd0 100644
--- a/src/k8splugin/rb/definition.go
+++ b/src/k8splugin/rb/definition.go
@@ -17,6 +17,8 @@
package rb
import (
+ "bytes"
+ "encoding/base64"
"k8splugin/db"
"log"
@@ -39,6 +41,7 @@ type DefinitionManager interface {
List() ([]Definition, error)
Get(resID string) (Definition, error)
Delete(resID string) error
+ Upload(resID string, inp []byte) error
}
// DefinitionClient implements the DefinitionManager
@@ -63,7 +66,7 @@ func (v *DefinitionClient) Create(def Definition) (Definition, error) {
}
key := v.keyPrefix + def.UUID
- serData, err := db.Serialize(v)
+ serData, err := db.Serialize(def)
if err != nil {
return Definition{}, pkgerrors.Wrap(err, "Serialize Resource Bundle Definition")
}
@@ -133,3 +136,27 @@ func (v *DefinitionClient) Delete(id string) error {
return nil
}
+
+// Upload the contents of resource bundle into database
+func (v *DefinitionClient) Upload(id string, inp []byte) error {
+
+ //ignore the returned data here.
+ _, err := v.Get(id)
+ if err != nil {
+ return pkgerrors.Errorf("Invalid ID provided %s", err.Error())
+ }
+
+ err = isTarGz(bytes.NewBuffer(inp))
+ if err != nil {
+ return pkgerrors.Errorf("Error in file format %s", err.Error())
+ }
+
+ encodedStr := base64.StdEncoding.EncodeToString(inp)
+ key := v.keyPrefix + id + "/content"
+ err = db.DBconn.Create(key, encodedStr)
+ if err != nil {
+ return pkgerrors.Errorf("Error uploading data to db %s", err.Error())
+ }
+
+ return nil
+}