diff --git a/agents/fsagent.go b/agents/fsagent.go index 986d2e35b..e51502c9f 100644 --- a/agents/fsagent.go +++ b/agents/fsagent.go @@ -173,7 +173,7 @@ func (sm *FSSessionManager) onChannelPark(fsev FSEvent, connId string) { } } if authArgs.GetSuppliers { - fsArray := SliceAsFsArray(authReply.Suppliers) + fsArray := SliceAsFsArray(authReply.Suppliers.SuppliersWithParams()) if _, err := sm.conns[connId].SendApiCmd(fmt.Sprintf("uuid_setvar %s %s %s\n\n", fsev.GetUUID(), utils.CGR_SUPPLIERS, fsArray)); err != nil { utils.Logger.Info(fmt.Sprintf("<%s> error setting suppliers: %s", utils.FreeSWITCHAgent, err.Error())) diff --git a/engine/attributes.go b/engine/attributes.go index 4db7e67d9..201da449e 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -114,12 +114,31 @@ func (alS *AttributeService) attributeProfileForEvent(ev *utils.CGREvent) (attrP return attrPrfls[0], nil } +// AttrSFldNameValue is a helper struct for AttrSDigest deserialization +type AttrSFieldNameValue struct { + FieldName string + FieldValue string +} + type AttrSProcessEventReply struct { MatchedProfile string AlteredFields []string CGREvent *utils.CGREvent } +// Digest returns serialized version of alteredFields in AttrSProcessEventReply +// format fldName1:fldVal1,fldName2:fldVal2 +func (attrReply *AttrSProcessEventReply) Digest() (rplyDigest string) { + for i, fld := range attrReply.AlteredFields { + if i != 0 { + rplyDigest += utils.FIELDS_SEP + } + fldStrVal, _ := attrReply.CGREvent.FieldAsString(fld) + rplyDigest += fld + utils.InInFieldSep + fldStrVal + } + return +} + // processEvent will match event with attribute profile and do the necessary replacements func (alS *AttributeService) processEvent(ev *utils.CGREvent) (rply *AttrSProcessEventReply, err error) { attrPrf, err := alS.attributeProfileForEvent(ev) diff --git a/engine/libsuppliers.go b/engine/libsuppliers.go index 996d1a2b6..c60ba68f9 100644 --- a/engine/libsuppliers.go +++ b/engine/libsuppliers.go @@ -21,7 +21,7 @@ package engine import ( "fmt" "sort" - // "time" + "strings" "github.com/cgrates/cgrates/utils" ) @@ -29,8 +29,8 @@ import ( // SupplierReply represents one supplier in type SortedSupplier struct { SupplierID string - SortingData map[string]interface{} // store here extra info like cost or stats SupplierParameters string + SortingData map[string]interface{} // store here extra info like cost or stats } // SuppliersReply is returned as part of GetSuppliers call @@ -49,6 +49,18 @@ func (sSpls *SortedSuppliers) SupplierIDs() (sIDs []string) { return } +// SupplierIDs returns list of suppliers +func (sSpls *SortedSuppliers) SuppliersWithParams() (sPs []string) { + sPs = make([]string, len(sSpls.SortedSuppliers)) + for i, spl := range sSpls.SortedSuppliers { + sPs[i] = spl.SupplierID + if spl.SupplierParameters != "" { + sPs[i] += utils.InInFieldSep + spl.SupplierParameters + } + } + return +} + // SortWeight is part of sort interface, sort based on Weight func (sSpls *SortedSuppliers) SortWeight() { sort.Slice(sSpls.SortedSuppliers, func(i, j int) bool { @@ -68,16 +80,14 @@ func (sSpls *SortedSuppliers) SortCost() { } // Digest returns list of supplierIDs + parameters for easier outside access -func (sSpls *SortedSuppliers) SuppliersDigest() (sDigest []string) { - sDigest = make([]string, len(sSpls.SortedSuppliers)) - for i, sSpl := range sSpls.SortedSuppliers { - sDigest[i] = sSpl.SupplierID - if sSpl.SupplierParameters != "" { - sDigest[i] += utils.InInFieldSep + sSpl.SupplierParameters - } +// format suppl1:suppl1params,suppl2:suppl2params +func (sSpls *SortedSuppliers) Digest() string { + return strings.Join(sSpls.SuppliersWithParams(), utils.FIELDS_SEP) +} - } - return +type SupplierWithParams struct { + SupplierName string + SupplierParams string } // SuppliersSorter is the interface which needs to be implemented by supplier sorters diff --git a/sessionmanager/smgeneric.go b/sessionmanager/smgeneric.go index 7d371920c..d330bf225 100644 --- a/sessionmanager/smgeneric.go +++ b/sessionmanager/smgeneric.go @@ -1299,7 +1299,7 @@ type V1AuthorizeReply struct { Attributes *engine.AttrSProcessEventReply ResourceAllocation *string MaxUsage *time.Duration - Suppliers []string + Suppliers *engine.SortedSuppliers } // BiRPCV1Authorize performs authorization for CGREvent based on specific components @@ -1364,7 +1364,9 @@ func (smg *SMGeneric) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection, sArgs, &splsReply); err != nil { return utils.NewErrSupplierS(err) } - authReply.Suppliers = splsReply.SuppliersDigest() + if splsReply.SortedSuppliers != nil { + authReply.Suppliers = &splsReply + } } return nil }