add username to our trip
This commit is contained in:
parent
6681c455d8
commit
fd01f535a1
@ -118,6 +118,7 @@ func InitDaemon(appName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IDTokenClaims struct {
|
type IDTokenClaims struct {
|
||||||
|
UserID string `json:"user_id"`
|
||||||
PeerID string `json:"peer_id"`
|
PeerID string `json:"peer_id"`
|
||||||
Groups []string `json:"groups"`
|
Groups []string `json:"groups"`
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ type Claims struct {
|
|||||||
Session SessionClaims `json:"session"`
|
Session SessionClaims `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractTokenInfo(request http.Request) (string, []string) {
|
func ExtractTokenInfo(request http.Request) (string, string, []string) {
|
||||||
reqToken := request.Header.Get("Authorization")
|
reqToken := request.Header.Get("Authorization")
|
||||||
splitToken := strings.Split(reqToken, "Bearer ")
|
splitToken := strings.Split(reqToken, "Bearer ")
|
||||||
if len(splitToken) < 2 {
|
if len(splitToken) < 2 {
|
||||||
@ -146,17 +147,17 @@ func ExtractTokenInfo(request http.Request) (string, []string) {
|
|||||||
if len(token) > 2 {
|
if len(token) > 2 {
|
||||||
bytes, err := base64.StdEncoding.DecodeString(token[2])
|
bytes, err := base64.StdEncoding.DecodeString(token[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", []string{}
|
return "", "", []string{}
|
||||||
}
|
}
|
||||||
var c Claims
|
var c Claims
|
||||||
err = json.Unmarshal(bytes, &c)
|
err = json.Unmarshal(bytes, &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", []string{}
|
return "", "", []string{}
|
||||||
}
|
}
|
||||||
return c.Session.IDToken.PeerID, c.Session.IDToken.Groups
|
return c.Session.IDToken.UserID, c.Session.IDToken.PeerID, c.Session.IDToken.Groups
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", []string{}
|
return "", "", []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(appName string) {
|
func Init(appName string) {
|
||||||
@ -199,7 +200,7 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
|||||||
If not we will store it
|
If not we will store it
|
||||||
Resource model is the model that will define the structure of the resources
|
Resource model is the model that will define the structure of the resources
|
||||||
*/
|
*/
|
||||||
accessor := (&resource_model.ResourceModel{}).GetAccessor("", []string{}, nil)
|
accessor := (&resource_model.ResourceModel{}).GetAccessor("", "", []string{}, nil)
|
||||||
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
||||||
data, code, _ := accessor.Search(nil, model)
|
data, code, _ := accessor.Search(nil, model)
|
||||||
if code == 404 || len(data) == 0 {
|
if code == 404 || len(data) == 0 {
|
||||||
@ -268,13 +269,14 @@ func GetConfLoader() *onion.Onion {
|
|||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
collection LibDataEnum
|
collection LibDataEnum
|
||||||
|
user string
|
||||||
peerID string
|
peerID string
|
||||||
groups []string
|
groups []string
|
||||||
caller *tools.HTTPCaller
|
caller *tools.HTTPCaller
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRequest(collection LibDataEnum, peerID string, groups []string, caller *tools.HTTPCaller) *Request {
|
func NewRequest(collection LibDataEnum, user string, peerID string, groups []string, caller *tools.HTTPCaller) *Request {
|
||||||
return &Request{collection: collection, peerID: peerID, groups: groups, caller: caller}
|
return &Request{collection: collection, user: user, peerID: peerID, groups: groups, caller: caller}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -292,7 +294,7 @@ func (r *Request) Search(filters *dbs.Filters, word string) (data LibDataShallow
|
|||||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).Search(filters, word)
|
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).Search(filters, word)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -314,7 +316,7 @@ func (r *Request) LoadAll() (data LibDataShallow) {
|
|||||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).LoadAll()
|
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -337,7 +339,7 @@ func (r *Request) LoadOne(id string) (data LibData) {
|
|||||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in LoadOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in LoadOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).LoadOne(id)
|
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadOne(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -362,7 +364,7 @@ func (r *Request) UpdateOne(set map[string]interface{}, id string) (data LibData
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
model := models.Model(r.collection.EnumIndex())
|
model := models.Model(r.collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
|
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -385,7 +387,7 @@ func (r *Request) DeleteOne(id string) (data LibData) {
|
|||||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in DeleteOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in DeleteOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).DeleteOne(id)
|
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).DeleteOne(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -409,7 +411,7 @@ func (r *Request) StoreOne(object map[string]interface{}) (data LibData) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
model := models.Model(r.collection.EnumIndex())
|
model := models.Model(r.collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
|
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -433,7 +435,7 @@ func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
model := models.Model(r.collection.EnumIndex())
|
model := models.Model(r.collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).CopyOne(model.Deserialize(object, model))
|
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).CopyOne(model.Deserialize(object, model))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||||
return
|
return
|
||||||
@ -445,72 +447,72 @@ func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
|
|||||||
// ================ CAST ========================= //
|
// ================ CAST ========================= //
|
||||||
|
|
||||||
func (l *LibData) ToDataResource() *resources.DataResource {
|
func (l *LibData) ToDataResource() *resources.DataResource {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.DATA_RESOURCE {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.DATA_RESOURCE {
|
||||||
return l.Data.(*resources.DataResource)
|
return l.Data.(*resources.DataResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToComputeResource() *resources.ComputeResource {
|
func (l *LibData) ToComputeResource() *resources.ComputeResource {
|
||||||
if l.Data != nil && l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE {
|
if l.Data != nil && l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE {
|
||||||
return l.Data.(*resources.ComputeResource)
|
return l.Data.(*resources.ComputeResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToStorageResource() *resources.StorageResource {
|
func (l *LibData) ToStorageResource() *resources.StorageResource {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.STORAGE_RESOURCE {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.STORAGE_RESOURCE {
|
||||||
return l.Data.(*resources.StorageResource)
|
return l.Data.(*resources.StorageResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToProcessingResource() *resources.ProcessingResource {
|
func (l *LibData) ToProcessingResource() *resources.ProcessingResource {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE {
|
||||||
return l.Data.(*resources.ProcessingResource)
|
return l.Data.(*resources.ProcessingResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToWorkflowResource() *resources.WorkflowResource {
|
func (l *LibData) ToWorkflowResource() *resources.WorkflowResource {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE {
|
||||||
return l.Data.(*resources.WorkflowResource)
|
return l.Data.(*resources.WorkflowResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToPeer() *peer.Peer {
|
func (l *LibData) ToPeer() *peer.Peer {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.PEER {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PEER {
|
||||||
return l.Data.(*peer.Peer)
|
return l.Data.(*peer.Peer)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW {
|
||||||
return l.Data.(*w2.Workflow)
|
return l.Data.(*w2.Workflow)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKSPACE {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKSPACE {
|
||||||
return l.Data.(*workspace.Workspace)
|
return l.Data.(*workspace.Workspace)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||||
return l.Data.(*collaborative_area.CollaborativeArea)
|
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToRule() *rule.Rule {
|
func (l *LibData) ToRule() *rule.Rule {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||||
return l.Data.(*rule.Rule)
|
return l.Data.(*rule.Rule)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION {
|
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION {
|
||||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -26,7 +26,7 @@ func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bo
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
e := *end
|
e := *end
|
||||||
accessor := New(tools.BOOKING, "", nil, nil)
|
accessor := New(tools.BOOKING, "", "", nil, nil)
|
||||||
res, code, err := accessor.Search(&dbs.Filters{
|
res, code, err := accessor.Search(&dbs.Filters{
|
||||||
And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
|
And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
|
||||||
"compute_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
"compute_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||||
@ -53,6 +53,6 @@ func (d *Booking) GetName() string {
|
|||||||
return d.UUID + "_" + d.ExecDate.String()
|
return d.UUID + "_" + d.ExecDate.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Booking) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Booking) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.BOOKING, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.BOOKING, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,14 @@ type bookingMongoAccessor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the bookingMongoAccessor
|
// New creates a new instance of the bookingMongoAccessor
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *bookingMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *bookingMongoAccessor {
|
||||||
return &bookingMongoAccessor{
|
return &bookingMongoAccessor{
|
||||||
AbstractAccessor: utils.AbstractAccessor{
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
Groups: groups, // Set the caller
|
Groups: groups,
|
||||||
|
User: username, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (ao *CollaborativeArea) Clear(peerID string) {
|
|||||||
ao.CollaborativeAreaRule.CreatedAt = time.Now().UTC()
|
ao.CollaborativeAreaRule.CreatedAt = time.Now().UTC()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *CollaborativeArea) VerifyAuth(peerID string, groups []string) bool {
|
func (ao *CollaborativeArea) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||||
if ao.AllowedPeersGroup != nil || config.GetConfig().Whitelist {
|
if ao.AllowedPeersGroup != nil || config.GetConfig().Whitelist {
|
||||||
if grps, ok := ao.AllowedPeersGroup[peerID]; ok || config.GetConfig().Whitelist {
|
if grps, ok := ao.AllowedPeersGroup[peerID]; ok || config.GetConfig().Whitelist {
|
||||||
fmt.Println("grps", grps, "ok", ok, "config.GetConfig().Whitelist", config.GetConfig().Whitelist)
|
fmt.Println("grps", grps, "ok", ok, "config.GetConfig().Whitelist", config.GetConfig().Whitelist)
|
||||||
@ -87,8 +87,8 @@ func (ao *CollaborativeArea) VerifyAuth(peerID string, groups []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *CollaborativeArea) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *CollaborativeArea) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.COLLABORATIVE_AREA, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.COLLABORATIVE_AREA, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *CollaborativeArea) Trim() *CollaborativeArea {
|
func (d *CollaborativeArea) Trim() *CollaborativeArea {
|
||||||
|
@ -26,7 +26,7 @@ type collaborativeAreaMongoAccessor struct {
|
|||||||
ruleAccessor utils.Accessor
|
ruleAccessor utils.Accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *collaborativeAreaMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *collaborativeAreaMongoAccessor {
|
||||||
return &collaborativeAreaMongoAccessor{
|
return &collaborativeAreaMongoAccessor{
|
||||||
AbstractAccessor: utils.AbstractAccessor{
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
@ -35,10 +35,10 @@ func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCal
|
|||||||
Groups: groups, // Set the caller
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
workspaceAccessor: (&workspace.Workspace{}).GetAccessor(peerID, groups, nil),
|
workspaceAccessor: (&workspace.Workspace{}).GetAccessor(username, peerID, groups, nil),
|
||||||
workflowAccessor: (&w.Workflow{}).GetAccessor(peerID, groups, nil),
|
workflowAccessor: (&w.Workflow{}).GetAccessor(username, peerID, groups, nil),
|
||||||
peerAccessor: (&peer.Peer{}).GetAccessor(peerID, groups, nil),
|
peerAccessor: (&peer.Peer{}).GetAccessor(username, peerID, groups, nil),
|
||||||
ruleAccessor: (&rule.Rule{}).GetAccessor(peerID, groups, nil),
|
ruleAccessor: (&rule.Rule{}).GetAccessor(username, peerID, groups, nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,6 @@ func (r *Rule) GenerateID() {
|
|||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Rule) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Rule) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.RULE, peerID, groups, caller)
|
return New(tools.RULE, username, peerID, groups, caller)
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,14 @@ type ruleMongoAccessor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the ruleMongoAccessor
|
// New creates a new instance of the ruleMongoAccessor
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *ruleMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *ruleMongoAccessor {
|
||||||
return &ruleMongoAccessor{
|
return &ruleMongoAccessor{
|
||||||
AbstractAccessor: utils.AbstractAccessor{
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
Groups: groups, // Set the caller
|
Groups: groups, // Set the caller
|
||||||
|
User: username,
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ type ShallowCollaborativeArea struct {
|
|||||||
Rules []string `json:"rules,omitempty" bson:"rules,omitempty"`
|
Rules []string `json:"rules,omitempty" bson:"rules,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ShallowCollaborativeArea) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ShallowCollaborativeArea) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.COLLABORATIVE_AREA, peerID, groups, caller)
|
return New(tools.COLLABORATIVE_AREA, username, peerID, groups, caller)
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,14 @@ type shallowSharedWorkspaceMongoAccessor struct {
|
|||||||
utils.AbstractAccessor
|
utils.AbstractAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *shallowSharedWorkspaceMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *shallowSharedWorkspaceMongoAccessor {
|
||||||
return &shallowSharedWorkspaceMongoAccessor{
|
return &shallowSharedWorkspaceMongoAccessor{
|
||||||
AbstractAccessor: utils.AbstractAccessor{
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
Groups: groups, // Set the caller
|
User: username, // Set the caller
|
||||||
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (ao *Peer) RemoveExecution(exec PeerExecution) {
|
|||||||
|
|
||||||
// IsMySelf checks if the peer is the local peer
|
// IsMySelf checks if the peer is the local peer
|
||||||
func (ao *Peer) IsMySelf() (bool, string) {
|
func (ao *Peer) IsMySelf() (bool, string) {
|
||||||
d, code, err := New(tools.PEER, "", nil, nil).Search(nil, SELF.String())
|
d, code, err := New(tools.PEER, "", "", nil, nil).Search(nil, SELF.String())
|
||||||
if code != 200 || err != nil || len(d) == 0 {
|
if code != 200 || err != nil || len(d) == 0 {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt tools.DataTy
|
|||||||
p.UUID = peerID
|
p.UUID = peerID
|
||||||
return cache.LaunchPeerExecution(peerID, dataID, dt, method, body, caller) // Launch the execution on the peer through the cache
|
return cache.LaunchPeerExecution(peerID, dataID, dt, method, body, caller) // Launch the execution on the peer through the cache
|
||||||
}
|
}
|
||||||
func (d *Peer) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Peer) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New(tools.PEER, peerID, groups, caller) // Create a new instance of the accessor
|
data := New(tools.PEER, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,13 @@ func NewShallow() *peerMongoAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *peerMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *peerMongoAccessor {
|
||||||
return &peerMongoAccessor{
|
return &peerMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
|
User: username,
|
||||||
Groups: groups, // Set the caller
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
|
@ -23,8 +23,8 @@ type ComputeResource struct {
|
|||||||
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ComputeResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ComputeResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New[*ComputeResource](tools.COMPUTE_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &ComputeResource{} })
|
return New[*ComputeResource](tools.COMPUTE_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &ComputeResource{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPU is a struct that represents a CPU
|
// CPU is a struct that represents a CPU
|
||||||
|
@ -37,6 +37,6 @@ type DataResource struct {
|
|||||||
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *DataResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New[*DataResource](tools.DATA_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor
|
return New[*DataResource](tools.DATA_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,6 @@ type ProcessingResource struct {
|
|||||||
Expose []Expose `bson:"expose,omitempty" json:"expose,omitempty"` // Expose is the execution
|
Expose []Expose `bson:"expose,omitempty" json:"expose,omitempty"` // Expose is the execution
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ProcessingResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ProcessingResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New[*ProcessingResource](tools.PROCESSING_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &ProcessingResource{} }) // Create a new instance of the accessor
|
return New[*ProcessingResource](tools.PROCESSING_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &ProcessingResource{} }) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func (r *ResourceSet) Clear() {
|
|||||||
r.WorkflowResources = nil
|
r.WorkflowResources = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ResourceSet) Fill(peerID string, groups []string) {
|
func (r *ResourceSet) Fill(username string, peerID string, groups []string) {
|
||||||
for k, v := range map[utils.DBObject][]string{
|
for k, v := range map[utils.DBObject][]string{
|
||||||
(&DataResource{}): r.Datas,
|
(&DataResource{}): r.Datas,
|
||||||
(&ComputeResource{}): r.Computes,
|
(&ComputeResource{}): r.Computes,
|
||||||
@ -47,7 +47,7 @@ func (r *ResourceSet) Fill(peerID string, groups []string) {
|
|||||||
(&WorkflowResource{}): r.Workflows,
|
(&WorkflowResource{}): r.Workflows,
|
||||||
} {
|
} {
|
||||||
for _, id := range v {
|
for _, id := range v {
|
||||||
d, _, e := k.GetAccessor(peerID, groups, nil).LoadOne(id)
|
d, _, e := k.GetAccessor(username, peerID, groups, nil).LoadOne(id)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
switch k.(type) {
|
switch k.(type) {
|
||||||
case *DataResource:
|
case *DataResource:
|
||||||
|
@ -14,14 +14,15 @@ type resourceMongoAccessor[T ResourceInterface] struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the computeMongoAccessor
|
// New creates a new instance of the computeMongoAccessor
|
||||||
func New[T ResourceInterface](t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller, g func() utils.DBObject) *resourceMongoAccessor[T] {
|
func New[T ResourceInterface](t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller, g func() utils.DBObject) *resourceMongoAccessor[T] {
|
||||||
return &resourceMongoAccessor[T]{
|
return &resourceMongoAccessor[T]{
|
||||||
AbstractAccessor: utils.AbstractAccessor{
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
ResourceModelAccessor: resource_model.New(),
|
ResourceModelAccessor: resource_model.New(),
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
Groups: groups, // Set the caller
|
User: username, // Set the caller
|
||||||
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
generateData: g,
|
generateData: g,
|
||||||
|
@ -38,7 +38,7 @@ type AbstractResource struct {
|
|||||||
Currency string `json:"currency,omitempty" bson:"currency,omitempty"` // Currency is the currency of the price
|
Currency string `json:"currency,omitempty" bson:"currency,omitempty"` // Currency is the currency of the price
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *AbstractResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (ao *AbstractResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ func (abs *AbstractResource) SetResourceModel(model *ResourceModel) {
|
|||||||
abs.ResourceModel = model
|
abs.ResourceModel = model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abs *AbstractResource) VerifyAuth(peerID string, groups []string) bool {
|
func (abs *AbstractResource) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||||
if grps, ok := abs.AllowedPeersGroup[peerID]; ok || config.GetConfig().Whitelist {
|
if grps, ok := abs.AllowedPeersGroup[peerID]; ok || config.GetConfig().Whitelist {
|
||||||
if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) {
|
if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) {
|
||||||
return true
|
return true
|
||||||
@ -135,16 +135,17 @@ func (d *ResourceModel) GetName() string {
|
|||||||
return d.UUID
|
return d.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abs *ResourceModel) VerifyAuth(peerID string, groups []string) bool {
|
func (abs *ResourceModel) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ResourceModel) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ResourceModel) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return &ResourceModelMongoAccessor{
|
return &ResourceModelMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
utils.AbstractAccessor{
|
||||||
Type: tools.RESOURCE_MODEL,
|
Type: tools.RESOURCE_MODEL,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
Groups: groups,
|
Groups: groups,
|
||||||
|
User: username,
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,6 @@ type StorageResource struct {
|
|||||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *StorageResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *StorageResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New[*StorageResource](tools.STORAGE_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor
|
return New[*StorageResource](tools.STORAGE_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,6 @@ type WorkflowResource struct {
|
|||||||
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"` // WorkflowID is the ID of the native workflow
|
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"` // WorkflowID is the ID of the native workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *WorkflowResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New[*WorkflowResource](tools.WORKFLOW_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &WorkflowResource{} }) // Create a new instance of the accessor
|
return New[*WorkflowResource](tools.WORKFLOW_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &WorkflowResource{} }) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (ao *AbstractObject) UpToDate() {
|
|||||||
// ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
|
// ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *AbstractObject) VerifyAuth(peerID string, groups []string) bool {
|
func (ao *AbstractObject) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,15 +82,19 @@ func (dma *AbstractObject) Serialize(obj DBObject) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AbstractAccessor struct {
|
type AbstractAccessor struct {
|
||||||
Logger zerolog.Logger // Logger is the logger of the accessor, it's a specilized logger for the accessor
|
Logger zerolog.Logger // Logger is the logger of the accessor, it's a specilized logger for the accessor
|
||||||
Type tools.DataType // Type is the data type of the accessor
|
Type tools.DataType // Type is the data type of the accessor
|
||||||
Caller *tools.HTTPCaller // Caller is the http caller of the accessor (optionnal) only need in a peer connection
|
Caller *tools.HTTPCaller // Caller is the http caller of the accessor (optionnal) only need in a peer connection
|
||||||
PeerID string // PeerID is the id of the peer
|
PeerID string // PeerID is the id of the peer
|
||||||
Groups []string // Groups is the list of groups that can access the accessor
|
Groups []string // Groups is the list of groups that can access the accessor
|
||||||
|
User string // User is the user that is using the accessor
|
||||||
ResourceModelAccessor Accessor
|
ResourceModelAccessor Accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dma *AbstractAccessor) GetUser() string {
|
||||||
|
return dma.User
|
||||||
|
}
|
||||||
|
|
||||||
func (dma *AbstractAccessor) GetPeerID() string {
|
func (dma *AbstractAccessor) GetPeerID() string {
|
||||||
return dma.PeerID
|
return dma.PeerID
|
||||||
}
|
}
|
||||||
@ -128,7 +132,7 @@ func GenericStoreOne(data DBObject, a Accessor) (DBObject, int, error) {
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if !data.VerifyAuth(a.GetPeerID(), a.GetGroups()) {
|
if !data.VerifyAuth(a.GetUser(), a.GetPeerID(), a.GetGroups()) {
|
||||||
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
if cursor, _, _ := a.Search(&f, ""); len(cursor) > 0 {
|
if cursor, _, _ := a.Search(&f, ""); len(cursor) > 0 {
|
||||||
@ -153,7 +157,7 @@ func GenericDeleteOne(id string, a Accessor) (DBObject, int, error) {
|
|||||||
a.GetLogger().Error().Msg("Could not retrieve " + id + " to db. Error: " + err.Error())
|
a.GetLogger().Error().Msg("Could not retrieve " + id + " to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
if !res.VerifyAuth(a.GetPeerID(), a.GetGroups()) {
|
if !res.VerifyAuth(a.GetUser(), a.GetPeerID(), a.GetGroups()) {
|
||||||
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
_, code, err = mongo.MONGOService.DeleteOne(id, a.GetType().String())
|
_, code, err = mongo.MONGOService.DeleteOne(id, a.GetType().String())
|
||||||
@ -171,7 +175,7 @@ func GenericUpdateOne(set DBObject, id string, a Accessor, new DBObject) (DBObje
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, c, err
|
return nil, c, err
|
||||||
}
|
}
|
||||||
if !r.VerifyAuth(a.GetPeerID(), a.GetGroups()) {
|
if !r.VerifyAuth(a.GetUser(), a.GetPeerID(), a.GetGroups()) {
|
||||||
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
change := set.Serialize(set) // get the changes
|
change := set.Serialize(set) // get the changes
|
||||||
@ -196,7 +200,7 @@ func GenericLoadOne[T DBObject](id string, f func(DBObject) (DBObject, int, erro
|
|||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
res_mongo.Decode(&data)
|
res_mongo.Decode(&data)
|
||||||
if !data.VerifyAuth(a.GetPeerID(), a.GetGroups()) {
|
if !data.VerifyAuth(a.GetUser(), a.GetPeerID(), a.GetGroups()) {
|
||||||
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
return nil, 403, errors.New("You are not allowed to access this collaborative area")
|
||||||
}
|
}
|
||||||
return f(data)
|
return f(data)
|
||||||
@ -213,7 +217,7 @@ func genericLoadAll[T DBObject](res *mgb.Cursor, code int, err error, f func(DBO
|
|||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if !r.VerifyAuth(a.GetPeerID(), a.GetGroups()) {
|
if !r.VerifyAuth(a.GetUser(), a.GetPeerID(), a.GetGroups()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
objs = append(objs, f(r))
|
objs = append(objs, f(r))
|
||||||
|
@ -21,15 +21,16 @@ type DBObject interface {
|
|||||||
GetID() string
|
GetID() string
|
||||||
GetName() string
|
GetName() string
|
||||||
UpToDate()
|
UpToDate()
|
||||||
VerifyAuth(PeerID string, groups []string) bool
|
VerifyAuth(username string, PeerID string, groups []string) bool
|
||||||
Deserialize(j map[string]interface{}, obj DBObject) DBObject
|
Deserialize(j map[string]interface{}, obj DBObject) DBObject
|
||||||
Serialize(obj DBObject) map[string]interface{}
|
Serialize(obj DBObject) map[string]interface{}
|
||||||
GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) Accessor
|
GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) Accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessor is an interface that defines the basic methods for an Accessor
|
// Accessor is an interface that defines the basic methods for an Accessor
|
||||||
type Accessor interface {
|
type Accessor interface {
|
||||||
GetType() tools.DataType
|
GetType() tools.DataType
|
||||||
|
GetUser() string
|
||||||
GetPeerID() string
|
GetPeerID() string
|
||||||
GetGroups() []string
|
GetGroups() []string
|
||||||
GetLogger() *zerolog.Logger
|
GetLogger() *zerolog.Logger
|
||||||
|
@ -98,15 +98,15 @@ type Workflow struct {
|
|||||||
AbstractWorkflow // AbstractWorkflow contains the basic fields of a workflow
|
AbstractWorkflow // AbstractWorkflow contains the basic fields of a workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *Workflow) VerifyAuth(peerID string, groups []string) bool {
|
func (ao *Workflow) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||||
isAuthorized := false
|
isAuthorized := false
|
||||||
if len(ao.Shared) > 0 {
|
if len(ao.Shared) > 0 {
|
||||||
for _, shared := range ao.Shared {
|
for _, shared := range ao.Shared {
|
||||||
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, peerID, groups, nil).LoadOne(shared)
|
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, username, peerID, groups, nil).LoadOne(shared)
|
||||||
if code != 200 || shared == nil {
|
if code != 200 || shared == nil {
|
||||||
isAuthorized = false
|
isAuthorized = false
|
||||||
}
|
}
|
||||||
isAuthorized = shared.VerifyAuth(peerID, groups)
|
isAuthorized = shared.VerifyAuth(username, peerID, groups)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
isAuthorized = true
|
isAuthorized = true
|
||||||
@ -122,7 +122,7 @@ func (wfa *Workflow) CheckBooking(caller *tools.HTTPCaller) (bool, error) {
|
|||||||
if wfa.Graph == nil { // no graph no booking
|
if wfa.Graph == nil { // no graph no booking
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
accessor := (&resources.ComputeResource{}).GetAccessor("", []string{}, caller)
|
accessor := (&resources.ComputeResource{}).GetAccessor("", "", []string{}, caller)
|
||||||
for _, link := range wfa.Graph.Links {
|
for _, link := range wfa.Graph.Links {
|
||||||
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a compute and a resource
|
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a compute and a resource
|
||||||
dc, code, _ := accessor.LoadOne(dc_id)
|
dc, code, _ := accessor.LoadOne(dc_id)
|
||||||
@ -143,6 +143,6 @@ func (wfa *Workflow) CheckBooking(caller *tools.HTTPCaller) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Workflow) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Workflow) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.WORKFLOW, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.WORKFLOW, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
type WorkflowHistory struct{ Workflow }
|
type WorkflowHistory struct{ Workflow }
|
||||||
|
|
||||||
func (d *WorkflowHistory) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowHistory) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.WORKSPACE_HISTORY, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.WORKSPACE_HISTORY, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
func (r *WorkflowHistory) GenerateID() {
|
func (r *WorkflowHistory) GenerateID() {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
|
@ -30,16 +30,17 @@ type workflowMongoAccessor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the workflowMongoAccessor
|
// New creates a new instance of the workflowMongoAccessor
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *workflowMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *workflowMongoAccessor {
|
||||||
return &workflowMongoAccessor{
|
return &workflowMongoAccessor{
|
||||||
computeResourceAccessor: (&resources.ComputeResource{}).GetAccessor(peerID, groups, nil),
|
computeResourceAccessor: (&resources.ComputeResource{}).GetAccessor(username, peerID, groups, nil),
|
||||||
collaborativeAreaAccessor: (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(peerID, groups, nil),
|
collaborativeAreaAccessor: (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(username, peerID, groups, nil),
|
||||||
executionAccessor: (&workflow_execution.WorkflowExecution{}).GetAccessor(peerID, groups, nil),
|
executionAccessor: (&workflow_execution.WorkflowExecution{}).GetAccessor(username, peerID, groups, nil),
|
||||||
workspaceAccessor: (&workspace.Workspace{}).GetAccessor(peerID, groups, nil),
|
workspaceAccessor: (&workspace.Workspace{}).GetAccessor(username, peerID, groups, nil),
|
||||||
AbstractAccessor: utils.AbstractAccessor{
|
AbstractAccessor: utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
|
User: username,
|
||||||
Groups: groups, // Set the caller
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@ func TestStoreOneWorkflow(t *testing.T) {
|
|||||||
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
||||||
}
|
}
|
||||||
|
|
||||||
wma := New(tools.WORKFLOW, "", nil, nil)
|
wma := New(tools.WORKFLOW, "", "", nil, nil)
|
||||||
id, _, _ := wma.StoreOne(&w)
|
id, _, _ := wma.StoreOne(&w)
|
||||||
|
|
||||||
assert.NotEmpty(t, id)
|
assert.NotEmpty(t, id)
|
||||||
@ -24,7 +24,7 @@ func TestLoadOneWorkflow(t *testing.T) {
|
|||||||
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
||||||
}
|
}
|
||||||
|
|
||||||
wma := New(tools.WORKFLOW, "", nil, nil)
|
wma := New(tools.WORKFLOW, "", "", nil, nil)
|
||||||
new_w, _, _ := wma.StoreOne(&w)
|
new_w, _, _ := wma.StoreOne(&w)
|
||||||
assert.Equal(t, w, new_w)
|
assert.Equal(t, w, new_w)
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,6 @@ func (d *WorkflowExecution) GetName() string {
|
|||||||
return d.UUID + "_" + d.ExecDate.String()
|
return d.UUID + "_" + d.ExecDate.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *WorkflowExecution) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowExecution) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.WORKFLOW_EXECUTION, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.WORKFLOW_EXECUTION, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,14 @@ type workflowExecutionMongoAccessor struct {
|
|||||||
utils.AbstractAccessor
|
utils.AbstractAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *workflowExecutionMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *workflowExecutionMongoAccessor {
|
||||||
return &workflowExecutionMongoAccessor{
|
return &workflowExecutionMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
Groups: groups, // Set the caller
|
User: username, // Set the caller
|
||||||
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,18 @@ type Workspace struct {
|
|||||||
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
|
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Workspace) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Workspace) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.WORKSPACE, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.WORKSPACE, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *Workspace) VerifyAuth(peerID string, groups []string) bool {
|
func (ao *Workspace) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||||
fmt.Println("Workspace.VerifyAuth", ao.Shared)
|
fmt.Println("Workspace.VerifyAuth", ao.Shared)
|
||||||
if ao.Shared != "" {
|
if ao.Shared != "" {
|
||||||
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, peerID, groups, nil).LoadOne(ao.Shared)
|
shared, code, _ := shallow_collaborative_area.New(tools.COLLABORATIVE_AREA, username, peerID, groups, nil).LoadOne(ao.Shared)
|
||||||
if code != 200 || shared == nil {
|
if code != 200 || shared == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return shared.VerifyAuth(peerID, groups)
|
return shared.VerifyAuth(username, peerID, groups)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
type WorkspaceHistory struct{ Workspace }
|
type WorkspaceHistory struct{ Workspace }
|
||||||
|
|
||||||
func (d *WorkspaceHistory) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkspaceHistory) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||||
return New(tools.WORKFLOW_HISTORY, peerID, groups, caller) // Create a new instance of the accessor
|
return New(tools.WORKFLOW_HISTORY, username, peerID, groups, caller) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
func (r *WorkspaceHistory) GenerateID() {
|
func (r *WorkspaceHistory) GenerateID() {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
|
@ -18,12 +18,13 @@ type workspaceMongoAccessor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the workspaceMongoAccessor
|
// New creates a new instance of the workspaceMongoAccessor
|
||||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *workspaceMongoAccessor {
|
func New(t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller) *workspaceMongoAccessor {
|
||||||
return &workspaceMongoAccessor{
|
return &workspaceMongoAccessor{
|
||||||
utils.AbstractAccessor{
|
utils.AbstractAccessor{
|
||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Caller: caller,
|
Caller: caller,
|
||||||
PeerID: peerID,
|
PeerID: peerID,
|
||||||
|
User: username,
|
||||||
Groups: groups, // Set the caller
|
Groups: groups, // Set the caller
|
||||||
Type: t,
|
Type: t,
|
||||||
},
|
},
|
||||||
@ -86,21 +87,21 @@ func (a *workspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, i
|
|||||||
|
|
||||||
func (a *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*Workspace](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
return utils.GenericLoadOne[*Workspace](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
d.(*Workspace).Fill(a.PeerID, a.Groups)
|
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
|
||||||
return d, 200, nil
|
return d, 200, nil
|
||||||
}, a)
|
}, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
func (a *workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||||
return utils.GenericLoadAll[*Workspace](func(d utils.DBObject) utils.ShallowDBObject {
|
return utils.GenericLoadAll[*Workspace](func(d utils.DBObject) utils.ShallowDBObject {
|
||||||
d.(*Workspace).Fill(a.PeerID, a.Groups)
|
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
|
||||||
return d
|
return d
|
||||||
}, a)
|
}, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||||
return utils.GenericSearch[*Workspace](filters, search, (&Workspace{}).GetObjectFilters(search), func(d utils.DBObject) utils.ShallowDBObject {
|
return utils.GenericSearch[*Workspace](filters, search, (&Workspace{}).GetObjectFilters(search), func(d utils.DBObject) utils.ShallowDBObject {
|
||||||
d.(*Workspace).Fill(a.PeerID, a.Groups)
|
d.(*Workspace).Fill(a.GetUser(), a.PeerID, a.Groups)
|
||||||
return d
|
return d
|
||||||
}, a)
|
}, a)
|
||||||
}
|
}
|
||||||
@ -114,7 +115,7 @@ func (a *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
shallow := &shallow_collaborative_area.ShallowCollaborativeArea{}
|
shallow := &shallow_collaborative_area.ShallowCollaborativeArea{}
|
||||||
access := (shallow).GetAccessor(a.PeerID, a.Groups, nil)
|
access := (shallow).GetAccessor(a.GetUser(), a.PeerID, a.Groups, nil)
|
||||||
res, code, _ := access.LoadOne(realData.Shared)
|
res, code, _ := access.LoadOne(realData.Shared)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user