From 9ca91cc401be026885306aaa555912ac0e5a5d68 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 6 Jun 2018 10:20:53 -0400 Subject: [PATCH] Fine tuning on dispatcher methods --- dispatcher/resources.go | 7 +++++-- dispatcher/stats.go | 21 +++++++++++++++------ dispatcher/thresholds.go | 14 ++++++++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dispatcher/resources.go b/dispatcher/resources.go index 4576267f3..a04077833 100755 --- a/dispatcher/resources.go +++ b/dispatcher/resources.go @@ -49,8 +49,11 @@ func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(args ArgsV1ResUsage if err = dS.authorizeEvent(ev, &rplyEv); err != nil { return } - mp := utils.ParseStringMap(rplyEv.CGREvent.Event[utils.APIMethods].(string)) - if !mp.HasKey(utils.ResourceSv1GetResourcesForEvent) { + var apiMethods string + if apiMethods, err = rplyEv.CGREvent.FieldAsString(utils.APIMethods); err != nil { + return + } + if !utils.ParseStringMap(apiMethods).HasKey(utils.ResourceSv1GetResourcesForEvent) { return utils.ErrUnauthorizedApi } return dS.resS.Call(utils.ResourceSv1GetResourcesForEvent, args.ArgRSv1ResourceUsage, reply) diff --git a/dispatcher/stats.go b/dispatcher/stats.go index 2d67ade86..49e244f34 100755 --- a/dispatcher/stats.go +++ b/dispatcher/stats.go @@ -52,8 +52,11 @@ func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *CGREvWithApiKey, if err = dS.authorizeEvent(ev, &rplyEv); err != nil { return } - mp := utils.ParseStringMap(rplyEv.CGREvent.Event[utils.APIMethods].(string)) - if !mp.HasKey(utils.StatSv1GetStatQueuesForEvent) { + var apiMethods string + if apiMethods, err = rplyEv.CGREvent.FieldAsString(utils.APIMethods); err != nil { + return + } + if !utils.ParseStringMap(apiMethods).HasKey(utils.StatSv1GetStatQueuesForEvent) { return utils.ErrUnauthorizedApi } return dS.statS.Call(utils.StatSv1GetStatQueuesForEvent, args.CGREvent, reply) @@ -76,8 +79,11 @@ func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey, if err = dS.authorizeEvent(ev, &rplyEv); err != nil { return } - mp := utils.ParseStringMap(rplyEv.CGREvent.Event[utils.APIMethods].(string)) - if !mp.HasKey(utils.StatSv1GetQueueStringMetrics) { + var apiMethods string + if apiMethods, err = rplyEv.CGREvent.FieldAsString(utils.APIMethods); err != nil { + return + } + if !utils.ParseStringMap(apiMethods).HasKey(utils.StatSv1GetQueueStringMetrics) { return utils.ErrUnauthorizedApi } return dS.statS.Call(utils.StatSv1GetQueueStringMetrics, args.TenantID, reply) @@ -100,8 +106,11 @@ func (dS *DispatcherService) StatSv1ProcessEvent(args *CGREvWithApiKey, if err = dS.authorizeEvent(ev, &rplyEv); err != nil { return } - mp := utils.ParseStringMap(rplyEv.CGREvent.Event[utils.APIMethods].(string)) - if !mp.HasKey(utils.StatSv1ProcessEvent) { + var apiMethods string + if apiMethods, err = rplyEv.CGREvent.FieldAsString(utils.APIMethods); err != nil { + return + } + if !utils.ParseStringMap(apiMethods).HasKey(utils.StatSv1ProcessEvent) { return utils.ErrUnauthorizedApi } return dS.statS.Call(utils.StatSv1ProcessEvent, args.CGREvent, reply) diff --git a/dispatcher/thresholds.go b/dispatcher/thresholds.go index 4899cae5c..9c587b3cc 100755 --- a/dispatcher/thresholds.go +++ b/dispatcher/thresholds.go @@ -82,8 +82,11 @@ func (dS *DispatcherService) ThresholdSv1GetThresholdForEvent(args *ArgsProcessE if err = dS.authorizeEvent(ev, &rplyEv); err != nil { return } - mp := utils.ParseStringMap(rplyEv.CGREvent.Event[utils.APIMethods].(string)) - if !mp.HasKey(utils.ThresholdSv1GetThresholdsForEvent) { + var apiMethods string + if apiMethods, err = rplyEv.CGREvent.FieldAsString(utils.APIMethods); err != nil { + return + } + if !utils.ParseStringMap(apiMethods).HasKey(utils.ThresholdSv1GetThresholdsForEvent) { return utils.ErrUnauthorizedApi } return dS.thdS.Call(utils.ThresholdSv1GetThresholdsForEvent, args.TenantID, t) @@ -106,8 +109,11 @@ func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *ArgsProcessEventWith if err = dS.authorizeEvent(ev, &rplyEv); err != nil { return } - mp := utils.ParseStringMap(rplyEv.CGREvent.Event[utils.APIMethods].(string)) - if !mp.HasKey(utils.ThresholdSv1ProcessEvent) { + var apiMethods string + if apiMethods, err = rplyEv.CGREvent.FieldAsString(utils.APIMethods); err != nil { + return + } + if !utils.ParseStringMap(apiMethods).HasKey(utils.ThresholdSv1ProcessEvent) { return utils.ErrUnauthorizedApi } return dS.thdS.Call(utils.ThresholdSv1ProcessEvent, args.ArgsProcessEvent, tIDs)