From e200668cb42ae38e067a1f954da2ac8214483d44 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 5 Apr 2022 17:35:31 +0300 Subject: [PATCH] Generate dispatchers after adding new filters API --- data/conf/cgrates/cgrates.json | 6 ++++++ dispatchers/admins.go | 20 ++++++++++++++++++++ dispatchers/caches.go | 3 +-- dispatchers/rates.go | 14 +++++++------- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index ba3e32c11..61047fd89 100755 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -128,6 +128,7 @@ + // "listen": { // "rpc_json": "127.0.0.1:2012", // RPC JSON listening address // "rpc_gob": "127.0.0.1:2013", // RPC GOB listening address @@ -516,6 +517,7 @@ // // "connIDs": [], // connections for connManager to this exporter // // "rpcConnTimeout" : "1s", // connection unsuccesfull on timeout // // "rpcReplyTimeout":"2s", // connection down at replies if taking longer that this value +// // "rpcAPIOpts": {}, // opts that will be passed within APIOpts // }, // extra options for exporter // "timezone": "", // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> // "filters": [], // limit parsing based on the filters @@ -1755,5 +1757,9 @@ // } // }, +// "tpes": { +// "enabled": false, +// }, + } diff --git a/dispatchers/admins.go b/dispatchers/admins.go index 2604ddf0d..8323d4e87 100644 --- a/dispatchers/admins.go +++ b/dispatchers/admins.go @@ -60,6 +60,26 @@ func (dS *DispatcherService) AdminSv1ComputeFilterIndexes(ctx *context.Context, } return dS.Dispatch(ctx, &utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaAdminS, utils.AdminSv1ComputeFilterIndexes, args, reply) } +func (dS *DispatcherService) AdminSv1FiltersMatch(ctx *context.Context, args *engine.ArgsFiltersMatch, reply *bool) (err error) { + tnt := dS.cfg.GeneralCfg().DefaultTenant + if args != nil && (args.CGREvent != nil && len(args.CGREvent.Tenant) != 0) { + tnt = args.CGREvent.Tenant + } + ev := make(map[string]interface{}) + if args != nil && args.CGREvent != nil { + ev = args.CGREvent.Event + } + opts := make(map[string]interface{}) + if args != nil && args.CGREvent != nil { + opts = args.CGREvent.APIOpts + } + if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { + if err = dS.authorize(ctx, utils.AdminSv1FiltersMatch, tnt, utils.IfaceAsString(opts[utils.OptsAPIKey])); err != nil { + return + } + } + return dS.Dispatch(ctx, &utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaAdminS, utils.AdminSv1FiltersMatch, args, reply) +} func (dS *DispatcherService) AdminSv1GetAccount(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *utils.Account) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && (args.TenantID != nil && len(args.TenantID.Tenant) != 0) { diff --git a/dispatchers/caches.go b/dispatchers/caches.go index e51434d68..536c9ea09 100644 --- a/dispatchers/caches.go +++ b/dispatchers/caches.go @@ -20,11 +20,10 @@ along with this program. If not, see package dispatchers import ( - "time" - "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" + "time" ) func (dS *DispatcherService) CacheSv1Clear(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *string) (err error) { diff --git a/dispatchers/rates.go b/dispatchers/rates.go index 59181cbc8..e8e238907 100644 --- a/dispatchers/rates.go +++ b/dispatchers/rates.go @@ -64,18 +64,18 @@ func (dS *DispatcherService) RateSv1Ping(ctx *context.Context, args *utils.CGREv } return dS.Dispatch(ctx, &utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.RateS, utils.RateSv1Ping, args, reply) } -func (dS *DispatcherService) RateSv1RateProfileRatesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { +func (dS *DispatcherService) RateSv1RateProfileRatesForEvent(ctx *context.Context, args *utils.CGREventWithRateProfile, reply *[]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant - if args != nil && len(args.Tenant) != 0 { - tnt = args.Tenant + if args != nil && (args.CGREvent != nil && len(args.CGREvent.Tenant) != 0) { + tnt = args.CGREvent.Tenant } ev := make(map[string]interface{}) - if args != nil { - ev = args.Event + if args != nil && args.CGREvent != nil { + ev = args.CGREvent.Event } opts := make(map[string]interface{}) - if args != nil { - opts = args.APIOpts + if args != nil && args.CGREvent != nil { + opts = args.CGREvent.APIOpts } if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(ctx, utils.RateSv1RateProfileRatesForEvent, tnt, utils.IfaceAsString(opts[utils.OptsAPIKey])); err != nil {