Update both ReAuthorize API signatures

The one from sessions takes an additional event alongside the
SessionFilter, while the one from agents will accept a CGREvent
instead of a simple originID string

The additional event sent to SessionSv1ReAuthorize will be merged
with the EventStart event from the matched session and can be used
when building server initiated requests from the *req map. The
initial packet which was initially inside *req, will be moved to
the *oreq ExtraDP (stands for original request).
This commit is contained in:
ionutboangiu
2024-02-13 11:04:06 -05:00
committed by Dan Christian Bogos
parent 61bcf48678
commit d8ad760dbb
15 changed files with 112 additions and 75 deletions

View File

@@ -45,11 +45,11 @@ var authReqs = engine.MapEvent{
// BiRPCClient is the interface implemented by Agents which are able to
// communicate bidirectionally with SessionS and remote Communication Switch
type BiRPCClient interface {
V1DisconnectSession(ctx *context.Context, args utils.AttrDisconnectSession, reply *string) (err error)
V1GetActiveSessionIDs(ctx *context.Context, ignParam string, sessionIDs *[]*SessionID) (err error)
V1ReAuthorize(ctx *context.Context, originID string, reply *string) (err error)
V1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error)
V1WarnDisconnect(ctx *context.Context, args map[string]any, reply *string) (err error)
V1DisconnectSession(*context.Context, utils.AttrDisconnectSession, *string) error
V1GetActiveSessionIDs(*context.Context, string, *[]*SessionID) error
V1ReAuthorize(*context.Context, utils.CGREvent, *string) error
V1DisconnectPeer(*context.Context, *utils.DPRArgs, *string) error
V1WarnDisconnect(*context.Context, map[string]any, *string) error
}
// GetSetCGRID will populate the CGRID key if not present and return it

View File

@@ -4002,18 +4002,31 @@ func (sS *SessionS) BiRPCV1ProcessCDR(ctx *context.Context,
rply)
}
func (sS *SessionS) sendRar(s *Session) (err error) {
func (sS *SessionS) sendRar(ctx *context.Context, s *Session, event map[string]any) (err error) {
clnt := sS.biJClnt(s.ClientConnID)
if clnt == nil {
return fmt.Errorf("calling %s requires bidirectional JSON connection, connID: <%s>",
utils.SessionSv1ReAuthorize, s.ClientConnID)
}
var originID string
if originID, err = s.EventStart.GetString(utils.OriginID); err != nil {
return
// Merge parameter event with the session event. Losing the EventStart OriginID
// could create unwanted behaviour.
if event == nil {
event = make(map[string]any)
}
for key, val := range s.EventStart {
if _, has := event[key]; !has {
event[key] = val
}
}
args := utils.CGREvent{
ID: utils.GenUUID(),
Time: utils.TimePointer(time.Now()),
Event: event,
}
var rply string
if err = clnt.conn.Call(context.TODO(), utils.SessionSv1ReAuthorize, originID, &rply); err == utils.ErrNotImplemented {
if err = clnt.conn.Call(ctx, utils.SessionSv1ReAuthorize, args, &rply); err == utils.ErrNotImplemented {
err = nil
}
return
@@ -4021,11 +4034,11 @@ func (sS *SessionS) sendRar(s *Session) (err error) {
// BiRPCv1ReAuthorize sends a RAR for the matching sessions
func (sS *SessionS) BiRPCv1ReAuthorize(ctx *context.Context,
args *utils.SessionFilter, reply *string) (err error) {
if args == nil { //protection in case on nil
args = &utils.SessionFilter{}
args utils.SessionFilterWithEvent, reply *string) (err error) {
if args.SessionFilter == nil { //protection in case on nil
args.SessionFilter = &utils.SessionFilter{}
}
aSs := sS.filterSessions(args, false)
aSs := sS.filterSessions(args.SessionFilter, false)
if len(aSs) == 0 {
return utils.ErrNotFound
}
@@ -4039,7 +4052,7 @@ func (sS *SessionS) BiRPCv1ReAuthorize(ctx *context.Context,
if len(ss) == 0 {
continue
}
if errTerm := sS.sendRar(ss[0]); errTerm != nil {
if errTerm := sS.sendRar(ctx, ss[0], args.Event); errTerm != nil {
utils.Logger.Warning(
fmt.Sprintf(
"<%s> failed sending RAR for session with id: <%s>, err: <%s>",