diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index 16d1c05..258beee 100644 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -12,6 +12,7 @@ type ResourceInterface interface { ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF GetType() string GetSelectedInstance() utils.DBObject + ClearEnv() utils.DBObject SetAllowedInstances(request *tools.APIRequest) } @@ -20,6 +21,7 @@ type ResourceInstanceITF interface { GetID() string GetName() string StoreDraftDefault() + ClearEnv() GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string) ClearPeerGroups() diff --git a/models/resources/resource.go b/models/resources/resource.go index a9a7a57..4cadd04 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -71,6 +71,13 @@ func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource( } } +func (abs *AbstractIntanciatedResource[T]) ClearEnv() utils.DBObject { + for _, instance := range abs.Instances { + instance.ClearEnv() + } + return abs +} + func (r *AbstractIntanciatedResource[T]) GetSelectedInstance() utils.DBObject { if r.SelectedInstanceIndex != nil && len(r.Instances) > *r.SelectedInstanceIndex { return r.Instances[*r.SelectedInstanceIndex] @@ -127,17 +134,30 @@ type GeoPoint struct { Longitude float64 `json:"longitude,omitempty" bson:"longitude,omitempty"` } +type Credentials struct { + Login string `json:"login,omitempty" bson:"login,omitempty"` + Pass string `json:"password,omitempty" bson:"password,omitempty"` +} + type ResourceInstance[T ResourcePartnerITF] struct { utils.AbstractObject Location GeoPoint `json:"location,omitempty" bson:"location,omitempty"` Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"` AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"` + Access *Credentials `json:"access,omitempty" bson:"access,omitempty"` Env []models.Param `json:"env,omitempty" bson:"env,omitempty"` Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"` Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"` } +func (ri *ResourceInstance[T]) ClearEnv() { + ri.Access = nil + ri.Env = []models.Param{} + ri.Inputs = []models.Param{} + ri.Outputs = []models.Param{} +} + func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF { pricings := []pricing.PricingProfileITF{} for _, p := range ri.Partnerships { diff --git a/models/resources/workflow.go b/models/resources/workflow.go index b191958..a80622e 100644 --- a/models/resources/workflow.go +++ b/models/resources/workflow.go @@ -23,6 +23,10 @@ func (r *WorkflowResource) GetType() string { return tools.WORKFLOW_RESOURCE.String() } +func (d *WorkflowResource) ClearEnv() utils.DBObject { + return d +} + func (d *WorkflowResource) Trim() { /* EMPTY */ } diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index 302674b..eaf6bd0 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -125,6 +125,13 @@ func (a *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, i // CopyOne copies a workflow in the database func (a *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) { + wf := data.(*Workflow) + for _, item := range wf.Graph.Items { + _, obj := item.GetResource() + if obj != nil { + obj.ClearEnv() + } + } return utils.GenericStoreOne(data, a) }