test of a lightest formula of code
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
@@ -58,27 +56,8 @@ type StorageResource struct {
|
||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
||||
}
|
||||
|
||||
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(b, dma)
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *StorageResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(b, &m)
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
func (d *StorageResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.STORAGE_RESOURCE, peerID, groups, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
@@ -13,7 +15,11 @@ type storageMongoAccessor struct {
|
||||
|
||||
// New creates a new instance of the storageMongoAccessor
|
||||
func New() *storageMongoAccessor {
|
||||
return &storageMongoAccessor{}
|
||||
return &storageMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -26,16 +32,16 @@ func (sma *storageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, erro
|
||||
|
||||
func (sma *storageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
set.(*StorageResource).ResourceModel = nil
|
||||
return sma.GenericUpdateOne(set, id, sma, &StorageResource{})
|
||||
return sma.GenericUpdateOne(set.(*StorageResource).Trim(), id, sma, &StorageResource{})
|
||||
}
|
||||
|
||||
func (sma *storageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
data.(*StorageResource).ResourceModel = nil
|
||||
return sma.GenericStoreOne(data, sma)
|
||||
return sma.GenericStoreOne(data.(*StorageResource).Trim(), sma)
|
||||
}
|
||||
|
||||
func (sma *storageMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return sma.GenericStoreOne(data, sma)
|
||||
return sma.StoreOne(data)
|
||||
}
|
||||
|
||||
func (sma *storageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
@@ -49,8 +55,10 @@ func (sma *storageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
|
||||
}
|
||||
|
||||
res_mongo.Decode(&storage)
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||
resources, _, err := accessor.Search(nil, sma.GetType())
|
||||
if !storage.VerifyAuth(sma.PeerID, sma.Groups) {
|
||||
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
||||
}
|
||||
resources, _, err := sma.ResourceModelAccessor.Search(nil, sma.GetType())
|
||||
if err == nil && len(resources) > 0 {
|
||||
storage.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
@@ -68,9 +76,11 @@ func (wfa storageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||
resources, _, err := accessor.Search(nil, wfa.GetType())
|
||||
resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType())
|
||||
for _, r := range results {
|
||||
if !r.VerifyAuth(wfa.PeerID, wfa.Groups) {
|
||||
continue
|
||||
}
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
@@ -102,9 +112,11 @@ func (wfa *storageMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||
resources, _, err := accessor.Search(nil, wfa.GetType())
|
||||
resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType())
|
||||
for _, r := range results {
|
||||
if !r.VerifyAuth(wfa.PeerID, wfa.Groups) {
|
||||
continue
|
||||
}
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package storage
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
Reference in New Issue
Block a user