Adjust Mongo
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"slices"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
@@ -27,6 +28,10 @@ type AbstractResource struct {
|
||||
AllowedBookingModes map[booking.BookingMode]*pricing.PricingVariation `bson:"allowed_booking_modes" json:"allowed_booking_modes"`
|
||||
}
|
||||
|
||||
func (abs *AbstractResource) FilterPeer(peerID string) *dbs.Filters {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AbstractResource) GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation {
|
||||
if len(r.AllowedBookingModes) == 0 {
|
||||
return map[booking.BookingMode]*pricing.PricingVariation{
|
||||
@@ -68,6 +73,35 @@ type AbstractInstanciatedResource[T ResourceInstanceITF] struct {
|
||||
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
||||
}
|
||||
|
||||
// PEERID found
|
||||
func (abs *AbstractInstanciatedResource[T]) RefineResourceByPartnership(peerID string) ResourceInterface {
|
||||
instances := []T{}
|
||||
for _, i := range instances {
|
||||
i, ok := i.RefineResourceByPartnership(peerID)
|
||||
if ok {
|
||||
instances = append(instances, i.(T))
|
||||
}
|
||||
}
|
||||
abs.Instances = instances
|
||||
return abs
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) FilterPeer(peerID string) *dbs.Filters {
|
||||
return &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"instances": {{Operator: dbs.ELEMMATCH.String(), Value: &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"partnerships": {{Operator: dbs.ELEMMATCH.String(), Value: &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"peer_groups." + peerID: {{Operator: dbs.EXISTS.String(), Value: true}},
|
||||
},
|
||||
}}},
|
||||
},
|
||||
}}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) AddInstances(instance ResourceInstanceITF) {
|
||||
abs.Instances = append(abs.Instances, instance.(T))
|
||||
}
|
||||
@@ -132,7 +166,7 @@ func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.A
|
||||
if request != nil && request.PeerID == abs.CreatorID && request.PeerID != "" {
|
||||
return
|
||||
}
|
||||
abs.Instances = VerifyAuthAction[T](abs.Instances, request)
|
||||
abs.Instances = VerifyAuthAction(abs.Instances, request)
|
||||
}
|
||||
|
||||
func (d *AbstractInstanciatedResource[T]) Trim() {
|
||||
@@ -145,7 +179,7 @@ func (d *AbstractInstanciatedResource[T]) Trim() {
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) VerifyAuth(callName string, request *tools.APIRequest) bool {
|
||||
return len(VerifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(callName, request)
|
||||
return len(VerifyAuthAction(abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(callName, request)
|
||||
}
|
||||
|
||||
func VerifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.APIRequest) []T {
|
||||
@@ -186,10 +220,6 @@ type ResourceInstance[T ResourcePartnerITF] struct {
|
||||
Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"`
|
||||
Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"`
|
||||
|
||||
// SelectedPartnershipIndex int `json:"selected_partnership_index,omitempty" bson:"selected_partnership_index,omitempty"`
|
||||
// SelectedBuyingStrategy int `json:"selected_buying_strategy,omitempty" bson:"selected_buying_strategy,omitempty"`
|
||||
// SelectedStrategy int `json:"selected_strategy,omitempty" bson:"selected_strategy,omitempty"`
|
||||
|
||||
Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"`
|
||||
}
|
||||
|
||||
@@ -205,6 +235,19 @@ func NewInstance[T ResourcePartnerITF](name string) *ResourceInstance[T] {
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *ResourceInstance[T]) RefineResourceByPartnership(peerID string) (ResourceInstanceITF, bool) {
|
||||
okk := false
|
||||
partners := []T{}
|
||||
for _, p := range abs.Partnerships {
|
||||
partner, ok := p.RefineResourceByPartnership(peerID)
|
||||
if ok {
|
||||
partners = append(partners, partner.(T))
|
||||
okk = true
|
||||
}
|
||||
}
|
||||
return abs, okk
|
||||
}
|
||||
|
||||
func (ri *ResourceInstance[T]) ClearEnv() {
|
||||
ri.Env = []models.Param{}
|
||||
ri.Inputs = []models.Param{}
|
||||
@@ -267,6 +310,19 @@ type ResourcePartnerShip[T pricing.PricingProfileITF] struct {
|
||||
// to upgrade pricing profiles. to be a map BuyingStrategy, map of Strategy
|
||||
}
|
||||
|
||||
func (ri *ResourcePartnerShip[T]) RefineResourceByPartnership(peerID string) (ResourcePartnerITF, bool) {
|
||||
ok := false
|
||||
peerGrp := map[string][]string{}
|
||||
for k, v := range ri.PeerGroups {
|
||||
if k == peerID {
|
||||
peerGrp[k] = v
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
ri.PeerGroups = peerGrp
|
||||
return ri, ok
|
||||
}
|
||||
|
||||
func (ri *ResourcePartnerShip[T]) GetProfile(buying *int, strategy *int) pricing.PricingProfileITF {
|
||||
if buying != nil && strategy != nil {
|
||||
if strat, ok := ri.PricingProfiles[*buying]; ok {
|
||||
|
||||
Reference in New Issue
Block a user