SessionSv1.AuthorizeEvent using SuppliersDigest as suppliers

This commit is contained in:
DanB
2018-01-21 18:46:58 +01:00
parent 1616797b5c
commit dd0b436b1e
5 changed files with 17 additions and 26 deletions

View File

@@ -173,7 +173,7 @@ func (sm *FSSessionManager) onChannelPark(fsev FSEvent, connId string) {
}
}
if authArgs.GetSuppliers {
fsArray := SliceAsFsArray(authReply.Suppliers.SupplierIDs())
fsArray := SliceAsFsArray(authReply.Suppliers)
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()))

View File

@@ -141,24 +141,7 @@ func TestSSv1ItAuth(t *testing.T) {
if *rply.ResourceAllocation == "" {
t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
}
eSplrs := &engine.SortedSuppliers{
ProfileID: "SPL_ACNT_1001",
Sorting: utils.MetaWeight,
SortedSuppliers: []*engine.SortedSupplier{
&engine.SortedSupplier{
SupplierID: "supplier1",
SortingData: map[string]interface{}{
"Weight": 20.0,
},
},
&engine.SortedSupplier{
SupplierID: "supplier2",
SortingData: map[string]interface{}{
"Weight": 10.0,
},
},
},
}
eSplrs := []string{"supplier1", "supplier2"}
if !reflect.DeepEqual(eSplrs, rply.Suppliers) {
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Suppliers))
}

View File

@@ -69,9 +69,6 @@
"freeswitch_agent": {
"enabled": true,
"event_socket_conns":[
{"address": "127.0.0.1:8021", "password": "ClueCon", "reconnects": 5}
],
},

View File

@@ -67,6 +67,19 @@ 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
}
}
return
}
// SuppliersSorter is the interface which needs to be implemented by supplier sorters
type SuppliersSorter interface {
SortSuppliers(string, []*Supplier, *utils.CGREvent) (*SortedSuppliers, error)

View File

@@ -1299,7 +1299,7 @@ type V1AuthorizeReply struct {
Attributes *engine.AttrSProcessEventReply
ResourceAllocation *string
MaxUsage *time.Duration
Suppliers *engine.SortedSuppliers
Suppliers []string
}
// BiRPCV1Authorize performs authorization for CGREvent based on specific components
@@ -1364,9 +1364,7 @@ func (smg *SMGeneric) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection,
sArgs, &splsReply); err != nil {
return utils.NewErrSupplierS(err)
}
if splsReply.SortedSuppliers != nil {
authReply.Suppliers = &splsReply
}
authReply.Suppliers = splsReply.SuppliersDigest()
}
return nil
}