From 085a8718e053bd3865cb648b1e494b994400d72f Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 13 Feb 2025 15:11:23 +0100 Subject: [PATCH] correct --- models/resources/compute.go | 5 +++-- models/resources/data.go | 4 ++-- models/resources/processing.go | 2 +- models/resources/resource.go | 14 +++++++------- models/resources/storage.go | 8 ++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/models/resources/compute.go b/models/resources/compute.go index 7a0e014..22e521e 100644 --- a/models/resources/compute.go +++ b/models/resources/compute.go @@ -17,7 +17,7 @@ import ( * it defines the resource compute */ type ComputeResource struct { - AbstractIntanciatedResource[*ComputeResourceInstance] + AbstractInstanciatedResource[*ComputeResourceInstance] Architecture string `json:"architecture,omitempty" bson:"architecture,omitempty"` // Architecture is the architecture Infrastructure enum.InfrastructureType `json:"infrastructure" bson:"infrastructure" default:"-1"` // Infrastructure is the infrastructure } @@ -35,7 +35,7 @@ func (abs *ComputeResource) ConvertToPricedResource( if t != tools.COMPUTE_RESOURCE { return nil } - p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request) + p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request) priced := p.(*PricedResource) return &PricedComputeResource{ PricedResource: *priced, @@ -52,6 +52,7 @@ type ComputeNode struct { type ComputeResourceInstance struct { ResourceInstance[*ComputeResourcePartnership] + Source string `json:"source,omitempty" bson:"source,omitempty"` // Source is the source of the resource SecurityLevel string `json:"security_level,omitempty" bson:"security_level,omitempty"` PowerSources []string `json:"power_sources,omitempty" bson:"power_sources,omitempty"` AnnualCO2Emissions float64 `json:"annual_co2_emissions,omitempty" bson:"co2_emissions,omitempty"` diff --git a/models/resources/data.go b/models/resources/data.go index 774baaf..8734e59 100644 --- a/models/resources/data.go +++ b/models/resources/data.go @@ -16,7 +16,7 @@ import ( * it defines the resource data */ type DataResource struct { - AbstractIntanciatedResource[*DataInstance] + AbstractInstanciatedResource[*DataInstance] Type string `bson:"type,omitempty" json:"type,omitempty"` Quality string `bson:"quality,omitempty" json:"quality,omitempty"` OpenData bool `bson:"open_data" json:"open_data" default:"false"` // Type is the type of the storage @@ -42,7 +42,7 @@ func (abs *DataResource) ConvertToPricedResource( if t != tools.DATA_RESOURCE { return nil } - p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request) + p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request) priced := p.(*PricedResource) return &PricedDataResource{ PricedResource: *priced, diff --git a/models/resources/processing.go b/models/resources/processing.go index da26eb6..c2f9e38 100644 --- a/models/resources/processing.go +++ b/models/resources/processing.go @@ -25,7 +25,7 @@ type ProcessingUsage struct { * it defines the resource processing */ type ProcessingResource struct { - AbstractIntanciatedResource[*ProcessingInstance] + AbstractInstanciatedResource[*ProcessingInstance] Infrastructure enum.InfrastructureType `json:"infrastructure" bson:"infrastructure" default:"-1"` // Infrastructure is the infrastructure IsService bool `json:"is_service,omitempty" bson:"is_service,omitempty"` // IsService is a flag that indicates if the processing is a service Usage *ProcessingUsage `bson:"usage,omitempty" json:"usage,omitempty"` // Usage is the usage of the processing diff --git a/models/resources/resource.go b/models/resources/resource.go index 32cee2a..7d0dcf0 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -47,12 +47,12 @@ func (r *AbstractResource) CanDelete() bool { return r.IsDraft // only draft bookings can be deleted } -type AbstractIntanciatedResource[T ResourceInstanceITF] struct { +type AbstractInstanciatedResource[T ResourceInstanceITF] struct { AbstractResource // AbstractResource contains the basic fields of an object (id, name) Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource } -func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource( +func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource( t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { instances := map[string]string{} profiles := []pricing.PricingProfileITF{} @@ -71,14 +71,14 @@ func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource( } } -func (abs *AbstractIntanciatedResource[T]) ClearEnv() utils.DBObject { +func (abs *AbstractInstanciatedResource[T]) ClearEnv() utils.DBObject { for _, instance := range abs.Instances { instance.ClearEnv() } return abs } -func (r *AbstractIntanciatedResource[T]) GetSelectedInstance() utils.DBObject { +func (r *AbstractInstanciatedResource[T]) GetSelectedInstance() utils.DBObject { if r.SelectedInstanceIndex != nil && len(r.Instances) > *r.SelectedInstanceIndex { return r.Instances[*r.SelectedInstanceIndex] } @@ -88,11 +88,11 @@ func (r *AbstractIntanciatedResource[T]) GetSelectedInstance() utils.DBObject { return nil } -func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) { +func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) { abs.Instances = verifyAuthAction[T](abs.Instances, request) } -func (d *AbstractIntanciatedResource[T]) Trim() { +func (d *AbstractInstanciatedResource[T]) Trim() { d.Type = d.GetType() if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok { for _, instance := range d.Instances { @@ -101,7 +101,7 @@ func (d *AbstractIntanciatedResource[T]) Trim() { } } -func (abs *AbstractIntanciatedResource[T]) VerifyAuth(request *tools.APIRequest) bool { +func (abs *AbstractInstanciatedResource[T]) VerifyAuth(request *tools.APIRequest) bool { return len(verifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(request) } diff --git a/models/resources/storage.go b/models/resources/storage.go index 500b2d6..6d7c8ce 100644 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -17,9 +17,9 @@ import ( * it defines the resource storage */ type StorageResource struct { - AbstractIntanciatedResource[*StorageResourceInstance] // AbstractResource contains the basic fields of an object (id, name) - StorageType enum.StorageType `bson:"storage_type" json:"storage_type" default:"-1"` // Type is the type of the storage - Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage + AbstractInstanciatedResource[*StorageResourceInstance] // AbstractResource contains the basic fields of an object (id, name) + StorageType enum.StorageType `bson:"storage_type" json:"storage_type" default:"-1"` // Type is the type of the storage + Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage } func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor { @@ -35,7 +35,7 @@ func (abs *StorageResource) ConvertToPricedResource( if t != tools.STORAGE_RESOURCE { return nil } - p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request) + p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request) priced := p.(*PricedResource) return &PricedStorageResource{ PricedResource: *priced,