Add ArgDispatcher in Arguments from SessionS, ThresholdS, SupplierS, etc...

This commit is contained in:
TeoV
2019-04-07 04:52:27 -04:00
committed by Dan Christian Bogos
parent 9392a34d9f
commit 8519a40e34
53 changed files with 1190 additions and 1090 deletions

View File

@@ -208,28 +208,28 @@ type DispatcherThresholdSv1 struct {
}
// Ping implements ThresholdSv1Ping
func (dT *DispatcherThresholdSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dT *DispatcherThresholdSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dT.dS.ThresholdSv1Ping(args, reply)
}
// GetThresholdsForEvent implements ThresholdSv1GetThresholdsForEvent
func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(tntID *dispatchers.ArgsProcessEventWithApiKey,
func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(tntID *engine.ArgsProcessEvent,
t *engine.Thresholds) error {
return dT.dS.ThresholdSv1GetThresholdsForEvent(tntID, t)
}
// ProcessEvent implements ThresholdSv1ProcessEvent
func (dT *DispatcherThresholdSv1) ProcessEvent(args *dispatchers.ArgsProcessEventWithApiKey,
func (dT *DispatcherThresholdSv1) ProcessEvent(args *engine.ArgsProcessEvent,
tIDs *[]string) error {
return dT.dS.ThresholdSv1ProcessEvent(args, tIDs)
}
func (dT *DispatcherThresholdSv1) GetThresholdIDs(args *dispatchers.TntWithApiKey,
func (dT *DispatcherThresholdSv1) GetThresholdIDs(args *utils.TenantWithArgDispatcher,
tIDs *[]string) error {
return dT.dS.ThresholdSv1GetThresholdIDs(args, tIDs)
}
func (dT *DispatcherThresholdSv1) GetThreshold(args *dispatchers.TntIDWithApiKey,
func (dT *DispatcherThresholdSv1) GetThreshold(args *utils.TenantIDWithArgDispatcher,
th *engine.Threshold) error {
return dT.dS.ThresholdSv1GetThreshold(args, th)
}
@@ -244,33 +244,33 @@ type DispatcherStatSv1 struct {
}
// Ping implements StatSv1Ping
func (dSts *DispatcherStatSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dSts *DispatcherStatSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dSts.dS.StatSv1Ping(args, reply)
}
// GetStatQueuesForEvent implements StatSv1GetStatQueuesForEvent
func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(args *dispatchers.ArgsStatProcessEventWithApiKey, reply *[]string) error {
func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error {
return dSts.dS.StatSv1GetStatQueuesForEvent(args, reply)
}
// GetQueueStringMetrics implements StatSv1GetQueueStringMetrics
func (dSts *DispatcherStatSv1) GetQueueStringMetrics(args *dispatchers.TntIDWithApiKey,
func (dSts *DispatcherStatSv1) GetQueueStringMetrics(args *utils.TenantIDWithArgDispatcher,
reply *map[string]string) error {
return dSts.dS.StatSv1GetQueueStringMetrics(args, reply)
}
func (dSts *DispatcherStatSv1) GetQueueFloatMetrics(args *dispatchers.TntIDWithApiKey,
func (dSts *DispatcherStatSv1) GetQueueFloatMetrics(args *utils.TenantIDWithArgDispatcher,
reply *map[string]float64) error {
return dSts.dS.StatSv1GetQueueFloatMetrics(args, reply)
}
func (dSts *DispatcherStatSv1) GetQueueIDs(args *dispatchers.TntWithApiKey,
func (dSts *DispatcherStatSv1) GetQueueIDs(args *utils.TenantWithArgDispatcher,
reply *[]string) error {
return dSts.dS.StatSv1GetQueueIDs(args, reply)
}
// GetQueueStringMetrics implements StatSv1ProcessEvent
func (dSts *DispatcherStatSv1) ProcessEvent(args *dispatchers.ArgsStatProcessEventWithApiKey, reply *[]string) error {
func (dSts *DispatcherStatSv1) ProcessEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error {
return dSts.dS.StatSv1ProcessEvent(args, reply)
}
@@ -284,27 +284,27 @@ type DispatcherResourceSv1 struct {
}
// Ping implements ResourceSv1Ping
func (dRs *DispatcherResourceSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dRs *DispatcherResourceSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dRs.dRs.ResourceSv1Ping(args, reply)
}
// GetResourcesForEvent implements ResourceSv1GetResourcesForEvent
func (dRs *DispatcherResourceSv1) GetResourcesForEvent(args *dispatchers.ArgsV1ResUsageWithApiKey,
func (dRs *DispatcherResourceSv1) GetResourcesForEvent(args *utils.ArgRSv1ResourceUsage,
reply *engine.Resources) error {
return dRs.dRs.ResourceSv1GetResourcesForEvent(args, reply)
}
func (dRs *DispatcherResourceSv1) AuthorizeResources(args *dispatchers.ArgsV1ResUsageWithApiKey,
func (dRs *DispatcherResourceSv1) AuthorizeResources(args *utils.ArgRSv1ResourceUsage,
reply *string) error {
return dRs.dRs.ResourceSv1AuthorizeResources(args, reply)
}
func (dRs *DispatcherResourceSv1) AllocateResources(args *dispatchers.ArgsV1ResUsageWithApiKey,
func (dRs *DispatcherResourceSv1) AllocateResources(args *utils.ArgRSv1ResourceUsage,
reply *string) error {
return dRs.dRs.ResourceSv1AllocateResources(args, reply)
}
func (dRs *DispatcherResourceSv1) ReleaseResources(args *dispatchers.ArgsV1ResUsageWithApiKey,
func (dRs *DispatcherResourceSv1) ReleaseResources(args *utils.ArgRSv1ResourceUsage,
reply *string) error {
return dRs.dRs.ResourceSv1ReleaseResources(args, reply)
}
@@ -319,12 +319,12 @@ type DispatcherSupplierSv1 struct {
}
// Ping implements SupplierSv1Ping
func (dSup *DispatcherSupplierSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dSup *DispatcherSupplierSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dSup.dSup.SupplierSv1Ping(args, reply)
}
// GetSuppliers implements SupplierSv1GetSuppliers
func (dSup *DispatcherSupplierSv1) GetSuppliers(args *dispatchers.ArgsGetSuppliersWithApiKey,
func (dSup *DispatcherSupplierSv1) GetSuppliers(args *engine.ArgsGetSuppliers,
reply *engine.SortedSuppliers) error {
return dSup.dSup.SupplierSv1GetSuppliers(args, reply)
}
@@ -339,18 +339,18 @@ type DispatcherAttributeSv1 struct {
}
// Ping implements SupplierSv1Ping
func (dA *DispatcherAttributeSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dA *DispatcherAttributeSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dA.dA.AttributeSv1Ping(args, reply)
}
// GetAttributeForEvent implements AttributeSv1GetAttributeForEvent
func (dA *DispatcherAttributeSv1) GetAttributeForEvent(args *dispatchers.ArgsAttrProcessEventWithApiKey,
func (dA *DispatcherAttributeSv1) GetAttributeForEvent(args *engine.AttrArgsProcessEvent,
reply *engine.AttributeProfile) error {
return dA.dA.AttributeSv1GetAttributeForEvent(args, reply)
}
// ProcessEvent implements AttributeSv1ProcessEvent
func (dA *DispatcherAttributeSv1) ProcessEvent(args *dispatchers.ArgsAttrProcessEventWithApiKey,
func (dA *DispatcherAttributeSv1) ProcessEvent(args *engine.AttrArgsProcessEvent,
reply *engine.AttrSProcessEventReply) error {
return dA.dA.AttributeSv1ProcessEvent(args, reply)
}
@@ -365,18 +365,18 @@ type DispatcherChargerSv1 struct {
}
// Ping implements ChargerSv1Ping
func (dC *DispatcherChargerSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dC *DispatcherChargerSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dC.dC.ChargerSv1Ping(args, reply)
}
// GetChargersForEvent implements ChargerSv1GetChargersForEvent
func (dC *DispatcherChargerSv1) GetChargersForEvent(args *dispatchers.CGREvWithApiKey,
func (dC *DispatcherChargerSv1) GetChargersForEvent(args *utils.CGREventWithArgDispatcher,
reply *engine.ChargerProfiles) (err error) {
return dC.dC.ChargerSv1GetChargersForEvent(args, reply)
}
// ProcessEvent implements ChargerSv1ProcessEvent
func (dC *DispatcherChargerSv1) ProcessEvent(args *dispatchers.CGREvWithApiKey,
func (dC *DispatcherChargerSv1) ProcessEvent(args *utils.CGREventWithArgDispatcher,
reply *[]*engine.ChrgSProcessEventReply) (err error) {
return dC.dC.ChargerSv1ProcessEvent(args, reply)
}
@@ -391,53 +391,53 @@ type DispatcherSessionSv1 struct {
}
// Ping implements SessionSv1Ping
func (dS *DispatcherSessionSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dS *DispatcherSessionSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.SessionSv1Ping(args, reply)
}
// AuthorizeEventWithDigest implements SessionSv1AuthorizeEventWithDigest
func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(args *dispatchers.AuthorizeArgsWithApiKey,
func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs,
reply *sessions.V1AuthorizeReplyWithDigest) error {
return dS.dS.SessionSv1AuthorizeEventWithDigest(args, reply)
}
func (dS *DispatcherSessionSv1) AuthorizeEvent(args *dispatchers.AuthorizeArgsWithApiKey,
func (dS *DispatcherSessionSv1) AuthorizeEvent(args *sessions.V1AuthorizeArgs,
reply *sessions.V1AuthorizeReply) error {
return dS.dS.SessionSv1AuthorizeEvent(args, reply)
}
// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(args *dispatchers.InitArgsWithApiKey,
func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(args *sessions.V1InitSessionArgs,
reply *sessions.V1InitReplyWithDigest) (err error) {
return dS.dS.SessionSv1InitiateSessionWithDigest(args, reply)
}
// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
func (dS *DispatcherSessionSv1) InitiateSession(args *dispatchers.InitArgsWithApiKey,
func (dS *DispatcherSessionSv1) InitiateSession(args *sessions.V1InitSessionArgs,
reply *sessions.V1InitSessionReply) (err error) {
return dS.dS.SessionSv1InitiateSession(args, reply)
}
// ProcessCDR implements SessionSv1ProcessCDR
func (dS *DispatcherSessionSv1) ProcessCDR(args *dispatchers.CGREvWithApiKey,
func (dS *DispatcherSessionSv1) ProcessCDR(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
return dS.dS.SessionSv1ProcessCDR(args, reply)
}
// ProcessEvent implements SessionSv1ProcessEvent
func (dS *DispatcherSessionSv1) ProcessEvent(args *dispatchers.ProcessEventWithApiKey,
func (dS *DispatcherSessionSv1) ProcessEvent(args *sessions.V1ProcessEventArgs,
reply *sessions.V1ProcessEventReply) (err error) {
return dS.dS.SessionSv1ProcessEvent(args, reply)
}
// TerminateSession implements SessionSv1TerminateSession
func (dS *DispatcherSessionSv1) TerminateSession(args *dispatchers.TerminateSessionWithApiKey,
func (dS *DispatcherSessionSv1) TerminateSession(args *sessions.V1TerminateSessionArgs,
reply *string) (err error) {
return dS.dS.SessionSv1TerminateSession(args, reply)
}
// UpdateSession implements SessionSv1UpdateSession
func (dS *DispatcherSessionSv1) UpdateSession(args *dispatchers.UpdateSessionWithApiKey,
func (dS *DispatcherSessionSv1) UpdateSession(args *sessions.V1UpdateSessionArgs,
reply *sessions.V1UpdateSessionReply) (err error) {
return dS.dS.SessionSv1UpdateSession(args, reply)
}
@@ -472,7 +472,7 @@ func (dS *DispatcherSessionSv1) ReplicateSessions(args *dispatchers.ArgsReplicat
return dS.dS.SessionSv1ReplicateSessions(args, reply)
}
func (dS *DispatcherSessionSv1) SetPassiveSession(args *dispatchers.SessionWithApiKey,
func (dS *DispatcherSessionSv1) SetPassiveSession(args *sessions.Session,
reply *string) (err error) {
return dS.dS.SessionSv1SetPassiveSession(args, reply)
}
@@ -486,44 +486,44 @@ type DispatcherResponder struct {
dS *dispatchers.DispatcherService
}
func (dS *DispatcherResponder) Status(args *dispatchers.TntWithApiKey, reply *map[string]interface{}) error {
func (dS *DispatcherResponder) Status(args *utils.TenantWithArgDispatcher, reply *map[string]interface{}) error {
return dS.dS.ResponderStatus(args, reply)
}
func (dS *DispatcherResponder) GetCost(args *dispatchers.CallDescriptorWithApiKey, reply *engine.CallCost) error {
func (dS *DispatcherResponder) GetCost(args *engine.CallDescriptor, reply *engine.CallCost) error {
return dS.dS.ResponderGetCost(args, reply)
}
func (dS *DispatcherResponder) Debit(args *dispatchers.CallDescriptorWithApiKey, reply *engine.CallCost) error {
func (dS *DispatcherResponder) Debit(args *engine.CallDescriptor, reply *engine.CallCost) error {
return dS.dS.ResponderDebit(args, reply)
}
func (dS *DispatcherResponder) MaxDebit(args *dispatchers.CallDescriptorWithApiKey, reply *engine.CallCost) error {
func (dS *DispatcherResponder) MaxDebit(args *engine.CallDescriptor, reply *engine.CallCost) error {
return dS.dS.ResponderMaxDebit(args, reply)
}
func (dS *DispatcherResponder) RefundIncrements(args *dispatchers.CallDescriptorWithApiKey, reply *engine.Account) error {
func (dS *DispatcherResponder) RefundIncrements(args *engine.CallDescriptor, reply *engine.Account) error {
return dS.dS.ResponderRefundIncrements(args, reply)
}
func (dS *DispatcherResponder) RefundRounding(args *dispatchers.CallDescriptorWithApiKey, reply *float64) error {
func (dS *DispatcherResponder) RefundRounding(args *engine.CallDescriptor, reply *float64) error {
return dS.dS.ResponderRefundRounding(args, reply)
}
func (dS *DispatcherResponder) GetMaxSessionTime(args *dispatchers.CallDescriptorWithApiKey, reply *time.Duration) error {
func (dS *DispatcherResponder) GetMaxSessionTime(args *engine.CallDescriptor, reply *time.Duration) error {
return dS.dS.ResponderGetMaxSessionTime(args, reply)
}
func (dS *DispatcherResponder) Shutdown(args *dispatchers.TntWithApiKey, reply *string) error {
func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithArgDispatcher, reply *string) error {
return dS.dS.ResponderShutdown(args, reply)
}
func (dS *DispatcherResponder) GetTimeout(args *dispatchers.TntWithApiKey, reply *time.Duration) error {
func (dS *DispatcherResponder) GetTimeout(args *utils.TenantWithArgDispatcher, reply *time.Duration) error {
return dS.dS.ResponderGetTimeout(args, reply)
}
// Ping used to detreminate if component is active
func (dS *DispatcherResponder) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dS *DispatcherResponder) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.ResponderPing(args, reply)
}
@@ -611,7 +611,7 @@ func (dS *DispatcherCacheSv1) LoadCache(args dispatchers.AttrReloadCacheWithApiK
}
// Ping used to detreminate if component is active
func (dS *DispatcherCacheSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dS *DispatcherCacheSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.CacheSv1Ping(args, reply)
}
@@ -635,7 +635,7 @@ func (dS *DispatcherGuardianSv1) RemoteUnlock(attr *dispatchers.AttrRemoteUnlock
}
// Ping used to detreminate if component is active
func (dS *DispatcherGuardianSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dS *DispatcherGuardianSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.GuardianSv1Ping(args, reply)
}
@@ -654,7 +654,7 @@ func (dS *DispatcherSchedulerSv1) Reload(attr *dispatchers.StringkWithApiKey, re
}
// Ping used to detreminate if component is active
func (dS *DispatcherSchedulerSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
func (dS *DispatcherSchedulerSv1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.SchedulerSv1Ping(args, reply)
}

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -28,7 +27,7 @@ func init() {
c := &CmdGetAttributeForEvent{
name: "attributes_for_event",
rpcMethod: utils.AttributeSv1GetAttributeForEvent,
rpcParams: &dispatchers.ArgsAttrProcessEventWithApiKey{},
rpcParams: &engine.AttrArgsProcessEvent{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -37,7 +36,7 @@ func init() {
type CmdGetAttributeForEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsAttrProcessEventWithApiKey
rpcParams *engine.AttrArgsProcessEvent
*CommandExecuter
}
@@ -51,7 +50,7 @@ func (self *CmdGetAttributeForEvent) RpcMethod() string {
func (self *CmdGetAttributeForEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsAttrProcessEventWithApiKey{}
self.rpcParams = &engine.AttrArgsProcessEvent{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdAttributesProcessEvent{
name: "attributes_process_event",
rpcMethod: utils.AttributeSv1ProcessEvent,
rpcParams: &dispatchers.ArgsAttrProcessEventWithApiKey{},
rpcParams: &engine.AttrArgsProcessEvent{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdAttributesProcessEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsAttrProcessEventWithApiKey
rpcParams *engine.AttrArgsProcessEvent
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdAttributesProcessEvent) RpcMethod() string {
func (self *CmdAttributesProcessEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsAttrProcessEventWithApiKey{}
self.rpcParams = &engine.AttrArgsProcessEvent{}
}
return self.rpcParams
}

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -28,7 +27,7 @@ func init() {
c := &CmdGetChargersForEvent{
name: "chargers_for_event",
rpcMethod: utils.ChargerSv1GetChargersForEvent,
rpcParams: &dispatchers.CGREvWithApiKey{},
rpcParams: &utils.CGREventWithArgDispatcher{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -37,7 +36,7 @@ func init() {
type CmdGetChargersForEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.CGREvWithApiKey
rpcParams *utils.CGREventWithArgDispatcher
*CommandExecuter
}
@@ -51,7 +50,7 @@ func (self *CmdGetChargersForEvent) RpcMethod() string {
func (self *CmdGetChargersForEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.CGREvWithApiKey{}
self.rpcParams = &utils.CGREventWithArgDispatcher{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdChargersProcessEvent{
name: "chargers_process_event",
rpcMethod: utils.ChargerSv1ProcessEvent,
rpcParams: &dispatchers.CGREvWithApiKey{},
rpcParams: &utils.CGREventWithArgDispatcher{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdChargersProcessEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.CGREvWithApiKey
rpcParams *utils.CGREventWithArgDispatcher
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdChargersProcessEvent) RpcMethod() string {
func (self *CmdChargersProcessEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.CGREvWithApiKey{}
self.rpcParams = &utils.CGREventWithArgDispatcher{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdGetResourceForEvent{
name: "resources_for_event",
rpcMethod: utils.ResourceSv1GetResourcesForEvent,
rpcParams: &dispatchers.ArgsV1ResUsageWithApiKey{},
rpcParams: &utils.ArgRSv1ResourceUsage{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -40,7 +39,7 @@ func init() {
type CmdGetResourceForEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsV1ResUsageWithApiKey
rpcParams *utils.ArgRSv1ResourceUsage
*CommandExecuter
}
@@ -54,7 +53,7 @@ func (self *CmdGetResourceForEvent) RpcMethod() string {
func (self *CmdGetResourceForEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsV1ResUsageWithApiKey{}
self.rpcParams = &utils.ArgRSv1ResourceUsage{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdSessionsAuthorize{
name: "session_authorize_event",
rpcMethod: utils.SessionSv1AuthorizeEventWithDigest,
rpcParams: &dispatchers.AuthorizeArgsWithApiKey{},
rpcParams: &sessions.V1AuthorizeArgs{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdSessionsAuthorize struct {
name string
rpcMethod string
rpcParams *dispatchers.AuthorizeArgsWithApiKey
rpcParams *sessions.V1AuthorizeArgs
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdSessionsAuthorize) RpcMethod() string {
func (self *CmdSessionsAuthorize) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.AuthorizeArgsWithApiKey{}
self.rpcParams = &sessions.V1AuthorizeArgs{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdSessionsInitiate{
name: "session_initiate",
rpcMethod: utils.SessionSv1InitiateSessionWithDigest,
rpcParams: &dispatchers.InitArgsWithApiKey{},
rpcParams: &sessions.V1InitSessionArgs{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdSessionsInitiate struct {
name string
rpcMethod string
rpcParams *dispatchers.InitArgsWithApiKey
rpcParams *sessions.V1InitSessionArgs
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdSessionsInitiate) RpcMethod() string {
func (self *CmdSessionsInitiate) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.InitArgsWithApiKey{}
self.rpcParams = &sessions.V1InitSessionArgs{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +28,7 @@ func init() {
c := &CmdSessionsProcessCDR{
name: "session_process_cdr",
rpcMethod: utils.SessionSv1ProcessCDR,
rpcParams: &dispatchers.CGREvWithApiKey{},
rpcParams: &utils.CGREventWithArgDispatcher{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -38,7 +37,7 @@ func init() {
type CmdSessionsProcessCDR struct {
name string
rpcMethod string
rpcParams *dispatchers.CGREvWithApiKey
rpcParams *utils.CGREventWithArgDispatcher
*CommandExecuter
}
@@ -52,7 +51,7 @@ func (self *CmdSessionsProcessCDR) RpcMethod() string {
func (self *CmdSessionsProcessCDR) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.CGREvWithApiKey{}
self.rpcParams = &utils.CGREventWithArgDispatcher{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdSessionsProcessEvent{
name: "session_process_event",
rpcMethod: utils.SessionSv1ProcessEvent,
rpcParams: &dispatchers.ProcessEventWithApiKey{},
rpcParams: &sessions.V1ProcessEventArgs{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdSessionsProcessEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ProcessEventWithApiKey
rpcParams *sessions.V1ProcessEventArgs
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdSessionsProcessEvent) RpcMethod() string {
func (self *CmdSessionsProcessEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ProcessEventWithApiKey{}
self.rpcParams = &sessions.V1ProcessEventArgs{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,7 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +29,7 @@ func init() {
c := &CmdSessionsTerminate{
name: "session_terminate",
rpcMethod: utils.SessionSv1TerminateSession,
rpcParams: &dispatchers.TerminateSessionWithApiKey{},
rpcParams: &sessions.V1TerminateSessionArgs{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -38,7 +38,7 @@ func init() {
type CmdSessionsTerminate struct {
name string
rpcMethod string
rpcParams *dispatchers.TerminateSessionWithApiKey
rpcParams *sessions.V1TerminateSessionArgs
*CommandExecuter
}
@@ -52,7 +52,7 @@ func (self *CmdSessionsTerminate) RpcMethod() string {
func (self *CmdSessionsTerminate) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.TerminateSessionWithApiKey{}
self.rpcParams = &sessions.V1TerminateSessionArgs{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdSessionsUpdate{
name: "session_update",
rpcMethod: utils.SessionSv1UpdateSession,
rpcParams: &dispatchers.UpdateSessionWithApiKey{},
rpcParams: &sessions.V1UpdateSessionArgs{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdSessionsUpdate struct {
name string
rpcMethod string
rpcParams *dispatchers.UpdateSessionWithApiKey
rpcParams *sessions.V1UpdateSessionArgs
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdSessionsUpdate) RpcMethod() string {
func (self *CmdSessionsUpdate) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.UpdateSessionWithApiKey{}
self.rpcParams = &sessions.V1UpdateSessionArgs{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,7 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +29,7 @@ func init() {
c := &CmdStatsQueueForEvent{
name: "stats_for_event",
rpcMethod: utils.StatSv1GetStatQueuesForEvent,
rpcParams: &dispatchers.ArgsStatProcessEventWithApiKey{},
rpcParams: &engine.StatsArgsProcessEvent{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +39,7 @@ func init() {
type CmdStatsQueueForEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsStatProcessEventWithApiKey
rpcParams *engine.StatsArgsProcessEvent
*CommandExecuter
}
@@ -53,7 +53,7 @@ func (self *CmdStatsQueueForEvent) RpcMethod() string {
func (self *CmdStatsQueueForEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsStatProcessEventWithApiKey{}
self.rpcParams = &engine.StatsArgsProcessEvent{}
}
return self.rpcParams
}

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/utils"
)
@@ -27,7 +26,7 @@ func init() {
c := &CmdGetStatQueueStringMetrics{
name: "stats_metrics",
rpcMethod: utils.StatSv1GetQueueStringMetrics,
rpcParams: &dispatchers.TntIDWithApiKey{},
rpcParams: &utils.TenantIDWithArgDispatcher{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -37,7 +36,7 @@ func init() {
type CmdGetStatQueueStringMetrics struct {
name string
rpcMethod string
rpcParams *dispatchers.TntIDWithApiKey
rpcParams *utils.TenantIDWithArgDispatcher
*CommandExecuter
}
@@ -51,7 +50,7 @@ func (self *CmdGetStatQueueStringMetrics) RpcMethod() string {
func (self *CmdGetStatQueueStringMetrics) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.TntIDWithApiKey{}
self.rpcParams = &utils.TenantIDWithArgDispatcher{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,7 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +29,7 @@ func init() {
c := &CmdStatQueueProcessEvent{
name: "stats_process_event",
rpcMethod: utils.StatSv1ProcessEvent,
rpcParams: &dispatchers.ArgsStatProcessEventWithApiKey{},
rpcParams: &engine.StatsArgsProcessEvent{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +39,7 @@ func init() {
type CmdStatQueueProcessEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsStatProcessEventWithApiKey
rpcParams *engine.StatsArgsProcessEvent
*CommandExecuter
}
@@ -53,7 +53,7 @@ func (self *CmdStatQueueProcessEvent) RpcMethod() string {
func (self *CmdStatQueueProcessEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsStatProcessEventWithApiKey{}
self.rpcParams = &engine.StatsArgsProcessEvent{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,6 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdSuppliersSort{
name: "suppliers",
rpcMethod: utils.SupplierSv1GetSuppliers,
rpcParams: &dispatchers.ArgsGetSuppliersWithApiKey{},
rpcParams: &engine.ArgsGetSuppliers{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdSuppliersSort struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsGetSuppliersWithApiKey
rpcParams *engine.ArgsGetSuppliers
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdSuppliersSort) RpcMethod() string {
func (self *CmdSuppliersSort) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsGetSuppliersWithApiKey{}
self.rpcParams = &engine.ArgsGetSuppliers{}
}
return self.rpcParams
}

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,7 +29,7 @@ func init() {
c := &CmdThresholdsForEvent{
name: "thresholds_for_event",
rpcMethod: utils.ThresholdSv1GetThresholdsForEvent,
rpcParams: &dispatchers.ArgsProcessEventWithApiKey{},
rpcParams: &engine.ArgsProcessEvent{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -39,7 +38,7 @@ func init() {
type CmdThresholdsForEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsProcessEventWithApiKey
rpcParams *engine.ArgsProcessEvent
*CommandExecuter
}
@@ -53,7 +52,7 @@ func (self *CmdThresholdsForEvent) RpcMethod() string {
func (self *CmdThresholdsForEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsProcessEventWithApiKey{}
self.rpcParams = &engine.ArgsProcessEvent{}
}
return self.rpcParams
}

View File

@@ -21,7 +21,7 @@ package console
import (
"time"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +29,7 @@ func init() {
c := &CmdThresholdProcessEvent{
name: "thresholds_process_event",
rpcMethod: utils.ThresholdSv1ProcessEvent,
rpcParams: &dispatchers.ArgsProcessEventWithApiKey{},
rpcParams: &engine.ArgsProcessEvent{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -38,7 +38,7 @@ func init() {
type CmdThresholdProcessEvent struct {
name string
rpcMethod string
rpcParams *dispatchers.ArgsProcessEventWithApiKey
rpcParams *engine.ArgsProcessEvent
*CommandExecuter
}
@@ -52,7 +52,7 @@ func (self *CmdThresholdProcessEvent) RpcMethod() string {
func (self *CmdThresholdProcessEvent) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &dispatchers.ArgsProcessEventWithApiKey{}
self.rpcParams = &engine.ArgsProcessEvent{}
}
return self.rpcParams
}

View File

@@ -24,43 +24,52 @@ import (
)
// AttributeSv1Ping interogates AttributeS server responsible to process the event
func (dS *DispatcherService) AttributeSv1Ping(args *CGREvWithApiKey,
func (dS *DispatcherService) AttributeSv1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.AttributeSv1Ping,
args.Tenant,
args.APIKey, args.Time); err != nil {
return
}
}
return dS.Dispatch(args.CGREvent, utils.MetaAttributes, args.RouteID,
utils.AttributeSv1Ping, args, reply)
}
// AttributeSv1GetAttributeForEvent is the dispatcher method for AttributeSv1.GetAttributeForEvent
func (dS *DispatcherService) AttributeSv1GetAttributeForEvent(args *engine.AttrArgsProcessEvent,
reply *engine.AttributeProfile) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.AttributeSv1GetAttributeForEvent,
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes, args.RouteID,
utils.AttributeSv1Ping, args.CGREvent, reply)
utils.AttributeSv1GetAttributeForEvent, args, reply)
}
// AttributeSv1GetAttributeForEvent is the dispatcher method for AttributeSv1.GetAttributeForEvent
func (dS *DispatcherService) AttributeSv1GetAttributeForEvent(args *ArgsAttrProcessEventWithApiKey,
reply *engine.AttributeProfile) (err error) {
if dS.attrS != nil {
if err = dS.authorize(utils.AttributeSv1GetAttributeForEvent,
args.AttrArgsProcessEvent.CGREvent.Tenant,
args.APIKey, args.AttrArgsProcessEvent.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes, args.RouteID,
utils.AttributeSv1GetAttributeForEvent, args.AttrArgsProcessEvent, reply)
}
func (dS *DispatcherService) AttributeSv1ProcessEvent(args *ArgsAttrProcessEventWithApiKey,
func (dS *DispatcherService) AttributeSv1ProcessEvent(args *engine.AttrArgsProcessEvent,
reply *engine.AttrSProcessEventReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.AttributeSv1ProcessEvent,
args.AttrArgsProcessEvent.CGREvent.Tenant,
args.APIKey, args.AttrArgsProcessEvent.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes, args.RouteID,
utils.AttributeSv1ProcessEvent, args.AttrArgsProcessEvent, reply)
utils.AttributeSv1ProcessEvent, args, reply)
}

View File

@@ -35,6 +35,7 @@ var sTestsDspAttr = []func(t *testing.T){
testDspAttrGetAttrRoundRobin,
testDspAttrPing,
testDspAttrTestMissingArgDispatcher,
testDspAttrTestMissingApiKey,
testDspAttrTestUnknownApiKey,
testDspAttrTestAuthKey,
@@ -65,12 +66,12 @@ func testDspAttrPingFailover(t *testing.T) {
t.Errorf("Received: %s", reply)
}
reply = ""
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "attr12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("attr12345"),
},
}
if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil {
@@ -95,21 +96,19 @@ func testDspAttrPingFailover(t *testing.T) {
}
func testDspAttrGetAttrFailover(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "attr12345",
},
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1002",
utils.EVENT_NAME: "Event1",
},
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1002",
utils.EVENT_NAME: "Event1",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("attr12345"),
},
}
eAttrPrf := &engine.AttributeProfile{
Tenant: args.Tenant,
@@ -191,12 +190,12 @@ func testDspAttrPing(t *testing.T) {
if dispEngine.RCP == nil {
t.Fatal(dispEngine.RCP)
}
if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "attr12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("attr12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -205,20 +204,37 @@ func testDspAttrPing(t *testing.T) {
}
}
func testDspAttrTestMissingApiKey(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
func testDspAttrTestMissingArgDispatcher(t *testing.T) {
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
}
var attrReply *engine.AttributeProfile
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
args, &attrReply); err == nil || err.Error() != utils.NewErrMandatoryIeMissing("ArgDispatcher").Error() {
t.Errorf("Error:%v rply=%s", err, utils.ToJSON(attrReply))
}
}
func testDspAttrTestMissingApiKey(t *testing.T) {
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{},
}
var attrReply *engine.AttributeProfile
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
args, &attrReply); err == nil || err.Error() != utils.NewErrMandatoryIeMissing(utils.APIKey).Error() {
t.Errorf("Error:%v rply=%s", err, utils.ToJSON(attrReply))
@@ -226,20 +242,18 @@ func testDspAttrTestMissingApiKey(t *testing.T) {
}
func testDspAttrTestUnknownApiKey(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "1234",
},
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("1234"),
},
}
var attrReply *engine.AttributeProfile
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
@@ -249,20 +263,18 @@ func testDspAttrTestUnknownApiKey(t *testing.T) {
}
func testDspAttrTestAuthKey(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
},
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
var attrReply *engine.AttributeProfile
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
@@ -272,20 +284,18 @@ func testDspAttrTestAuthKey(t *testing.T) {
}
func testDspAttrTestAuthKey2(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "attr12345",
},
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("attr12345"),
},
}
eAttrPrf := &engine.AttributeProfile{
Tenant: args.Tenant,
@@ -339,21 +349,19 @@ func testDspAttrTestAuthKey2(t *testing.T) {
}
func testDspAttrTestAuthKey3(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "attr12345",
},
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
utils.EVENT_NAME: "Event1",
},
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1001",
utils.EVENT_NAME: "Event1",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("attr12345"),
},
}
var attrReply *engine.AttributeProfile
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
@@ -363,21 +371,19 @@ func testDspAttrTestAuthKey3(t *testing.T) {
}
func testDspAttrGetAttrRoundRobin(t *testing.T) {
args := &ArgsAttrProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "attr12345",
},
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1002",
utils.EVENT_NAME: "RoundRobin",
},
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
Event: map[string]interface{}{
utils.Account: "1002",
utils.EVENT_NAME: "RoundRobin",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("attr12345"),
},
}
eAttrPrf := &engine.AttributeProfile{
Tenant: args.Tenant,

View File

@@ -26,8 +26,11 @@ import (
)
// CacheSv1Ping interogates CacheSv1 server responsible to process the event
func (dS *DispatcherService) CacheSv1Ping(args *CGREvWithApiKey,
func (dS *DispatcherService) CacheSv1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1Ping,
args.CGREvent.Tenant,
@@ -35,7 +38,7 @@ func (dS *DispatcherService) CacheSv1Ping(args *CGREvWithApiKey,
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaCaches, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaCaches, args.RouteID,
utils.CacheSv1Ping, args.CGREvent, reply)
}
@@ -56,6 +59,9 @@ func (dS *DispatcherService) CacheSv1GetItemIDs(args *ArgsGetCacheItemIDsWithApi
// HasItem verifies the existence of an Item in cache
func (dS *DispatcherService) CacheSv1HasItem(args *ArgsGetCacheItemWithApiKey,
reply *bool) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1HasItem,
args.TenantArg.Tenant,
@@ -70,6 +76,9 @@ func (dS *DispatcherService) CacheSv1HasItem(args *ArgsGetCacheItemWithApiKey,
// GetItemExpiryTime returns the expiryTime for an item
func (dS *DispatcherService) CacheSv1GetItemExpiryTime(args *ArgsGetCacheItemWithApiKey,
reply *time.Time) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1GetItemExpiryTime,
args.TenantArg.Tenant,
@@ -84,6 +93,9 @@ func (dS *DispatcherService) CacheSv1GetItemExpiryTime(args *ArgsGetCacheItemWit
// RemoveItem removes the Item with ID from cache
func (dS *DispatcherService) CacheSv1RemoveItem(args *ArgsGetCacheItemWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1RemoveItem,
args.TenantArg.Tenant,
@@ -98,6 +110,9 @@ func (dS *DispatcherService) CacheSv1RemoveItem(args *ArgsGetCacheItemWithApiKey
// Clear will clear partitions in the cache (nil fol all, empty slice for none)
func (dS *DispatcherService) CacheSv1Clear(args *AttrCacheIDsWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1Clear,
args.TenantArg.Tenant,
@@ -111,6 +126,9 @@ func (dS *DispatcherService) CacheSv1Clear(args *AttrCacheIDsWithApiKey,
// FlushCache wipes out cache for a prefix or completely
func (dS *DispatcherService) CacheSv1FlushCache(args AttrReloadCacheWithApiKey, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1FlushCache,
args.TenantArg.Tenant,
@@ -125,6 +143,9 @@ func (dS *DispatcherService) CacheSv1FlushCache(args AttrReloadCacheWithApiKey,
// GetCacheStats returns CacheStats filtered by cacheIDs
func (dS *DispatcherService) CacheSv1GetCacheStats(args *AttrCacheIDsWithApiKey,
reply *map[string]*ltcache.CacheStats) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1GetCacheStats,
args.TenantArg.Tenant,
@@ -138,6 +159,9 @@ func (dS *DispatcherService) CacheSv1GetCacheStats(args *AttrCacheIDsWithApiKey,
// PrecacheStatus checks status of active precache processes
func (dS *DispatcherService) CacheSv1PrecacheStatus(args *AttrCacheIDsWithApiKey, reply *map[string]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1PrecacheStatus,
args.TenantArg.Tenant,
@@ -152,6 +176,9 @@ func (dS *DispatcherService) CacheSv1PrecacheStatus(args *AttrCacheIDsWithApiKey
// HasGroup checks existence of a group in cache
func (dS *DispatcherService) CacheSv1HasGroup(args *ArgsGetGroupWithApiKey,
reply *bool) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1HasGroup,
args.TenantArg.Tenant,
@@ -166,6 +193,9 @@ func (dS *DispatcherService) CacheSv1HasGroup(args *ArgsGetGroupWithApiKey,
// GetGroupItemIDs returns a list of itemIDs in a cache group
func (dS *DispatcherService) CacheSv1GetGroupItemIDs(args *ArgsGetGroupWithApiKey,
reply *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1GetGroupItemIDs,
args.TenantArg.Tenant,
@@ -180,6 +210,9 @@ func (dS *DispatcherService) CacheSv1GetGroupItemIDs(args *ArgsGetGroupWithApiKe
// RemoveGroup will remove a group and all items belonging to it from cache
func (dS *DispatcherService) CacheSv1RemoveGroup(args *ArgsGetGroupWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1RemoveGroup,
args.TenantArg.Tenant,
@@ -193,6 +226,9 @@ func (dS *DispatcherService) CacheSv1RemoveGroup(args *ArgsGetGroupWithApiKey,
// ReloadCache reloads cache from DB for a prefix or completely
func (dS *DispatcherService) CacheSv1ReloadCache(args AttrReloadCacheWithApiKey, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1ReloadCache,
args.TenantArg.Tenant,
@@ -206,6 +242,9 @@ func (dS *DispatcherService) CacheSv1ReloadCache(args AttrReloadCacheWithApiKey,
// LoadCache loads cache from DB for a prefix or completely
func (dS *DispatcherService) CacheSv1LoadCache(args AttrReloadCacheWithApiKey, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.CacheSv1LoadCache,
args.TenantArg.Tenant,

View File

@@ -62,12 +62,12 @@ func testDspChcPing(t *testing.T) {
if dispEngine.RCP == nil {
t.Fatal(dispEngine.RCP)
}
if err := dispEngine.RCP.Call(utils.CacheSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.CacheSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -85,8 +85,8 @@ func testDspChcLoadAfterFolder(t *testing.T) {
expStats[utils.CacheDestinations].Items = 4
expStats[utils.CacheLoadIDs].Items = 17
args := AttrCacheIDsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -100,8 +100,8 @@ func testDspChcLoadAfterFolder(t *testing.T) {
reply := ""
// Simple test that command is executed without errors
if err := dispEngine.RCP.Call(utils.CacheSv1LoadCache, AttrReloadCacheWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -171,8 +171,8 @@ func testDspChcPrecacheStatus(t *testing.T) {
}
if err := dispEngine.RCP.Call(utils.CacheSv1PrecacheStatus, AttrCacheIDsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -191,8 +191,8 @@ func testDspChcGetItemIDs(t *testing.T) {
ArgsGetCacheItemIDs: engine.ArgsGetCacheItemIDs{
CacheID: utils.CacheChargerProfiles,
},
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -214,8 +214,8 @@ func testDspChcHasItem(t *testing.T) {
CacheID: utils.CacheChargerProfiles,
ItemID: "cgrates.org:DEFAULT",
},
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -236,8 +236,8 @@ func testDspChcGetItemExpiryTime(t *testing.T) {
CacheID: utils.CacheChargerProfiles,
ItemID: "cgrates.org:DEFAULT",
},
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -253,8 +253,8 @@ func testDspChcGetItemExpiryTime(t *testing.T) {
func testDspChcReloadCache(t *testing.T) {
reply := ""
if err := dispEngine.RCP.Call(utils.CacheSv1ReloadCache, AttrReloadCacheWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -273,8 +273,8 @@ func testDspChcRemoveItem(t *testing.T) {
CacheID: utils.CacheChargerProfiles,
ItemID: "cgrates.org:DEFAULT",
},
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -301,8 +301,8 @@ func testDspChcRemoveItem(t *testing.T) {
func testDspChcClear(t *testing.T) {
reply := ""
if err := dispEngine.RCP.Call(utils.CacheSv1Clear, AttrCacheIDsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -315,8 +315,8 @@ func testDspChcClear(t *testing.T) {
var rcvStats map[string]*ltcache.CacheStats
expStats := engine.GetDefaultEmptyCacheStats()
if err := dispEngine.RCP.Call(utils.CacheSv1GetCacheStats, AttrCacheIDsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -331,8 +331,8 @@ func testDspChcClear(t *testing.T) {
func testDspChcFlush(t *testing.T) {
reply := ""
if err := dispEngine.RCP.Call(utils.CacheSv1FlushCache, AttrReloadCacheWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -348,8 +348,8 @@ func testDspChcFlush(t *testing.T) {
var rcvStats map[string]*ltcache.CacheStats
expStats := engine.GetDefaultEmptyCacheStats()
if err := dispEngine.RCP.Call(utils.CacheSv1GetCacheStats, AttrCacheIDsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chc12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chc12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",

View File

@@ -23,20 +23,26 @@ import (
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) ChargerSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
func (dS *DispatcherService) ChargerSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ChargerSv1Ping,
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
args.Tenant,
args.APIKey, args.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
utils.ChargerSv1Ping, args.CGREvent, reply)
return dS.Dispatch(args.CGREvent, utils.MetaChargers, args.RouteID,
utils.ChargerSv1Ping, args, reply)
}
func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *CGREvWithApiKey,
func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *utils.CGREventWithArgDispatcher,
reply *engine.ChargerProfiles) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ChargerSv1GetChargersForEvent,
args.CGREvent.Tenant,
@@ -44,12 +50,15 @@ func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *CGREvWithApiKey
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
utils.ChargerSv1GetChargersForEvent, args.CGREvent, reply)
return dS.Dispatch(args.CGREvent, utils.MetaChargers, args.RouteID,
utils.ChargerSv1GetChargersForEvent, args, reply)
}
func (dS *DispatcherService) ChargerSv1ProcessEvent(args *CGREvWithApiKey,
func (dS *DispatcherService) ChargerSv1ProcessEvent(args *utils.CGREventWithArgDispatcher,
reply *[]*engine.ChrgSProcessEventReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ChargerSv1ProcessEvent,
args.CGREvent.Tenant,
@@ -57,6 +66,6 @@ func (dS *DispatcherService) ChargerSv1ProcessEvent(args *CGREvWithApiKey,
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
utils.ChargerSv1ProcessEvent, args.CGREvent, reply)
return dS.Dispatch(args.CGREvent, utils.MetaChargers, args.RouteID,
utils.ChargerSv1ProcessEvent, args, reply)
}

View File

@@ -54,12 +54,12 @@ func testDspCppPingFailover(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "chrg12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chrg12345"),
},
}
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &ev, &reply); err != nil {
@@ -82,11 +82,8 @@ func testDspCppPingFailover(t *testing.T) {
}
func testDspCppGetChtgFailover(t *testing.T) {
args := CGREvWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chrg12345",
},
CGREvent: utils.CGREvent{
args := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
@@ -94,6 +91,9 @@ func testDspCppGetChtgFailover(t *testing.T) {
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chrg12345"),
},
}
eChargers := &engine.ChargerProfiles{
&engine.ChargerProfile{
@@ -130,12 +130,12 @@ func testDspCppPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "chrg12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chrg12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -145,17 +145,17 @@ func testDspCppPing(t *testing.T) {
}
func testDspCppTestAuthKey(t *testing.T) {
args := CGREvWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
},
CGREvent: utils.CGREvent{
args := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
var reply *engine.ChargerProfiles
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
@@ -165,17 +165,17 @@ func testDspCppTestAuthKey(t *testing.T) {
}
func testDspCppTestAuthKey2(t *testing.T) {
args := CGREvWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chrg12345",
},
CGREvent: utils.CGREvent{
args := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chrg12345"),
},
}
eChargers := &engine.ChargerProfiles{
&engine.ChargerProfile{
@@ -197,11 +197,8 @@ func testDspCppTestAuthKey2(t *testing.T) {
}
func testDspCppGetChtgRoundRobin(t *testing.T) {
args := CGREvWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "chrg12345",
},
CGREvent: utils.CGREvent{
args := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
@@ -209,6 +206,9 @@ func testDspCppGetChtgRoundRobin(t *testing.T) {
utils.Account: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("chrg12345"),
},
}
eChargers := &engine.ChargerProfiles{
&engine.ChargerProfile{

View File

@@ -78,8 +78,8 @@ func (dS *DispatcherService) authorizeEvent(ev *utils.CGREvent,
return
}
func (dS *DispatcherService) authorize(method, tenant, apiKey string, evTime *time.Time) (err error) {
if apiKey == "" {
func (dS *DispatcherService) authorize(method, tenant string, apiKey *string, evTime *time.Time) (err error) {
if apiKey == nil || *apiKey == "" {
return utils.NewErrMandatoryIeMissing(utils.APIKey)
}
ev := &utils.CGREvent{
@@ -87,7 +87,7 @@ func (dS *DispatcherService) authorize(method, tenant, apiKey string, evTime *ti
ID: utils.UUIDSha1Prefix(),
Time: evTime,
Event: map[string]interface{}{
utils.APIKey: apiKey,
utils.APIKey: *apiKey,
},
}
var rplyEv engine.AttrSProcessEventReply

View File

@@ -25,8 +25,11 @@ import (
)
// GuardianSv1Ping interogates GuardianSv1 server responsible to process the event
func (dS *DispatcherService) GuardianSv1Ping(args *CGREvWithApiKey,
func (dS *DispatcherService) GuardianSv1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.GuardianSv1Ping,
args.CGREvent.Tenant,
@@ -34,13 +37,16 @@ func (dS *DispatcherService) GuardianSv1Ping(args *CGREvWithApiKey,
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaGuardian, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaGuardian, args.RouteID,
utils.GuardianSv1Ping, args.CGREvent, reply)
}
// RemoteLock will lock a key from remote
func (dS *DispatcherService) GuardianSv1RemoteLock(args *AttrRemoteLockWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.GuardianSv1RemoteLock,
args.TenantArg.Tenant,
@@ -55,6 +61,9 @@ func (dS *DispatcherService) GuardianSv1RemoteLock(args *AttrRemoteLockWithApiKe
// RemoteUnlock will unlock a key from remote based on reference ID
func (dS *DispatcherService) GuardianSv1RemoteUnlock(args *AttrRemoteUnlockWithApiKey,
reply *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.GuardianSv1RemoteUnlock,
args.TenantArg.Tenant,

View File

@@ -45,12 +45,12 @@ func testDspGrdPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.GuardianSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.GuardianSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "grd12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("grd12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -72,8 +72,8 @@ func testDspGrdLock(t *testing.T) {
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "grd12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("grd12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -85,8 +85,8 @@ func testDspGrdLock(t *testing.T) {
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "grd12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("grd12345"),
},
}, &unlockReply); err != nil {
t.Error(err)

View File

@@ -23,7 +23,10 @@ import (
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) ResourceSv1Ping(args *CGREvWithApiKey, rpl *string) (err error) {
func (dS *DispatcherService) ResourceSv1Ping(args *utils.CGREventWithArgDispatcher, rpl *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResourceSv1Ping,
args.CGREvent.Tenant,
@@ -31,62 +34,74 @@ func (dS *DispatcherService) ResourceSv1Ping(args *CGREvWithApiKey, rpl *string)
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaResources, args.RouteID,
utils.ResourceSv1Ping, args.CGREvent, rpl)
}
func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(args *ArgsV1ResUsageWithApiKey,
func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(args *utils.ArgRSv1ResourceUsage,
reply *engine.Resources) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResourceSv1GetResourcesForEvent,
args.ArgRSv1ResourceUsage.CGREvent.Tenant,
args.APIKey, args.ArgRSv1ResourceUsage.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
utils.ResourceSv1GetResourcesForEvent, args.ArgRSv1ResourceUsage, reply)
utils.ResourceSv1GetResourcesForEvent, args, reply)
}
func (dS *DispatcherService) ResourceSv1AuthorizeResources(args *ArgsV1ResUsageWithApiKey,
func (dS *DispatcherService) ResourceSv1AuthorizeResources(args *utils.ArgRSv1ResourceUsage,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResourceSv1AuthorizeResources,
args.ArgRSv1ResourceUsage.CGREvent.Tenant,
args.APIKey, args.ArgRSv1ResourceUsage.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
utils.ResourceSv1AuthorizeResources, args.ArgRSv1ResourceUsage, reply)
utils.ResourceSv1AuthorizeResources, args, reply)
}
func (dS *DispatcherService) ResourceSv1AllocateResources(args *ArgsV1ResUsageWithApiKey,
func (dS *DispatcherService) ResourceSv1AllocateResources(args *utils.ArgRSv1ResourceUsage,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResourceSv1AllocateResources,
args.ArgRSv1ResourceUsage.CGREvent.Tenant,
args.APIKey, args.ArgRSv1ResourceUsage.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
utils.ResourceSv1AllocateResources, args.ArgRSv1ResourceUsage, reply)
utils.ResourceSv1AllocateResources, args, reply)
}
func (dS *DispatcherService) ResourceSv1ReleaseResources(args *ArgsV1ResUsageWithApiKey,
func (dS *DispatcherService) ResourceSv1ReleaseResources(args *utils.ArgRSv1ResourceUsage,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResourceSv1ReleaseResources,
args.ArgRSv1ResourceUsage.CGREvent.Tenant,
args.APIKey, args.ArgRSv1ResourceUsage.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
utils.ResourceSv1ReleaseResources, args.ArgRSv1ResourceUsage, reply)
utils.ResourceSv1ReleaseResources, args, reply)
}

View File

@@ -53,12 +53,12 @@ func testDspResPingFailover(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "res12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &ev, &reply); err != nil {
@@ -87,12 +87,12 @@ func testDspResPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "res12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -103,20 +103,18 @@ func testDspResPing(t *testing.T) {
func testDspResTestAuthKey(t *testing.T) {
var rs *engine.Resources
args := &ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Event: map[string]interface{}{
utils.Account: "1001",
utils.Destination: "1002",
},
args := &utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Event: map[string]interface{}{
utils.Account: "1001",
utils.Destination: "1002",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1GetResourcesForEvent,
@@ -127,20 +125,18 @@ func testDspResTestAuthKey(t *testing.T) {
func testDspResTestAuthKey2(t *testing.T) {
var rs *engine.Resources
args := &ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "res12345",
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Event: map[string]interface{}{
utils.Account: "1001",
utils.Destination: "1002",
},
args := &utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Event: map[string]interface{}{
utils.Account: "1001",
utils.Destination: "1002",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
eRs := &engine.Resources{
&engine.Resource{
@@ -161,20 +157,18 @@ func testDspResTestAuthKey2(t *testing.T) {
func testDspResTestAuthKey3(t *testing.T) {
// first event matching Resource1
var reply string
argsRU := ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "res12345",
argsRU := utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e51",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e51",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
Units: 1,
Units: 1,
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1AllocateResources,
@@ -191,20 +185,18 @@ func testDspResTestAuthKey3(t *testing.T) {
} else if reply != eAllocationMsg { // already 3 usages active before allow call, we should have now more than allowed
t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply)
}
argsRU = ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "res12345",
argsRU = utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
Units: 17,
Units: 17,
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1AuthorizeResources,
@@ -213,19 +205,17 @@ func testDspResTestAuthKey3(t *testing.T) {
}
// relase the only resource active for Resource1
argsRU = ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "res12345",
argsRU = utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1ReleaseResources,
@@ -234,20 +224,18 @@ func testDspResTestAuthKey3(t *testing.T) {
}
// try reserving with full units for Resource1, case which did not work in previous test
// only match Resource1 since we don't want for storing of the resource2 bellow
argsRU = ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "res12345",
argsRU = utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
Units: 7,
Units: 7,
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1AuthorizeResources, argsRU, &reply); err != nil {
@@ -256,19 +244,17 @@ func testDspResTestAuthKey3(t *testing.T) {
t.Error("Unexpected reply returned", reply)
}
var rs *engine.Resources
args := &ArgsV1ResUsageWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "res12345",
args := &utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "Event5",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "Event5",
Event: map[string]interface{}{
"Account": "1002",
"Subject": "1001",
"Destination": "1002"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("res12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil {

View File

@@ -26,8 +26,11 @@ import (
)
// ResponderPing interogates Responder server responsible to process the event
func (dS *DispatcherService) ResponderPing(args *CGREvWithApiKey,
func (dS *DispatcherService) ResponderPing(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderPing,
args.CGREvent.Tenant,
@@ -35,12 +38,15 @@ func (dS *DispatcherService) ResponderPing(args *CGREvWithApiKey,
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaResponder, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaResponder, args.RouteID,
utils.ResponderPing, args.CGREvent, reply)
}
func (dS *DispatcherService) ResponderStatus(args *TntWithApiKey,
func (dS *DispatcherService) ResponderStatus(args *utils.TenantWithArgDispatcher,
reply *map[string]interface{}) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderStatus, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
@@ -53,80 +59,101 @@ func (dS *DispatcherService) ResponderStatus(args *TntWithApiKey,
"", reply)
}
func (dS *DispatcherService) ResponderGetCost(args *CallDescriptorWithApiKey,
func (dS *DispatcherService) ResponderGetCost(args *engine.CallDescriptor,
reply *engine.CallCost) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderGetCost, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderGetCost, args.CallDescriptor, reply)
return dS.Dispatch(args.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderGetCost, args, reply)
}
func (dS *DispatcherService) ResponderDebit(args *CallDescriptorWithApiKey,
func (dS *DispatcherService) ResponderDebit(args *engine.CallDescriptor,
reply *engine.CallCost) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderDebit, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderDebit, args.CallDescriptor, reply)
return dS.Dispatch(args.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderDebit, args, reply)
}
func (dS *DispatcherService) ResponderMaxDebit(args *CallDescriptorWithApiKey,
func (dS *DispatcherService) ResponderMaxDebit(args *engine.CallDescriptor,
reply *engine.CallCost) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderMaxDebit, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderMaxDebit, args.CallDescriptor, reply)
return dS.Dispatch(args.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderMaxDebit, args, reply)
}
func (dS *DispatcherService) ResponderRefundIncrements(args *CallDescriptorWithApiKey,
func (dS *DispatcherService) ResponderRefundIncrements(args *engine.CallDescriptor,
reply *engine.Account) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderRefundIncrements, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderRefundIncrements, args.CallDescriptor, reply)
return dS.Dispatch(args.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderRefundIncrements, args, reply)
}
func (dS *DispatcherService) ResponderRefundRounding(args *CallDescriptorWithApiKey,
func (dS *DispatcherService) ResponderRefundRounding(args *engine.CallDescriptor,
reply *float64) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderRefundRounding, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderRefundRounding, args.CallDescriptor, reply)
return dS.Dispatch(args.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderRefundRounding, args, reply)
}
func (dS *DispatcherService) ResponderGetMaxSessionTime(args *CallDescriptorWithApiKey,
func (dS *DispatcherService) ResponderGetMaxSessionTime(args *engine.CallDescriptor,
reply *time.Duration) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderGetMaxSessionTime, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderGetMaxSessionTime, args.CallDescriptor, reply)
return dS.Dispatch(args.AsCGREvent(), utils.MetaResponder,
args.RouteID, utils.ResponderGetMaxSessionTime, args, reply)
}
func (dS *DispatcherService) ResponderShutdown(args *TntWithApiKey,
func (dS *DispatcherService) ResponderShutdown(args *utils.TenantWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderShutdown, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
@@ -139,8 +166,11 @@ func (dS *DispatcherService) ResponderShutdown(args *TntWithApiKey,
"", reply)
}
func (dS *DispatcherService) ResponderGetTimeout(args *TntWithApiKey,
func (dS *DispatcherService) ResponderGetTimeout(args *utils.TenantWithArgDispatcher,
reply *time.Duration) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ResponderGetTimeout, args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {

View File

@@ -51,12 +51,12 @@ func testDspResponderStatus(t *testing.T) {
} else if reply[utils.NodeID] != "ALL" {
t.Errorf("Received: %s", reply)
}
ev := TntWithApiKey{
TenantArg: utils.TenantArg{
ev := utils.TenantWithArgDispatcher{
TenantArg: &utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "rsp12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("rsp12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResponderStatus, &ev, &reply); err != nil {
@@ -76,24 +76,24 @@ func testDspResponderStatus(t *testing.T) {
func getNodeWithRoute(route string, t *testing.T) string {
var reply map[string]interface{}
var pingReply string
pingEv := CGREvWithApiKey{
CGREvent: utils.CGREvent{
pingEv := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
utils.EVENT_NAME: "Random",
},
},
DispatcherResource: DispatcherResource{
APIKey: "rsp12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("rsp12345"),
RouteID: &route,
},
}
ev := TntWithApiKey{
TenantArg: utils.TenantArg{
ev := utils.TenantWithArgDispatcher{
TenantArg: &utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "rsp12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("rsp12345"),
RouteID: &route,
},
}
@@ -122,12 +122,12 @@ func testDspResponderRandom(t *testing.T) {
func testDspResponderShutdown(t *testing.T) {
var reply string
var statusReply map[string]interface{}
ev := TntWithApiKey{
TenantArg: utils.TenantArg{
ev := utils.TenantWithArgDispatcher{
TenantArg: &utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "rsp12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("rsp12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResponderShutdown, &ev, &reply); err != nil {
@@ -151,15 +151,15 @@ func testDspResponderShutdown(t *testing.T) {
func testDspResponderBroadcast(t *testing.T) {
var pingReply string
pingEv := CGREvWithApiKey{
CGREvent: utils.CGREvent{
pingEv := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
Event: map[string]interface{}{
utils.EVENT_NAME: "Broadcast",
},
},
DispatcherResource: DispatcherResource{
APIKey: "rsp12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("rsp12345"),
},
}
if err := dispEngine.RCP.Call(utils.ResponderPing, pingEv, &pingReply); err != nil {

View File

@@ -24,7 +24,10 @@ import (
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) SchedulerSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
func (dS *DispatcherService) SchedulerSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SchedulerSv1Ping,
args.CGREvent.Tenant,
@@ -32,11 +35,14 @@ func (dS *DispatcherService) SchedulerSv1Ping(args *CGREvWithApiKey, reply *stri
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaScheduler, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaScheduler, args.RouteID,
utils.SchedulerSv1Ping, args.CGREvent, reply)
}
func (dS *DispatcherService) SchedulerSv1Reload(args *StringkWithApiKey, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SchedulerSv1Ping,
args.TenantArg.Tenant,

View File

@@ -42,12 +42,12 @@ func testDspSchedPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.SchedulerSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.SchedulerSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "sched12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("sched12345"),
},
}, &reply); err != nil {
t.Error(err)

View File

@@ -25,7 +25,10 @@ import (
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) SessionSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
func (dS *DispatcherService) SessionSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1Ping,
args.CGREvent.Tenant,
@@ -33,77 +36,95 @@ func (dS *DispatcherService) SessionSv1Ping(args *CGREvWithApiKey, reply *string
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1Ping, args.CGREvent, reply)
}
func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *AuthorizeArgsWithApiKey,
func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *sessions.V1AuthorizeArgs,
reply *sessions.V1AuthorizeReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1AuthorizeEvent,
args.V1AuthorizeArgs.CGREvent.Tenant,
args.APIKey, args.V1AuthorizeArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.V1AuthorizeArgs.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1AuthorizeEvent, args.V1AuthorizeArgs, reply)
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1AuthorizeEvent, args, reply)
}
func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *AuthorizeArgsWithApiKey,
func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs,
reply *sessions.V1AuthorizeReplyWithDigest) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1AuthorizeEventWithDigest,
args.V1AuthorizeArgs.CGREvent.Tenant,
args.APIKey, args.V1AuthorizeArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.V1AuthorizeArgs.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1AuthorizeEventWithDigest, args.V1AuthorizeArgs, reply)
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1AuthorizeEventWithDigest, args, reply)
}
func (dS *DispatcherService) SessionSv1InitiateSession(args *InitArgsWithApiKey,
func (dS *DispatcherService) SessionSv1InitiateSession(args *sessions.V1InitSessionArgs,
reply *sessions.V1InitSessionReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1InitiateSession,
args.V1InitSessionArgs.CGREvent.Tenant,
args.APIKey, args.V1InitSessionArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.V1InitSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1InitiateSession, args.V1InitSessionArgs, reply)
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1InitiateSession, args, reply)
}
func (dS *DispatcherService) SessionSv1InitiateSessionWithDigest(args *InitArgsWithApiKey,
func (dS *DispatcherService) SessionSv1InitiateSessionWithDigest(args *sessions.V1InitSessionArgs,
reply *sessions.V1InitReplyWithDigest) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1InitiateSessionWithDigest,
args.V1InitSessionArgs.CGREvent.Tenant,
args.APIKey, args.V1InitSessionArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.V1InitSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1InitiateSessionWithDigest, args.V1InitSessionArgs, reply)
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1InitiateSessionWithDigest, args, reply)
}
func (dS *DispatcherService) SessionSv1UpdateSession(args *UpdateSessionWithApiKey,
func (dS *DispatcherService) SessionSv1UpdateSession(args *sessions.V1UpdateSessionArgs,
reply *sessions.V1UpdateSessionReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1UpdateSession,
args.V1UpdateSessionArgs.CGREvent.Tenant,
args.APIKey, args.V1UpdateSessionArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.V1UpdateSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1UpdateSession, args.V1UpdateSessionArgs, reply)
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1UpdateSession, args, reply)
}
func (dS *DispatcherService) SessionSv1SyncSessions(args *TntWithApiKey,
func (dS *DispatcherService) SessionSv1SyncSessions(args *utils.TenantWithArgDispatcher,
reply *sessions.V1UpdateSessionReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1SyncSessions,
args.TenantArg.Tenant,
@@ -115,21 +136,27 @@ func (dS *DispatcherService) SessionSv1SyncSessions(args *TntWithApiKey,
utils.SessionSv1SyncSessions, &args.TenantArg.Tenant, reply)
}
func (dS *DispatcherService) SessionSv1TerminateSession(args *TerminateSessionWithApiKey,
func (dS *DispatcherService) SessionSv1TerminateSession(args *sessions.V1TerminateSessionArgs,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1TerminateSession,
args.V1TerminateSessionArgs.CGREvent.Tenant,
args.APIKey, args.V1TerminateSessionArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.V1TerminateSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1TerminateSession, args.V1TerminateSessionArgs, reply)
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1TerminateSession, args, reply)
}
func (dS *DispatcherService) SessionSv1ProcessCDR(args *CGREvWithApiKey,
func (dS *DispatcherService) SessionSv1ProcessCDR(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1ProcessCDR,
args.CGREvent.Tenant,
@@ -137,25 +164,31 @@ func (dS *DispatcherService) SessionSv1ProcessCDR(args *CGREvWithApiKey,
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1ProcessCDR, args.CGREvent, reply)
return dS.Dispatch(args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1ProcessCDR, args, reply)
}
func (dS *DispatcherService) SessionSv1ProcessEvent(args *ProcessEventWithApiKey,
func (dS *DispatcherService) SessionSv1ProcessEvent(args *sessions.V1ProcessEventArgs,
reply *sessions.V1ProcessEventReply) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1ProcessEvent,
args.V1ProcessEventArgs.CGREvent.Tenant,
args.APIKey, args.V1ProcessEventArgs.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
utils.SessionSv1ProcessEvent, args.V1ProcessEventArgs, reply)
utils.SessionSv1ProcessEvent, args, reply)
}
func (dS *DispatcherService) SessionSv1GetActiveSessions(args *FilterSessionWithApiKey,
reply *[]*sessions.ActiveSession) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1GetActiveSessions,
args.TenantArg.Tenant,
@@ -169,6 +202,9 @@ func (dS *DispatcherService) SessionSv1GetActiveSessions(args *FilterSessionWith
func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(args *FilterSessionWithApiKey,
reply *int) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1GetActiveSessionsCount,
args.TenantArg.Tenant,
@@ -182,6 +218,9 @@ func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(args *FilterSessio
func (dS *DispatcherService) SessionSv1ForceDisconnect(args *FilterSessionWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1ForceDisconnect,
args.TenantArg.Tenant,
@@ -195,6 +234,9 @@ func (dS *DispatcherService) SessionSv1ForceDisconnect(args *FilterSessionWithAp
func (dS *DispatcherService) SessionSv1GetPassiveSessions(args *FilterSessionWithApiKey,
reply *[]*sessions.ActiveSession) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1GetPassiveSessions,
args.TenantArg.Tenant,
@@ -208,6 +250,9 @@ func (dS *DispatcherService) SessionSv1GetPassiveSessions(args *FilterSessionWit
func (dS *DispatcherService) SessionSv1GetPassiveSessionsCount(args *FilterSessionWithApiKey,
reply *int) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1GetPassiveSessionsCount,
args.TenantArg.Tenant,
@@ -221,6 +266,9 @@ func (dS *DispatcherService) SessionSv1GetPassiveSessionsCount(args *FilterSessi
func (dS *DispatcherService) SessionSv1ReplicateSessions(args *ArgsReplicateSessionsWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1ReplicateSessions,
args.TenantArg.Tenant,
@@ -232,15 +280,18 @@ func (dS *DispatcherService) SessionSv1ReplicateSessions(args *ArgsReplicateSess
utils.SessionSv1ReplicateSessions, args.ArgsReplicateSessions, reply)
}
func (dS *DispatcherService) SessionSv1SetPassiveSession(args *SessionWithApiKey,
func (dS *DispatcherService) SessionSv1SetPassiveSession(args *sessions.Session,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SessionSv1SetPassiveSession,
args.Session.Tenant,
args.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{Tenant: args.Session.Tenant}, utils.MetaSessionS, args.RouteID,
utils.SessionSv1SetPassiveSession, args.Session, reply)
return dS.Dispatch(&utils.CGREvent{Tenant: args.Tenant}, utils.MetaSessionS, args.RouteID,
utils.SessionSv1SetPassiveSession, args, reply)
}

View File

@@ -111,12 +111,12 @@ func testDspSessionPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -132,12 +132,12 @@ func testDspSessionPingFailover(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &ev, &reply); err != nil {
@@ -161,31 +161,29 @@ func testDspSessionPingFailover(t *testing.T) {
func testDspSessionTestAuthKey(t *testing.T) {
authUsage := 5 * time.Minute
args := AuthorizeArgsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
},
V1AuthorizeArgs: sessions.V1AuthorizeArgs{
GetMaxUsage: true,
AuthorizeResources: true,
GetSuppliers: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItAuth",
Event: map[string]interface{}{
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.Usage: authUsage,
},
args := sessions.V1AuthorizeArgs{
GetMaxUsage: true,
AuthorizeResources: true,
GetSuppliers: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItAuth",
Event: map[string]interface{}{
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.Usage: authUsage,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
var rply sessions.V1AuthorizeReplyWithDigest
if err := dispEngine.RCP.Call(utils.SessionSv1AuthorizeEventWithDigest,
@@ -196,32 +194,30 @@ func testDspSessionTestAuthKey(t *testing.T) {
func testDspSessionAuthorize(t *testing.T) {
authUsage := 5 * time.Minute
argsAuth := &AuthorizeArgsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
V1AuthorizeArgs: sessions.V1AuthorizeArgs{
GetMaxUsage: true,
AuthorizeResources: true,
GetSuppliers: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItAuth",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.Usage: authUsage,
},
argsAuth := &sessions.V1AuthorizeArgs{
GetMaxUsage: true,
AuthorizeResources: true,
GetSuppliers: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItAuth",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.Usage: authUsage,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply sessions.V1AuthorizeReplyWithDigest
if err := dispEngine.RCP.Call(utils.SessionSv1AuthorizeEventWithDigest,
@@ -250,32 +246,30 @@ func testDspSessionAuthorize(t *testing.T) {
func testDspSessionInit(t *testing.T) {
initUsage := time.Duration(5 * time.Minute)
argsInit := &InitArgsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
V1InitSessionArgs: sessions.V1InitSessionArgs{
InitSession: true,
AllocateResources: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItInitiateSession",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: initUsage,
},
argsInit := &sessions.V1InitSessionArgs{
InitSession: true,
AllocateResources: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItInitiateSession",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: initUsage,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply sessions.V1InitReplyWithDigest
if err := dispEngine.RCP.Call(utils.SessionSv1InitiateSessionWithDigest,
@@ -292,8 +286,8 @@ func testDspSessionInit(t *testing.T) {
func testDspGetSessions(t *testing.T) {
filtr := FilterSessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -330,30 +324,28 @@ func testDspGetSessions(t *testing.T) {
func testDspSessionUpdate(t *testing.T) {
reqUsage := 5 * time.Minute
argsUpdate := &UpdateSessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
V1UpdateSessionArgs: sessions.V1UpdateSessionArgs{
GetAttributes: true,
UpdateSession: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItUpdateSession",
Event: map[string]interface{}{
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: reqUsage,
},
argsUpdate := &sessions.V1UpdateSessionArgs{
GetAttributes: true,
UpdateSession: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItUpdateSession",
Event: map[string]interface{}{
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: reqUsage,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply sessions.V1UpdateSessionReply
if err := dispEngine.RCP.Call(utils.SessionSv1UpdateSession,
@@ -393,31 +385,29 @@ func testDspSessionUpdate(t *testing.T) {
func testDspSessionUpdate2(t *testing.T) {
reqUsage := 5 * time.Minute
argsUpdate := &UpdateSessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
V1UpdateSessionArgs: sessions.V1UpdateSessionArgs{
GetAttributes: true,
UpdateSession: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItUpdateSession",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: reqUsage,
},
argsUpdate := &sessions.V1UpdateSessionArgs{
GetAttributes: true,
UpdateSession: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItUpdateSession",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: reqUsage,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply sessions.V1UpdateSessionReply
if err := dispEngine.RCP.Call(utils.SessionSv1UpdateSession,
@@ -462,30 +452,28 @@ func testDspSessionUpdate2(t *testing.T) {
}
func testDspSessionTerminate(t *testing.T) {
args := &TerminateSessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
V1TerminateSessionArgs: sessions.V1TerminateSessionArgs{
TerminateSession: true,
ReleaseResources: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItUpdateSession",
Event: map[string]interface{}{
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: 10 * time.Minute,
},
args := &sessions.V1TerminateSessionArgs{
TerminateSession: true,
ReleaseResources: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItUpdateSession",
Event: map[string]interface{}{
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: 10 * time.Minute,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply string
if err := dispEngine.RCP.Call(utils.SessionSv1TerminateSession,
@@ -498,11 +486,8 @@ func testDspSessionTerminate(t *testing.T) {
}
func testDspSessionProcessCDR(t *testing.T) {
args := CGREvWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
CGREvent: utils.CGREvent{
args := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItProcessCDR",
Event: map[string]interface{}{
@@ -518,6 +503,9 @@ func testDspSessionProcessCDR(t *testing.T) {
utils.Usage: 10 * time.Minute,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply string
@@ -532,32 +520,30 @@ func testDspSessionProcessCDR(t *testing.T) {
func testDspSessionProcessEvent(t *testing.T) {
initUsage := 5 * time.Minute
args := ProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
V1ProcessEventArgs: sessions.V1ProcessEventArgs{
AllocateResources: true,
Debit: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItProcessEvent",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It2",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: initUsage,
},
args := sessions.V1ProcessEventArgs{
AllocateResources: true,
Debit: true,
GetAttributes: true,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItProcessEvent",
Event: map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It2",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: initUsage,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}
var rply sessions.V1ProcessEventReply
if err := dispEngine.RCP.Call(utils.SessionSv1ProcessEvent,
@@ -608,8 +594,8 @@ func testDspSessionReplicate(t *testing.T) {
var reply string
if err := dispEngine.RCP.Call(utils.SessionSv1ReplicateSessions, ArgsReplicateSessionsWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -645,8 +631,8 @@ func testDspSessionPassive(t *testing.T) {
testDspSessionUpdate2(t)
var repl int
filtr := FilterSessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",
@@ -676,51 +662,49 @@ func testDspSessionPassive(t *testing.T) {
}
var reply string
if err := dispEngine.RCP.Call(utils.SessionSv1SetPassiveSession, SessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
},
Session: sessions.Session{
CGRID: rply[0].CGRID,
Tenant: rply[0].Tenant,
ResourceID: "TestSSv1It1",
EventStart: engine.NewSafEvent(map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: 5 * time.Minute,
}),
SRuns: []*sessions.SRun{
&sessions.SRun{
Event: engine.NewMapEvent(map[string]interface{}{
"RunID": "CustomerCharges",
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: 5 * time.Minute,
}),
CD: &engine.CallDescriptor{},
EventCost: &engine.EventCost{},
if err := dispEngine.RCP.Call(utils.SessionSv1SetPassiveSession, sessions.Session{
CGRID: rply[0].CGRID,
Tenant: rply[0].Tenant,
ResourceID: "TestSSv1It1",
EventStart: engine.NewSafEvent(map[string]interface{}{
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: 5 * time.Minute,
}),
SRuns: []*sessions.SRun{
&sessions.SRun{
Event: engine.NewMapEvent(map[string]interface{}{
"RunID": "CustomerCharges",
utils.CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
utils.OriginID: "TestSSv1It1",
utils.RequestType: utils.META_PREPAID,
utils.Account: "1001",
utils.Destination: "1002",
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
utils.Usage: 5 * time.Minute,
}),
CD: &engine.CallDescriptor{},
EventCost: &engine.EventCost{},
LastUsage: 5 * time.Minute,
TotalUsage: 10 * time.Minute,
},
LastUsage: 5 * time.Minute,
TotalUsage: 10 * time.Minute,
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
}, &reply); err != nil {
t.Fatal(err)
} else if reply != utils.OK {
@@ -751,8 +735,8 @@ func testDspSessionForceDisconect(t *testing.T) {
testDspSessionInit(t)
var repl int
filtr := FilterSessionWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "ses12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("ses12345"),
},
TenantArg: utils.TenantArg{
Tenant: "cgrates.org",

View File

@@ -21,10 +21,14 @@ package dispatchers
import (
"time"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) StatSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
func (dS *DispatcherService) StatSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.StatSv1Ping,
args.CGREvent.Tenant,
@@ -32,12 +36,15 @@ func (dS *DispatcherService) StatSv1Ping(args *CGREvWithApiKey, reply *string) (
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaStats, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaStats, args.RouteID,
utils.StatSv1Ping, args.CGREvent, reply)
}
func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *ArgsStatProcessEventWithApiKey,
func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *engine.StatsArgsProcessEvent,
reply *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.StatSv1GetStatQueuesForEvent,
args.CGREvent.Tenant,
@@ -46,11 +53,14 @@ func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *ArgsStatProcessE
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaStats, args.RouteID,
utils.StatSv1GetStatQueuesForEvent, args.StatsArgsProcessEvent, reply)
utils.StatSv1GetStatQueuesForEvent, args, reply)
}
func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey,
func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *utils.TenantIDWithArgDispatcher,
reply *map[string]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.StatSv1GetQueueStringMetrics,
args.TenantID.Tenant,
@@ -65,8 +75,11 @@ func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey,
args.TenantID, reply)
}
func (dS *DispatcherService) StatSv1ProcessEvent(args *ArgsStatProcessEventWithApiKey,
func (dS *DispatcherService) StatSv1ProcessEvent(args *engine.StatsArgsProcessEvent,
reply *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.StatSv1ProcessEvent,
args.CGREvent.Tenant,
@@ -75,11 +88,14 @@ func (dS *DispatcherService) StatSv1ProcessEvent(args *ArgsStatProcessEventWithA
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaStats, args.RouteID,
utils.StatSv1ProcessEvent, args.StatsArgsProcessEvent, reply)
utils.StatSv1ProcessEvent, args, reply)
}
func (dS *DispatcherService) StatSv1GetQueueFloatMetrics(args *TntIDWithApiKey,
func (dS *DispatcherService) StatSv1GetQueueFloatMetrics(args *utils.TenantIDWithArgDispatcher,
reply *map[string]float64) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.StatSv1GetQueueFloatMetrics,
args.TenantID.Tenant,
@@ -94,8 +110,11 @@ func (dS *DispatcherService) StatSv1GetQueueFloatMetrics(args *TntIDWithApiKey,
args.TenantID, reply)
}
func (dS *DispatcherService) StatSv1GetQueueIDs(args *TntWithApiKey,
func (dS *DispatcherService) StatSv1GetQueueIDs(args *utils.TenantWithArgDispatcher,
reply *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.StatSv1GetQueueIDs,
args.TenantArg.Tenant,

View File

@@ -56,12 +56,12 @@ func testDspStsPingFailover(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &ev, &reply); err != nil {
@@ -87,23 +87,21 @@ func testDspStsGetStatFailover(t *testing.T) {
var reply []string
var metrics map[string]string
expected := []string{"Stats1"}
args := ArgsStatProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
args := engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.EVENT_NAME: "Event1",
utils.Account: "1001",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(135 * time.Second),
utils.COST: 123.0,
utils.RunID: utils.DEFAULT_RUNID,
utils.Destination: "1002"},
},
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.EVENT_NAME: "Event1",
utils.Account: "1001",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(135 * time.Second),
utils.COST: 123.0,
utils.RunID: utils.DEFAULT_RUNID,
utils.Destination: "1002"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
@@ -112,11 +110,11 @@ func testDspStsGetStatFailover(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
}
args2 := TntIDWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
args2 := utils.TenantIDWithArgDispatcher{
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
TenantID: utils.TenantID{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats1",
},
@@ -144,12 +142,12 @@ func testDspStsPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -160,31 +158,31 @@ func testDspStsPing(t *testing.T) {
func testDspStsTestAuthKey(t *testing.T) {
var reply []string
args := ArgsStatProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
args := engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1001",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(135 * time.Second),
utils.COST: 123.0,
utils.PDD: time.Duration(12 * time.Second)},
},
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1001",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(135 * time.Second),
utils.COST: 123.0,
utils.PDD: time.Duration(12 * time.Second)}},
}}
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent,
args, &reply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
t.Error(err)
}
args2 := TntIDWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
args2 := utils.TenantIDWithArgDispatcher{
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
TenantID: utils.TenantID{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats2",
},
@@ -201,22 +199,20 @@ func testDspStsTestAuthKey2(t *testing.T) {
var reply []string
var metrics map[string]string
expected := []string{"Stats2"}
args := ArgsStatProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
args := engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1001",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(135 * time.Second),
utils.COST: 123.0,
utils.RunID: utils.DEFAULT_RUNID,
utils.Destination: "1002"},
},
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1001",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(135 * time.Second),
utils.COST: 123.0,
utils.RunID: utils.DEFAULT_RUNID,
utils.Destination: "1002"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
@@ -225,11 +221,11 @@ func testDspStsTestAuthKey2(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
}
args2 := TntIDWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
args2 := utils.TenantIDWithArgDispatcher{
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
TenantID: utils.TenantID{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats2",
},
@@ -246,24 +242,22 @@ func testDspStsTestAuthKey2(t *testing.T) {
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
}
args = ArgsStatProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
},
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1002",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(45 * time.Second),
utils.RunID: utils.DEFAULT_RUNID,
utils.COST: 10.0,
utils.Destination: "1001",
},
args = engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
Event: map[string]interface{}{
utils.Account: "1002",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(45 * time.Second),
utils.RunID: utils.DEFAULT_RUNID,
utils.COST: 10.0,
utils.Destination: "1001",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
t.Error(err)
@@ -287,11 +281,11 @@ func testDspStsTestAuthKey3(t *testing.T) {
var reply []string
var metrics map[string]float64
args2 := TntIDWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
args2 := utils.TenantIDWithArgDispatcher{
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
TenantID: utils.TenantID{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats2",
},
@@ -310,12 +304,12 @@ func testDspStsTestAuthKey3(t *testing.T) {
estats := []string{"Stats2", "Stats2_1"}
if err := dispEngine.RCP.Call(utils.StatSv1GetQueueIDs,
&TntWithApiKey{
TenantArg: utils.TenantArg{
&utils.TenantWithArgDispatcher{
TenantArg: &utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -328,23 +322,21 @@ func testDspStsTestAuthKey3(t *testing.T) {
estats = []string{"Stats2"}
if err := dispEngine.RCP.Call(utils.StatSv1GetStatQueuesForEvent,
&ArgsStatProcessEventWithApiKey{
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "GetStats",
Event: map[string]interface{}{
utils.Account: "1002",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(45 * time.Second),
utils.RunID: utils.DEFAULT_RUNID,
utils.COST: 10.0,
utils.Destination: "1001",
},
&engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "GetStats",
Event: map[string]interface{}{
utils.Account: "1002",
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
utils.Usage: time.Duration(45 * time.Second),
utils.RunID: utils.DEFAULT_RUNID,
utils.COST: 10.0,
utils.Destination: "1001",
},
},
DispatcherResource: DispatcherResource{
APIKey: "stat12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("stat12345"),
},
}, &reply); err != nil {
t.Error(err)

View File

@@ -23,7 +23,10 @@ import (
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) SupplierSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
func (dS *DispatcherService) SupplierSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SupplierSv1Ping,
args.CGREvent.Tenant,
@@ -31,19 +34,22 @@ func (dS *DispatcherService) SupplierSv1Ping(args *CGREvWithApiKey, reply *strin
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaSuppliers, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaSuppliers, args.RouteID,
utils.SupplierSv1Ping, args.CGREvent, reply)
}
func (dS *DispatcherService) SupplierSv1GetSuppliers(args *ArgsGetSuppliersWithApiKey,
func (dS *DispatcherService) SupplierSv1GetSuppliers(args *engine.ArgsGetSuppliers,
reply *engine.SortedSuppliers) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.SupplierSv1GetSuppliers,
args.ArgsGetSuppliers.CGREvent.Tenant,
args.APIKey, args.ArgsGetSuppliers.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaSuppliers, args.RouteID,
utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers, reply)
utils.SupplierSv1GetSuppliers, args, reply)
}

View File

@@ -55,12 +55,12 @@ func testDspSupPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "sup12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("sup12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -76,12 +76,12 @@ func testDspSupPingFailover(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "sup12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("sup12345"),
},
}
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err != nil {
@@ -142,25 +142,23 @@ func testDspSupGetSupFailover(t *testing.T) {
},
},
}
args := &ArgsGetSuppliersWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "sup12345",
},
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.EVENT_NAME: "Event1",
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
args := &engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.EVENT_NAME: "Event1",
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("sup12345"),
},
}
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
args, &rpl); err != nil {
@@ -180,24 +178,22 @@ func testDspSupGetSupFailover(t *testing.T) {
func testDspSupTestAuthKey(t *testing.T) {
var rpl *engine.SortedSuppliers
args := &ArgsGetSuppliersWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
},
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
args := &engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
args, &rpl); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
@@ -231,24 +227,22 @@ func testDspSupTestAuthKey2(t *testing.T) {
},
},
}
args := &ArgsGetSuppliersWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "sup12345",
},
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
args := &engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("sup12345"),
},
}
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
args, &rpl); err != nil {
@@ -297,25 +291,23 @@ func testDspSupGetSupRoundRobin(t *testing.T) {
},
},
}
args := &ArgsGetSuppliersWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "sup12345",
},
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.EVENT_NAME: "RoundRobin",
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
args := &engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.EVENT_NAME: "RoundRobin",
utils.Account: "1002",
utils.Subject: "1002",
utils.Destination: "1001",
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
utils.Usage: "1m20s",
},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("sup12345"),
},
}
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
args, &rpl); err != nil {

View File

@@ -25,7 +25,10 @@ import (
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) ThresholdSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
func (dS *DispatcherService) ThresholdSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ThresholdSv1Ping,
args.CGREvent.Tenant,
@@ -33,37 +36,46 @@ func (dS *DispatcherService) ThresholdSv1Ping(args *CGREvWithApiKey, reply *stri
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, args.RouteID,
return dS.Dispatch(args.CGREvent, utils.MetaThresholds, args.RouteID,
utils.ThresholdSv1Ping, args.CGREvent, reply)
}
func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *ArgsProcessEventWithApiKey,
func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *engine.ArgsProcessEvent,
t *engine.Thresholds) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ThresholdSv1GetThresholdsForEvent,
args.ArgsProcessEvent.CGREvent.Tenant,
args.APIKey, args.ArgsProcessEvent.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, args.RouteID,
utils.ThresholdSv1GetThresholdsForEvent, args.ArgsProcessEvent, t)
utils.ThresholdSv1GetThresholdsForEvent, args, t)
}
func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *ArgsProcessEventWithApiKey,
func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *engine.ArgsProcessEvent,
tIDs *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ThresholdSv1ProcessEvent,
args.ArgsProcessEvent.CGREvent.Tenant,
args.APIKey, args.ArgsProcessEvent.CGREvent.Time); err != nil {
args.CGREvent.Tenant,
args.APIKey, args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, args.RouteID,
utils.ThresholdSv1ProcessEvent, args.ArgsProcessEvent, tIDs)
utils.ThresholdSv1ProcessEvent, args, tIDs)
}
func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(args *TntWithApiKey, tIDs *[]string) (err error) {
func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(args *utils.TenantWithArgDispatcher, tIDs *[]string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ThresholdSv1GetThresholdIDs,
args.Tenant, args.APIKey, utils.TimePointer(time.Now())); err != nil {
@@ -74,7 +86,10 @@ func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(args *TntWithApiKey, tI
utils.ThresholdSv1GetThresholdIDs, args.TenantArg, tIDs)
}
func (dS *DispatcherService) ThresholdSv1GetThreshold(args *TntIDWithApiKey, th *engine.Threshold) (err error) {
func (dS *DispatcherService) ThresholdSv1GetThreshold(args *utils.TenantIDWithArgDispatcher, th *engine.Threshold) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ThresholdSv1GetThreshold,
args.TenantID.Tenant,

View File

@@ -56,12 +56,12 @@ func testDspThPingFailover(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
ev := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "thr12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("thr12345"),
},
}
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &ev, &reply); err != nil {
@@ -87,19 +87,17 @@ func testDspThProcessEventFailover(t *testing.T) {
var ids []string
eIDs := []string{"THD_ACNT_1001"}
nowTime := time.Now()
args := &ArgsProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "thr12345",
args := &engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.EVENT_NAME: "Event1",
utils.Account: "1001"},
},
ArgsProcessEvent: engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.EVENT_NAME: "Event1",
utils.Account: "1001"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("thr12345"),
},
}
@@ -123,12 +121,12 @@ func testDspThPing(t *testing.T) {
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &CGREvWithApiKey{
CGREvent: utils.CGREvent{
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "thr12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("thr12345"),
},
}, &reply); err != nil {
t.Error(err)
@@ -140,18 +138,16 @@ func testDspThPing(t *testing.T) {
func testDspThTestAuthKey(t *testing.T) {
var ids []string
nowTime := time.Now()
args := &ArgsProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "12345",
args := &engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002"},
},
ArgsProcessEvent: engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("12345"),
},
}
@@ -170,18 +166,16 @@ func testDspThTestAuthKey2(t *testing.T) {
var ids []string
eIDs := []string{"THD_ACNT_1002"}
nowTime := time.Now()
args := &ArgsProcessEventWithApiKey{
DispatcherResource: DispatcherResource{
APIKey: "thr12345",
args := &engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002"},
},
ArgsProcessEvent: engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: utils.UUIDSha1Prefix(),
Time: &nowTime,
Event: map[string]interface{}{
utils.Account: "1002"},
},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("thr12345"),
},
}
@@ -216,13 +210,13 @@ func testDspThTestAuthKey3(t *testing.T) {
ID: "THD_ACNT_1002",
Hits: 1,
}
if err := dispEngine.RCP.Call(utils.ThresholdSv1GetThreshold, &TntIDWithApiKey{
TenantID: utils.TenantID{
if err := dispEngine.RCP.Call(utils.ThresholdSv1GetThreshold, &utils.TenantIDWithArgDispatcher{
TenantID: &utils.TenantID{
Tenant: "cgrates.org",
ID: "THD_ACNT_1002",
},
DispatcherResource: DispatcherResource{
APIKey: "thr12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("thr12345"),
},
}, &th); err != nil {
t.Error(err)
@@ -237,12 +231,12 @@ func testDspThTestAuthKey3(t *testing.T) {
var ids []string
eIDs := []string{"THD_ACNT_1002"}
if err := dispEngine.RCP.Call(utils.ThresholdSv1GetThresholdIDs, &TntWithApiKey{
TenantArg: utils.TenantArg{
if err := dispEngine.RCP.Call(utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithArgDispatcher{
TenantArg: &utils.TenantArg{
Tenant: "cgrates.org",
},
DispatcherResource: DispatcherResource{
APIKey: "thr12345",
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer("thr12345"),
},
}, &ids); err != nil {
t.Fatal(err)

View File

@@ -33,148 +33,68 @@ var ( //var used in all tests
nowTime = time.Now()
)
type DispatcherResource struct {
APIKey string
RouteID *string // route over previous computed path
}
type CGREvWithApiKey struct {
DispatcherResource
utils.CGREvent
}
type DispatcherEvent struct {
utils.CGREvent
DispatcherResource
*utils.ArgDispatcher
Subsystem string
}
type TntIDWithApiKey struct {
utils.TenantID
DispatcherResource
}
type TntWithApiKey struct {
utils.TenantArg
DispatcherResource
}
type ArgsV1ResUsageWithApiKey struct {
DispatcherResource
utils.ArgRSv1ResourceUsage
}
type ArgsProcessEventWithApiKey struct {
DispatcherResource
engine.ArgsProcessEvent
}
type ArgsAttrProcessEventWithApiKey struct {
DispatcherResource
engine.AttrArgsProcessEvent
}
type ArgsGetSuppliersWithApiKey struct {
DispatcherResource
engine.ArgsGetSuppliers
}
type ArgsStatProcessEventWithApiKey struct {
DispatcherResource
engine.StatsArgsProcessEvent
}
type AuthorizeArgsWithApiKey struct {
DispatcherResource
sessions.V1AuthorizeArgs
}
type InitArgsWithApiKey struct {
DispatcherResource
sessions.V1InitSessionArgs
}
type ProcessEventWithApiKey struct {
DispatcherResource
sessions.V1ProcessEventArgs
}
type TerminateSessionWithApiKey struct {
DispatcherResource
sessions.V1TerminateSessionArgs
}
type UpdateSessionWithApiKey struct {
DispatcherResource
sessions.V1UpdateSessionArgs
}
type FilterSessionWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
Filters map[string]string
}
type ArgsReplicateSessionsWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
sessions.ArgsReplicateSessions
}
type SessionWithApiKey struct {
DispatcherResource
sessions.Session
}
type CallDescriptorWithApiKey struct {
DispatcherResource
engine.CallDescriptor
}
type ArgsGetCacheItemIDsWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
engine.ArgsGetCacheItemIDs
}
type ArgsGetCacheItemWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
engine.ArgsGetCacheItem
}
type AttrReloadCacheWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
utils.AttrReloadCache
}
type AttrCacheIDsWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
CacheIDs []string
}
type ArgsGetGroupWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
engine.ArgsGetGroup
}
type AttrRemoteLockWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
utils.AttrRemoteLock
}
type AttrRemoteUnlockWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
RefID string
}
type StringkWithApiKey struct {
DispatcherResource
*utils.ArgDispatcher
utils.TenantArg
Arg string
}

View File

@@ -147,6 +147,7 @@ type AttrArgsProcessEvent struct {
Context *string // attach the event to a context
ProcessRuns *int // number of loops for ProcessEvent
utils.CGREvent
*utils.ArgDispatcher
}
// processEvent will match event with attribute profile and do the necessary replacements

View File

@@ -171,6 +171,7 @@ type CallDescriptor struct {
DenyNegativeAccount bool // prevent account going on negative during debit
account *Account
testCallcost *CallCost // testing purpose only!
*utils.ArgDispatcher
}
// AsCGREvent converts the CallDescriptor into CGREvent

View File

@@ -130,8 +130,8 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREvent) (rply []*ChrgSProc
var evReply AttrSProcessEventReply
if err = cS.attrS.Call(utils.AttributeSv1ProcessEvent,
&AttrArgsProcessEvent{cP.AttributeIDs,
utils.StringPointer(utils.MetaChargers), nil, *clonedEv},
&AttrArgsProcessEvent{AttributeIDs: cP.AttributeIDs,
Context: utils.StringPointer(utils.MetaChargers), ProcessRuns: nil, CGREvent: *clonedEv},
&evReply); err != nil {
return nil, err
}

View File

@@ -228,6 +228,7 @@ func (ss *StatService) Call(serviceMethod string, args interface{}, reply interf
type StatsArgsProcessEvent struct {
StatIDs []string
utils.CGREvent
*utils.ArgDispatcher
}
// processEvent processes a new event, dispatching to matching queues

View File

@@ -434,6 +434,7 @@ type ArgsGetSuppliers struct {
MaxCost string // toDo: try with interface{} here
utils.CGREvent
utils.Paginator
*utils.ArgDispatcher
}
func (args *ArgsGetSuppliers) asOptsGetSuppliers() (opts *optsGetSuppliers, err error) {

View File

@@ -279,6 +279,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ArgsProcessEvent) (
type ArgsProcessEvent struct {
ThresholdIDs []string
utils.CGREvent
*utils.ArgDispatcher
}
// processEvent processes a new event, dispatching to matching thresholds

View File

@@ -75,6 +75,7 @@ type Session struct {
debitStop chan struct{}
sTerminator *sTerminator // automatic timeout for the session
*utils.ArgDispatcher
}
// CGRid is a thread-safe method to return the CGRID of a session

View File

@@ -1538,6 +1538,7 @@ type V1AuthorizeArgs struct {
SuppliersIgnoreErrors bool
utils.CGREvent
utils.Paginator
*utils.ArgDispatcher
}
// V1AuthorizeReply are options available in auth reply
@@ -1787,6 +1788,7 @@ type V1InitSessionArgs struct {
ProcessThresholds bool
ProcessStats bool
utils.CGREvent
*utils.ArgDispatcher
}
// V1InitSessionReply are options for initialization reply
@@ -2016,6 +2018,7 @@ type V1UpdateSessionArgs struct {
GetAttributes bool
UpdateSession bool
utils.CGREvent
*utils.ArgDispatcher
}
// V1UpdateSessionReply contains options for session update reply
@@ -2149,6 +2152,7 @@ type V1TerminateSessionArgs struct {
ProcessThresholds bool
ProcessStats bool
utils.CGREvent
*utils.ArgDispatcher
}
// BiRPCV1TerminateSession will stop debit loops as well as release any used resources
@@ -2376,8 +2380,8 @@ type V1ProcessEventArgs struct {
Debit bool
ProcessThresholds bool
ProcessStats bool
utils.CGREvent
*utils.ArgDispatcher
}
// V1ProcessEventReply is the reply for the ProcessEvent API

View File

@@ -1018,6 +1018,7 @@ type ArgRSv1ResourceUsage struct {
UsageID string // ResourceUsage Identifier
UsageTTL *time.Duration
Units float64
*ArgDispatcher
}
func (args *ArgRSv1ResourceUsage) TenantID() string {

View File

@@ -180,3 +180,8 @@ type CGREvents struct {
Time *time.Time // event time
Events []map[string]interface{}
}
type CGREventWithArgDispatcher struct {
*CGREvent
*ArgDispatcher
}

View File

@@ -792,11 +792,21 @@ type TenantArg struct {
Tenant string
}
type TenantWithArgDispatcher struct {
*TenantArg
*ArgDispatcher
}
type TenantID struct {
Tenant string
ID string
}
type TenantIDWithArgDispatcher struct {
*TenantID
*ArgDispatcher
}
func (tID *TenantID) TenantID() string {
return ConcatenatedKey(tID.Tenant, tID.ID)
}
@@ -938,6 +948,11 @@ type CachedRPCResponse struct {
Error error
}
type ArgDispatcher struct {
APIKey *string
RouteID *string
}
func ReverseString(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {