update the object stored for one workflow with user input

This commit is contained in:
pb
2024-03-29 17:00:53 +01:00
parent 49d3ba9763
commit b51c0f1b74
3 changed files with 79 additions and 24 deletions

View File

@@ -1,11 +1,13 @@
package models
import (
"encoding/xml"
"fmt"
"strings"
"cloud.o-forge.io/core/oc-catalog/models/rtype"
"cloud.o-forge.io/core/oc-catalog/services"
structtomap "github.com/Klathmon/StructToMap"
"github.com/beego/beego/v2/core/logs"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@@ -35,7 +37,7 @@ type ComputingNEWModel struct {
ShortDescription string `json:"short_description,omitempty" required:"true" validate:"required"`
Logo string `json:"logo,omitempty" required:"true" validate:"required"`
// Type string `json:"type,omitempty" required:"true"`
Type string `json:"type,omitempty" required:"true"`
Owner string `json:"owner,omitempty"`
License string `json:"license,omitempty"`
Price uint `json:"price,omitempty"`
@@ -49,7 +51,7 @@ type ComputingNEWModel struct {
Command string `json:"command,omitempty"`
Arguments []string `json:"arguments,omitempty"`
Environment []string `json:"environment,omitempty"`
// Ports []string `json:"ports,omitempty"`
Ports []string `json:"ports,omitempty"`
// CustomDeployment string `json:"custom_deployment,omitempty"`
@@ -77,6 +79,11 @@ type ComputingObject struct {
Inputs []string `json:"inputs"`
Outputs []string `json:"outputs"`
Image string `json:"image,omitempty"`
Command string `json:"command,omitempty"`
Arguments []string `json:"arguments,omitempty"`
Environment []string `json:"environment,omitempty"`
Ports []string `json:"ports,omitempty"`
DataCenterID string `json:"datacenterID" description:"Datacenter where the computing will be executed"`
}
@@ -174,19 +181,42 @@ func PostOneComputing(obj ComputingNEWModel) (ID string, err error) {
return postOneResource(obj, rtype.COMPUTING)
}
func (obj ComputingModel) AddUserInput(inputs map[string]interface{} ){
func (obj *ComputingObject) AddUserInput(inputs []xml.Attr){
// So far only a few input to handle so a switch with a case for each type of attribute
// is enough, to prevent too much complexity
for key, value := range inputs {
switch strings.ToLower(key) {
for _, j := range(inputs){
setting, _ := structtomap.Convert(j)
// fmt.Println(strings.ToLower(setting["Name"]))
name := setting["Name"].(xml.Name).Local
value := setting["Value"]
switch name {
case "command":
obj.Command = value.(string)
case "arguments":
obj.Arguments = value.([]string)
case "args":
empty, sliced_arguments := getSliceSettings(value.(string))
if (!empty){
obj.Arguments = sliced_arguments
}
case "env" :
obj.Environment = value.([]string)
empty, sliced_arguments := getSliceSettings(value.(string))
if (!empty){
obj.Environment = sliced_arguments
}
default:
logs.Alert(fmt.Printf("%s is not an attribute of storage componants", key))
logs.Alert(fmt.Printf("%s is not an attribute of computing componants", name))
}
}
}
func getSliceSettings(string_to_parse string)(empty bool, sliced_string []string){
if len(string_to_parse) == 0 {
return true, nil
}
empty = false
sliced_string = strings.Split(string_to_parse," ")
return
}