Adjust Mongo
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"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/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
type ResourceInterface interface {
|
||||
utils.DBObject
|
||||
Trim()
|
||||
FilterPeer(peerID string) *dbs.Filters
|
||||
GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation
|
||||
ConvertToPricedResource(t tools.DataType, a *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, b *int, request *tools.APIRequest) (pricing.PricedItemITF, error)
|
||||
GetType() string
|
||||
@@ -17,6 +19,7 @@ type ResourceInterface interface {
|
||||
ClearEnv() utils.DBObject
|
||||
SetAllowedInstances(request *tools.APIRequest)
|
||||
AddInstances(instance ResourceInstanceITF)
|
||||
RefineResourceByPartnership(peerID string) ResourceInterface
|
||||
}
|
||||
|
||||
type ResourceInstanceITF interface {
|
||||
@@ -29,9 +32,11 @@ type ResourceInstanceITF interface {
|
||||
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
||||
GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string)
|
||||
ClearPeerGroups()
|
||||
RefineResourceByPartnership(peerID string) (ResourceInstanceITF, bool)
|
||||
}
|
||||
|
||||
type ResourcePartnerITF interface {
|
||||
RefineResourceByPartnership(peerID string) (ResourcePartnerITF, bool)
|
||||
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
||||
GetPeerGroups() map[string][]string
|
||||
ClearPeerGroups()
|
||||
|
||||
@@ -55,6 +55,10 @@ func (w *NativeTool) ConvertToPricedResource(t tools.DataType, selectedInstance
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (abs *NativeTool) RefineResourceByPartnership(peerID string) ResourceInterface {
|
||||
return abs
|
||||
}
|
||||
|
||||
func InitNative() {
|
||||
for _, kind := range []native_tools.NativeToolsEnum{native_tools.WORKFLOW_EVENT} {
|
||||
newNative := &NativeTool{}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -36,6 +36,10 @@ type MockPartner struct {
|
||||
groups map[string][]string
|
||||
}
|
||||
|
||||
func (abs *MockPartner) RefineResourceByPartnership(peerID string) (resources.ResourceInstanceITF, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (m *MockPartner) GetProfile(buying *int, strategy *int) pricing.PricingProfileITF {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor
|
||||
return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} })
|
||||
}
|
||||
|
||||
func (abs *WorkflowResource) RefineResourceByPartnership(peerID string) ResourceInterface {
|
||||
return abs
|
||||
}
|
||||
|
||||
func (r *WorkflowResource) AddInstances(instance ResourceInstanceITF) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user