Compare commits
2 Commits
4b090ed825
...
5a532ae192
Author | SHA1 | Date | |
---|---|---|---|
5a532ae192 | |||
4820e87db5 |
@ -1,8 +1,9 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
oclib "cloud.o-forge.io/core/oc-lib"
|
oclib "cloud.o-forge.io/core/oc-lib"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
@ -35,7 +36,7 @@ func (o *SharedWorkspaceController) Search() {
|
|||||||
// @router /:id [put]
|
// @router /:id [put]
|
||||||
func (o *SharedWorkspaceController) Put() {
|
func (o *SharedWorkspaceController) Put() {
|
||||||
// store and return Id or post with UUID
|
// store and return Id or post with UUID
|
||||||
var paths = map[string]map[tools.METHOD]string{
|
var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers
|
||||||
utils.SHARED_WORKSPACE.String(): {
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
@ -55,7 +56,8 @@ func (o *SharedWorkspaceController) Put() {
|
|||||||
var res map[string]interface{}
|
var res map[string]interface{}
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||||
caller := tools.NewHTTPCaller(paths)
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
|
fmt.Println("UPDATE", res)
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, caller)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ func (o *SharedWorkspaceController) Put() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router / [post]
|
// @router / [post]
|
||||||
func (o *SharedWorkspaceController) Post() {
|
func (o *SharedWorkspaceController) Post() {
|
||||||
var paths = map[string]map[tools.METHOD]string{
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
utils.SHARED_WORKSPACE.String(): {
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
@ -83,9 +85,10 @@ func (o *SharedWorkspaceController) Post() {
|
|||||||
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
var res map[string]interface{}
|
var res map[string]interface{}
|
||||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||||
caller := tools.NewHTTPCaller(paths)
|
|
||||||
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, caller)
|
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
@ -117,13 +120,30 @@ func (o *SharedWorkspaceController) Get() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/workspace/:id2 [delete]
|
// @router /:id/workspace/:id2 [delete]
|
||||||
func (o *SharedWorkspaceController) RemoveWorkspace() {
|
func (o *SharedWorkspaceController) RemoveWorkspace() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
newWorkspace := []string{}
|
newWorkspace := []string{}
|
||||||
if slices.Contains(shared.Workspaces, id) {
|
if slices.Contains(shared.Workspaces, id2) {
|
||||||
for _, w := range shared.Workspaces {
|
for _, w := range shared.Workspaces {
|
||||||
if w != id2 {
|
if w != id2 {
|
||||||
newWorkspace = append(newWorkspace, w)
|
newWorkspace = append(newWorkspace, w)
|
||||||
@ -131,7 +151,7 @@ func (o *SharedWorkspaceController) RemoveWorkspace() {
|
|||||||
}
|
}
|
||||||
shared.Workspaces = newWorkspace
|
shared.Workspaces = newWorkspace
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,13 +162,31 @@ func (o *SharedWorkspaceController) RemoveWorkspace() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/workflow/:id2 [delete]
|
// @router /:id/workflow/:id2 [delete]
|
||||||
func (o *SharedWorkspaceController) RemoveWorkflow() {
|
func (o *SharedWorkspaceController) RemoveWorkflow() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
|
fmt.Println("RemoveWorkflow", r)
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
newWorkflows := []string{}
|
newWorkflows := []string{}
|
||||||
if slices.Contains(shared.Workflows, id) {
|
if slices.Contains(shared.Workflows, id2) {
|
||||||
for _, w := range shared.Workflows {
|
for _, w := range shared.Workflows {
|
||||||
if w != id2 {
|
if w != id2 {
|
||||||
newWorkflows = append(newWorkflows, w)
|
newWorkflows = append(newWorkflows, w)
|
||||||
@ -156,7 +194,7 @@ func (o *SharedWorkspaceController) RemoveWorkflow() {
|
|||||||
}
|
}
|
||||||
shared.Workflows = newWorkflows
|
shared.Workflows = newWorkflows
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +205,24 @@ func (o *SharedWorkspaceController) RemoveWorkflow() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/peer/:id2 [delete]
|
// @router /:id/peer/:id2 [delete]
|
||||||
func (o *SharedWorkspaceController) RemovePeer() {
|
func (o *SharedWorkspaceController) RemovePeer() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
@ -190,7 +245,7 @@ func (o *SharedWorkspaceController) RemovePeer() {
|
|||||||
}
|
}
|
||||||
shared.Peers = newPeers
|
shared.Peers = newPeers
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,13 +256,30 @@ func (o *SharedWorkspaceController) RemovePeer() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/rule/:id2 [delete]
|
// @router /:id/rule/:id2 [delete]
|
||||||
func (o *SharedWorkspaceController) RemoveRule() {
|
func (o *SharedWorkspaceController) RemoveRule() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
newRules := []string{}
|
newRules := []string{}
|
||||||
if slices.Contains(shared.Rules, id) {
|
if shared != nil && slices.Contains(shared.Rules, id2) {
|
||||||
for _, rule := range shared.Rules {
|
for _, rule := range shared.Rules {
|
||||||
if rule != id2 {
|
if rule != id2 {
|
||||||
newRules = append(newRules, rule)
|
newRules = append(newRules, rule)
|
||||||
@ -215,7 +287,7 @@ func (o *SharedWorkspaceController) RemoveRule() {
|
|||||||
}
|
}
|
||||||
shared.Rules = newRules
|
shared.Rules = newRules
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,15 +298,37 @@ func (o *SharedWorkspaceController) RemoveRule() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/workspace/:id2 [post]
|
// @router /:id/workspace/:id2 [post]
|
||||||
func (o *SharedWorkspaceController) AddWorkspace() {
|
func (o *SharedWorkspaceController) AddWorkspace() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
|
if r.Code != 200 {
|
||||||
|
o.Data["json"] = r
|
||||||
|
o.ServeJSON()
|
||||||
|
return
|
||||||
|
}
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
if !slices.Contains(shared.Workspaces, id) {
|
if shared != nil && !slices.Contains(shared.Workspaces, id2) {
|
||||||
shared.Workspaces = append(shared.Workspaces, id2)
|
shared.Workspaces = append(shared.Workspaces, id2)
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,15 +339,35 @@ func (o *SharedWorkspaceController) AddWorkspace() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/workflow/:id2 [post]
|
// @router /:id/workflow/:id2 [post]
|
||||||
func (o *SharedWorkspaceController) AddWorkflow() {
|
func (o *SharedWorkspaceController) AddWorkflow() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
|
fmt.Println("AddWorkflow", id, id2)
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
if !slices.Contains(shared.Workflows, id) {
|
if shared != nil && !slices.Contains(shared.Workflows, id2) {
|
||||||
shared.Workflows = append(shared.Workflows, id2)
|
shared.Workflows = append(shared.Workflows, id2)
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
fmt.Println("AddWorkflow", shared.Workflows)
|
||||||
|
|
||||||
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,15 +378,32 @@ func (o *SharedWorkspaceController) AddWorkflow() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/peer/:id2 [post]
|
// @router /:id/peer/:id2 [post]
|
||||||
func (o *SharedWorkspaceController) AddPeer() {
|
func (o *SharedWorkspaceController) AddPeer() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to call other OC services
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
if !slices.Contains(shared.Peers, id) {
|
if shared != nil && !slices.Contains(shared.Peers, id2) {
|
||||||
shared.Peers = append(shared.Peers, id2)
|
shared.Peers = append(shared.Peers, id2)
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,15 +414,32 @@ func (o *SharedWorkspaceController) AddPeer() {
|
|||||||
// @Success 200 {shared workspace} models.shared_workspace
|
// @Success 200 {shared workspace} models.shared_workspace
|
||||||
// @router /:id/rule/:id2 [post]
|
// @router /:id/rule/:id2 [post]
|
||||||
func (o *SharedWorkspaceController) AddRule() {
|
func (o *SharedWorkspaceController) AddRule() {
|
||||||
var res map[string]interface{}
|
var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers
|
||||||
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKSPACE.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKSPACE)) + "/oc/workspace/",
|
||||||
|
},
|
||||||
|
utils.WORKFLOW.String(): {
|
||||||
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/",
|
||||||
|
},
|
||||||
|
utils.PEER.String(): {
|
||||||
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc/peer",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
id2 := o.Ctx.Input.Param(":id2")
|
id2 := o.Ctx.Input.Param(":id2")
|
||||||
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
r := oclib.LoadOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id)
|
||||||
shared := r.ToSharedWorkspace()
|
shared := r.ToSharedWorkspace()
|
||||||
if !slices.Contains(shared.Rules, id) {
|
if shared != nil && !slices.Contains(shared.Rules, id2) {
|
||||||
shared.Rules = append(shared.Rules, id2)
|
shared.Rules = append(shared.Rules, id2)
|
||||||
}
|
}
|
||||||
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), res, id, nil)
|
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), shared.Serialize(), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +449,7 @@ func (o *SharedWorkspaceController) AddRule() {
|
|||||||
// @Success 200 {shared workspace} delete success!
|
// @Success 200 {shared workspace} delete success!
|
||||||
// @router /:id [delete]
|
// @router /:id [delete]
|
||||||
func (o *SharedWorkspaceController) Delete() {
|
func (o *SharedWorkspaceController) Delete() {
|
||||||
var paths = map[string]map[tools.METHOD]string{
|
var paths = map[string]map[tools.METHOD]string{ // paths used to send to peers
|
||||||
utils.SHARED_WORKSPACE.String(): {
|
utils.SHARED_WORKSPACE.String(): {
|
||||||
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/:id",
|
||||||
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE)) + "/oc/shared/workspace/",
|
||||||
@ -319,7 +467,7 @@ func (o *SharedWorkspaceController) Delete() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
id := o.Ctx.Input.Param(":id")
|
id := o.Ctx.Input.Param(":id")
|
||||||
caller := tools.NewHTTPCaller(paths)
|
caller := tools.NewHTTPCaller(paths) // caller used to send to peers
|
||||||
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id, caller)
|
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), id, caller)
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -11,7 +11,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d // indirect
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 // indirect
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/beego/bee/v2 v2.1.0 // indirect
|
github.com/beego/bee/v2 v2.1.0 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
20
go.sum
20
go.sum
@ -124,6 +124,26 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71 h1:GodGMXVFgSdd5
|
|||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826103423-aff9304b1a71/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d h1:CPwBFl2ecnHMi9sxubA9/peTKn4BVBVpHkCCwRTXUik=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d h1:CPwBFl2ecnHMi9sxubA9/peTKn4BVBVpHkCCwRTXUik=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826125854-050e6022cb8d/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826132851-63b02199f62f h1:gQ7mCNs1yK99SY6ilA9J5Ng+hsKhbFfDBtELNzLK6eM=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826132851-63b02199f62f/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826141022-00625eabd631 h1:FYMS7QWERjvjAcdsmYRaq1Ms/PDfWv7Pr+OTKkwJSXQ=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826141022-00625eabd631/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826145224-767c14044f51 h1:rUeRWR3ckK7KKqRabE+HBOLXG+35Tv0jBbhpfrR8c2g=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826145224-767c14044f51/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826155958-463144a0625b h1:wjqnBe8WFxG0jDmSAxRWm2FJsXvLGwAO24JhdDzPm1M=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826155958-463144a0625b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827080713-091cbb9e7fab h1:x3brpRs6nfv9549rvJMxeacYFqnpe1TrlM2qw5kzsXU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827080713-091cbb9e7fab/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827104028-772287225f44 h1:7jmT3iSzHJuJ2d1vJYTcwXeiDGv4SUOqQ8p4W04HIDY=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827104028-772287225f44/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827112206-45d53fc9a985 h1:4OzzVFOaI/QR/D5+qJiP4si6QsOggFFIPFmGwZ7cbeQ=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827112206-45d53fc9a985/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827121739-3c5c065b8d24 h1:naqxVtN3ew0eYVir+z2aagL13gCe1MdKv3Dp/sIBLxw=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240827121739-3c5c065b8d24/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240828114159-ede91cde4583 h1:5DVFZLJ4tySspQwk0H1HRR+arWSRsYsujP4N8zxvy2Q=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240828114159-ede91cde4583/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 h1:bEIY1lCsA78/mJqFE0gV6likAv5ZifH3RMnLJxiSk3o=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
|
5
main.go
5
main.go
@ -29,7 +29,12 @@ func main() {
|
|||||||
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
|
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
// Init OC with hostname and port for discovery purpose
|
||||||
oclib.Init("oc-shared", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8091"))
|
oclib.Init("oc-shared", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8091"))
|
||||||
|
/* PATHS ARE REFERENCE FOR INNER SERVICE OF DISTANT OC
|
||||||
|
* PATHS ARE USED TO CALL OTHER OC SERVICES
|
||||||
|
* NAMES ARE CANONICAL NAMES OF THE SERVICES
|
||||||
|
*/
|
||||||
oclib.AddPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), o.GetStringDefault("SHARED_WORKSPACE_URL", ":8091"))
|
oclib.AddPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), o.GetStringDefault("SHARED_WORKSPACE_URL", ":8091"))
|
||||||
oclib.AddPath(oclib.LibDataEnum(oclib.WORKSPACE), o.GetStringDefault("WORKSPACE_URL", ":8089"))
|
oclib.AddPath(oclib.LibDataEnum(oclib.WORKSPACE), o.GetStringDefault("WORKSPACE_URL", ":8089"))
|
||||||
oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":8088"))
|
oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":8088"))
|
||||||
|
Loading…
Reference in New Issue
Block a user