From 3e99bc3ad42c97f7aa6fce15ea5a9b86ba2c2148 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 19 Feb 2019 14:06:04 +0200 Subject: [PATCH] Added new SessionSv1 methods in Dispatcher --- apier/v1/dispatcher.go | 35 ++++++++ data/tariffplans/dispatchers/Attributes.csv | 2 +- dispatchers/sessions.go | 91 +++++++++++++++++++++ dispatchers/utils.go | 17 ++++ 4 files changed, 144 insertions(+), 1 deletion(-) diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 106b750bd..3bf98f472 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -327,3 +327,38 @@ func (dS *DispatcherSessionSv1) UpdateSession(args *dispatchers.UpdateSessionWit reply *sessions.V1UpdateSessionReply) (err error) { return dS.dS.SessionSv1UpdateSession(args, reply) } + +func (dS *DispatcherSessionSv1) GetActiveSessions(args *dispatchers.FilterSessionWithApiKey, + reply *[]*sessions.ActiveSession) (err error) { + return dS.dS.SessionSv1GetActiveSessions(args, reply) +} + +func (dS *DispatcherSessionSv1) GetActiveSessionsCount(args *dispatchers.FilterSessionWithApiKey, + reply *int) (err error) { + return dS.dS.SessionSv1GetActiveSessionsCount(args, reply) +} + +func (dS *DispatcherSessionSv1) ForceDisconnect(args *dispatchers.FilterSessionWithApiKey, + reply *string) (err error) { + return dS.dS.SessionSv1ForceDisconnect(args, reply) +} + +func (dS *DispatcherSessionSv1) GetPassiveSessions(args *dispatchers.FilterSessionWithApiKey, + reply *[]*sessions.ActiveSession) (err error) { + return dS.dS.SessionSv1GetPassiveSessions(args, reply) +} + +func (dS *DispatcherSessionSv1) GetPassiveSessionsCount(args *dispatchers.FilterSessionWithApiKey, + reply *int) (err error) { + return dS.dS.SessionSv1GetPassiveSessionsCount(args, reply) +} + +func (dS *DispatcherSessionSv1) ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithApiKey, + reply *string) (err error) { + return dS.dS.SessionSv1ReplicateSessions(args, reply) +} + +func (dS *DispatcherSessionSv1) SetPassiveSession(args *dispatchers.SessionWithApiKey, + reply *string) (err error) { + return dS.dS.SessionSv1SetPassiveSession(args, reply) +} diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index 8a7139d17..2ca0f2544 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -7,5 +7,5 @@ cgrates.org,ATTR_API_THR_AUTH,*auth,*string:APIKey:thr12345,,APIMethods,*any,Thr cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:APIKey:sup12345,,APIMethods,*any,SupplierSv1.Ping&SupplierSv1.GetSuppliers,true,false,20 cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:APIKey:stat12345,,APIMethods,*any,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,true,false,20 cgrates.org,ATTR_API_RES_AUTH,*auth,*string:APIKey:res12345,,APIMethods,*any,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,true,false,20 -cgrates.org,ATTR_API_SES_AUTH,*auth,*string:APIKey:ses12345,,APIMethods,*any,SessionSv1.Ping&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent,true,false,20 +cgrates.org,ATTR_API_SES_AUTH,*auth,*string:APIKey:ses12345,,APIMethods,*any,SessionSv1.Ping&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.SetPassiveSession&SessionSv1.ReplicateSessions,true,false,20 diff --git a/dispatchers/sessions.go b/dispatchers/sessions.go index 811ede1fe..2c882624d 100755 --- a/dispatchers/sessions.go +++ b/dispatchers/sessions.go @@ -153,3 +153,94 @@ func (dS *DispatcherService) SessionSv1ProcessEvent(args *ProcessEventWithApiKey return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID, utils.SessionSv1ProcessEvent, args.V1ProcessEventArgs, reply) } + +func (dS *DispatcherService) SessionSv1GetActiveSessions(args *FilterSessionWithApiKey, + reply *[]*sessions.ActiveSession) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1GetActiveSessions, + args.TenantArg.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID, + utils.SessionSv1GetActiveSessions, args.Filters, reply) +} + +func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(args *FilterSessionWithApiKey, + reply *int) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1GetActiveSessionsCount, + args.TenantArg.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID, + utils.SessionSv1GetActiveSessionsCount, args.Filters, reply) +} + +func (dS *DispatcherService) SessionSv1ForceDisconnect(args *FilterSessionWithApiKey, + reply *string) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1ForceDisconnect, + args.TenantArg.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID, + utils.SessionSv1ForceDisconnect, args.Filters, reply) +} + +func (dS *DispatcherService) SessionSv1GetPassiveSessions(args *FilterSessionWithApiKey, + reply *[]*sessions.ActiveSession) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1GetPassiveSessions, + args.TenantArg.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID, + utils.SessionSv1GetPassiveSessions, args.Filters, reply) +} + +func (dS *DispatcherService) SessionSv1GetPassiveSessionsCount(args *FilterSessionWithApiKey, + reply *int) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1GetPassiveSessionsCount, + args.TenantArg.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID, + utils.SessionSv1GetPassiveSessionsCount, args.Filters, reply) +} + +func (dS *DispatcherService) SessionSv1ReplicateSessions(args *ArgsReplicateSessionsWithApiKey, + reply *string) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1ReplicateSessions, + args.TenantArg.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID, + utils.SessionSv1ReplicateSessions, args.ArgsReplicateSessions, reply) +} + +func (dS *DispatcherService) SessionSv1SetPassiveSession(args *SessionWithApiKey, + reply *string) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.SessionSv1SetPassiveSession, + args.Session.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) +} diff --git a/dispatchers/utils.go b/dispatchers/utils.go index 1858fe616..52329ff92 100755 --- a/dispatchers/utils.go +++ b/dispatchers/utils.go @@ -103,6 +103,23 @@ type UpdateSessionWithApiKey struct { sessions.V1UpdateSessionArgs } +type FilterSessionWithApiKey struct { + DispatcherResource + utils.TenantArg + Filters map[string]string +} + +type ArgsReplicateSessionsWithApiKey struct { + DispatcherResource + utils.TenantArg + sessions.ArgsReplicateSessions +} + +type SessionWithApiKey struct { + DispatcherResource + sessions.Session +} + func ParseStringMap(s string) utils.StringMap { if s == utils.ZERO { return make(utils.StringMap)