light modification

This commit is contained in:
mr
2025-01-23 08:35:28 +01:00
parent 0e798dac50
commit 99693d8ec0
10 changed files with 21 additions and 33 deletions

View File

@@ -1,7 +1,6 @@
package collaborative_area
import (
"fmt"
"slices"
"time"
@@ -72,7 +71,6 @@ func (ao *CollaborativeArea) Clear(peerID string) {
func (ao *CollaborativeArea) VerifyAuth(request *tools.APIRequest) bool {
if (ao.AllowedPeersGroup != nil || config.GetConfig().Whitelist) && request != nil {
if grps, ok := ao.AllowedPeersGroup[request.PeerID]; ok || config.GetConfig().Whitelist {
fmt.Println("grps", grps, "ok", ok, "config.GetConfig().Whitelist", config.GetConfig().Whitelist)
if slices.Contains(grps, "*") || (!ok && config.GetConfig().Whitelist) {
return true
}

View File

@@ -1,8 +1,6 @@
package resources
import (
"fmt"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
@@ -38,7 +36,6 @@ func (r *ResourceSet) Fill(request *tools.APIRequest) {
(&ProcessingResource{}): r.Processings,
(&WorkflowResource{}): r.Workflows,
} {
fmt.Println(len(v), k)
for _, id := range v {
d, _, e := k.GetAccessor(request).LoadOne(id)
if e == nil {

View File

@@ -1,7 +1,6 @@
package resources
import (
"fmt"
"slices"
"cloud.o-forge.io/core/oc-lib/config"
@@ -101,17 +100,13 @@ func (abs *AbstractIntanciatedResource[T]) VerifyAuth(request *tools.APIRequest)
func verifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.APIRequest) []T {
instances := []T{}
fmt.Println("baseInstance", baseInstance)
for _, instance := range baseInstance {
_, peerGroups := instance.GetPeerGroups()
fmt.Println("peerGroups", peerGroups, request)
for _, peers := range peerGroups {
if request == nil {
continue
}
fmt.Println("request.PeerID]", peers[request.PeerID])
if grps, ok := peers[request.PeerID]; ok || config.GetConfig().Whitelist {
fmt.Println("grps", grps, request.Groups)
if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) {
instances = append(instances, instance)
continue
@@ -160,7 +155,6 @@ func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []strin
func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string) {
groups := []map[string][]string{}
partners := []ResourcePartnerITF{}
fmt.Println("ri.Partnerships", ri.Partnerships)
for _, p := range ri.Partnerships {
partners = append(partners, p)
groups = append(groups, p.GetPeerGroups())

View File

@@ -1,8 +1,6 @@
package workflow
import (
"fmt"
"cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/logs"
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
@@ -91,7 +89,6 @@ func (a *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *t
// UpdateOne updates a workflow in the database
func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
// avoid the update if the schedule is the same
fmt.Println(len(set.(*Workflow).Graph.Links))
res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{})
if code != 200 {
return nil, code, err

View File

@@ -13,11 +13,24 @@ import (
type workflowExecutionMongoAccessor struct {
utils.AbstractAccessor
shallow bool
}
func newShallowAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor {
return &workflowExecutionMongoAccessor{
shallow: true,
AbstractAccessor: utils.AbstractAccessor{
Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
Request: request,
Type: tools.WORKFLOW_EXECUTION,
},
}
}
func NewAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor {
return &workflowExecutionMongoAccessor{
utils.AbstractAccessor{
shallow: false,
AbstractAccessor: utils.AbstractAccessor{
Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
Request: request,
Type: tools.WORKFLOW_EXECUTION,
@@ -43,13 +56,13 @@ func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.D
func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
return utils.GenericLoadOne[*WorkflowExecutions](id, func(d utils.DBObject) (utils.DBObject, int, error) {
if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
utils.GenericDeleteOne(d.GetID(), a)
if d.(*WorkflowExecutions).State == enum.DRAFT && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
return nil, 404, errors.New("not found")
}
if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
if d.(*WorkflowExecutions).State == enum.SCHEDULED && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
d.(*WorkflowExecutions).State = enum.FORGOTTEN
utils.GenericRawUpdateOne(d, id, a)
utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request))
}
return d, 200, nil
}, a)
@@ -66,12 +79,13 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str
func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
return func(d utils.DBObject) utils.ShallowDBObject {
if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
utils.GenericDeleteOne(d.GetID(), a)
utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
return nil
}
if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
d.(*WorkflowExecutions).State = enum.FORGOTTEN
utils.GenericRawUpdateOne(d, d.GetID(), a)
d, _, _ = utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request))
return d
}
return d
}

View File

@@ -58,7 +58,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
}
wf := res.(*workflow.Workflow)
longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request)
fmt.Println("longest", longest, err)
if err != nil {
return false, wf, []*WorkflowExecutions{}, err
}
@@ -68,7 +67,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
ws.Warning = "The workflow may be too long to be executed in the given time frame, we will try to book it anyway\n"
}
execs, err := ws.getExecutions(wf)
fmt.Println("execs", execs, err)
if err != nil {
return false, wf, []*WorkflowExecutions{}, err
}

View File

@@ -2,7 +2,6 @@ package workspace
import (
"errors"
"fmt"
"cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/logs"
@@ -116,7 +115,6 @@ func (a *workspaceMongoAccessor) Search(filters *dbs.Filters, search string, isD
This function is used to share the workspace with the peers
*/
func (a *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD, caller *tools.HTTPCaller) {
fmt.Println("Sharing workspace", realData, caller)
if realData == nil || realData.Shared == "" || caller == nil || caller.Disabled {
return
}