mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Refactor ReAuthorize to AlterSessions
This commit is contained in:
committed by
Dan Christian Bogos
parent
ec9b95088f
commit
f9d1c0f0e1
@@ -373,8 +373,8 @@ func (sma *AsteriskAgent) V1GetActiveSessionIDs(ctx *context.Context, ignParam s
|
||||
|
||||
}
|
||||
|
||||
// V1ReAuthorize is used to implement the sessions.BiRPClient interface
|
||||
func (*AsteriskAgent) V1ReAuthorize(*context.Context, utils.CGREvent, *string) error {
|
||||
// V1AlterSessions is used to implement the sessions.BiRPClient interface
|
||||
func (*AsteriskAgent) V1AlterSessions(*context.Context, utils.CGREvent, *string) error {
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -1234,7 +1234,7 @@ func testDiamItRAR(t *testing.T) {
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
var reply string
|
||||
if err := apierRpc.Call(context.Background(), utils.SessionSv1ReAuthorize, utils.SessionFilterWithEvent{}, &reply); err != nil {
|
||||
if err := apierRpc.Call(context.Background(), utils.SessionSv1AlterSessions, utils.SessionFilterWithEvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
wait.Done()
|
||||
|
||||
@@ -347,7 +347,7 @@ func (da *DiameterAgent) V1DisconnectSession(ctx *context.Context, args utils.At
|
||||
case utils.MetaASR:
|
||||
return da.sendASR(originID, reply)
|
||||
case utils.MetaRAR:
|
||||
return da.V1ReAuthorize(ctx, utils.CGREvent{Event: args.EventStart}, reply)
|
||||
return da.V1AlterSessions(ctx, utils.CGREvent{Event: args.EventStart}, reply)
|
||||
default:
|
||||
return fmt.Errorf("Unsupported request type <%s>", da.cgrCfg.DiameterAgentCfg().ForcedDisconnect)
|
||||
}
|
||||
@@ -389,8 +389,8 @@ func (da *DiameterAgent) sendASR(originID string, reply *string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// V1ReAuthorize sends a rar message to diameter client
|
||||
func (da *DiameterAgent) V1ReAuthorize(ctx *context.Context, cgrEv utils.CGREvent, reply *string) (err error) {
|
||||
// V1AlterSessions sends a rar message to diameter client
|
||||
func (da *DiameterAgent) V1AlterSessions(ctx *context.Context, cgrEv utils.CGREvent, reply *string) (err error) {
|
||||
originID, err := cgrEv.FieldAsString(utils.OriginID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not retrieve OriginID: %w", err)
|
||||
|
||||
@@ -486,8 +486,8 @@ func (fsa *FSsessions) V1WarnDisconnect(ctx *context.Context, args map[string]an
|
||||
return
|
||||
}
|
||||
|
||||
// V1ReAuthorize is used to implement the sessions.BiRPClient interface
|
||||
func (*FSsessions) V1ReAuthorize(*context.Context, utils.CGREvent, *string) error {
|
||||
// V1AlterSessions is used to implement the sessions.BiRPClient interface
|
||||
func (*FSsessions) V1AlterSessions(*context.Context, utils.CGREvent, *string) error {
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -461,8 +461,8 @@ func (ka *KamailioAgent) Reload() {
|
||||
ka.conns = make([]*kamevapi.KamEvapi, len(ka.cfg.EvapiConns))
|
||||
}
|
||||
|
||||
// V1ReAuthorize is used to implement the sessions.BiRPClient interface
|
||||
func (*KamailioAgent) V1ReAuthorize(*context.Context, utils.CGREvent, *string) error {
|
||||
// V1AlterSessions is used to implement the sessions.BiRPClient interface
|
||||
func (*KamailioAgent) V1AlterSessions(*context.Context, utils.CGREvent, *string) error {
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -521,8 +521,8 @@ func (ra *RadiusAgent) V1DisconnectSession(_ *context.Context, attr utils.AttrDi
|
||||
return nil
|
||||
}
|
||||
|
||||
// V1ReAuthorize updates session authorization using RADIUS CoA functionality.
|
||||
func (ra *RadiusAgent) V1ReAuthorize(_ *context.Context, cgrEv utils.CGREvent, reply *string) error {
|
||||
// V1AlterSessions updates session authorization using RADIUS CoA functionality.
|
||||
func (ra *RadiusAgent) V1AlterSessions(_ *context.Context, cgrEv utils.CGREvent, reply *string) error {
|
||||
originID, err := cgrEv.FieldAsString(utils.OriginID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not retrieve OriginID: %w", err)
|
||||
|
||||
@@ -52,7 +52,7 @@ TestRadiusCoADisconnect scenario:
|
||||
|
||||
4. Send an AccountingRequest to initialize a session.
|
||||
|
||||
5. Send a SessionSv1ReAuthorize request, that will send a CoA request to the client. The
|
||||
5. Send a SessionSv1AlterSessions request, that will send a CoA request to the client. The
|
||||
client will then verify that the packet was populated correctly.
|
||||
|
||||
6. Send a SessionSv1ForceDisconnect request, that will attempt to remotely disconnect the
|
||||
@@ -105,7 +105,7 @@ func TestRadiusCoADisconnect(t *testing.T) {
|
||||
"Address":"localhost:2012",
|
||||
"Attempts":1,
|
||||
"Transport":"*json",
|
||||
"Method":"SessionSv1.ReAuthorize",
|
||||
"Method":"SessionSv1.AlterSessions",
|
||||
"Params":{
|
||||
"Filters":["*string:~*req.Account:1001"],
|
||||
"Tenant":"cgrates.org",
|
||||
@@ -278,7 +278,7 @@ func TestRadiusCoADisconnect(t *testing.T) {
|
||||
t.Errorf("unexpected reply received to AccountingRequest: %+v", replyPacket)
|
||||
}
|
||||
/*
|
||||
if err := raDiscRPC.Call(context.Background(), utils.SessionSv1ReAuthorize,
|
||||
if err := raDiscRPC.Call(context.Background(), utils.SessionSv1AlterSessions,
|
||||
utils.SessionFilterWithEvent{
|
||||
SessionFilter: &utils.SessionFilter{
|
||||
APIOpts: map[string]any{
|
||||
|
||||
@@ -139,9 +139,9 @@ func (ssv1 *SessionSv1) DeactivateSessions(ctx *context.Context, args *utils.Ses
|
||||
return ssv1.sS.BiRPCv1DeactivateSessions(ctx, args, reply)
|
||||
}
|
||||
|
||||
// ReAuthorize sends the RAR for filterd sessions
|
||||
func (ssv1 *SessionSv1) ReAuthorize(ctx *context.Context, args utils.SessionFilterWithEvent, reply *string) error {
|
||||
return ssv1.sS.BiRPCv1ReAuthorize(ctx, args, reply)
|
||||
// AlterSessions sends the RAR for filterd sessions
|
||||
func (ssv1 *SessionSv1) AlterSessions(ctx *context.Context, args utils.SessionFilterWithEvent, reply *string) error {
|
||||
return ssv1.sS.BiRPCv1AlterSessions(ctx, args, reply)
|
||||
}
|
||||
|
||||
// DisconnectPeer sends the DPR for the OriginHost and OriginRealm
|
||||
|
||||
@@ -10,4 +10,4 @@ LOG_WARNING,*log,,,,,,,,,,,,,false,false,10
|
||||
DISABLE_AND_LOG,*log,,,,,,,,,,,,,false,false,10
|
||||
DISABLE_AND_LOG,*disable_account,,,,,,,,,,,,,false,false,10
|
||||
TOPUP_100SMS_DE_MOBILE,*topup,,,,*sms,,DST_DE_MOBILE,,,,,100,10,false,false,10
|
||||
#ACT_RAD_COA_ACNT_1001,*cgr_rpc,"{""Address"":""localhost:2012"",""Transport"":""*json"",""Method"":""SessionSv1.ReAuthorize"",""Attempts"":1,""Async"":false,""Params"":{""Filters"":[""*string:~*req.Account:1001""],""Tenant"":""cgrates.org"",""APIOpts"":{""*radCoATemplate"":""mycoa""},""Event"":{""CustomFilter"":""custom_filter""}}}",,,,,,,,,,,,,,20
|
||||
#ACT_RAD_COA_ACNT_1001,*cgr_rpc,"{""Address"":""localhost:2012"",""Transport"":""*json"",""Method"":""SessionSv1.AlterSessions"",""Attempts"":1,""Async"":false,""Params"":{""Filters"":[""*string:~*req.Account:1001""],""Tenant"":""cgrates.org"",""APIOpts"":{""*radCoATemplate"":""mycoa""},""Event"":{""CustomFilter"":""custom_filter""}}}",,,,,,,,,,,,,,20
|
||||
|
||||
|
@@ -47,7 +47,7 @@ var authReqs = engine.MapEvent{
|
||||
type BiRPCClient interface {
|
||||
V1DisconnectSession(*context.Context, utils.AttrDisconnectSession, *string) error
|
||||
V1GetActiveSessionIDs(*context.Context, string, *[]*SessionID) error
|
||||
V1ReAuthorize(*context.Context, utils.CGREvent, *string) error
|
||||
V1AlterSessions(*context.Context, utils.CGREvent, *string) error
|
||||
V1DisconnectPeer(*context.Context, *utils.DPRArgs, *string) error
|
||||
V1WarnDisconnect(*context.Context, map[string]any, *string) error
|
||||
}
|
||||
|
||||
@@ -4006,7 +4006,7 @@ func (sS *SessionS) sendRar(ctx *context.Context, s *Session, apiOpts map[string
|
||||
clnt := sS.biJClnt(s.ClientConnID)
|
||||
if clnt == nil {
|
||||
return fmt.Errorf("calling %s requires bidirectional JSON connection, connID: <%s>",
|
||||
utils.SessionSv1ReAuthorize, s.ClientConnID)
|
||||
utils.SessionSv1AlterSessions, s.ClientConnID)
|
||||
}
|
||||
|
||||
// Merge parameter event with the session event. Losing the EventStart OriginID
|
||||
@@ -4027,14 +4027,14 @@ func (sS *SessionS) sendRar(ctx *context.Context, s *Session, apiOpts map[string
|
||||
}
|
||||
|
||||
var rply string
|
||||
if err = clnt.conn.Call(ctx, utils.SessionSv1ReAuthorize, args, &rply); err == utils.ErrNotImplemented {
|
||||
if err = clnt.conn.Call(ctx, utils.SessionSv1AlterSessions, args, &rply); err == utils.ErrNotImplemented {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BiRPCv1ReAuthorize sends a RAR for the matching sessions
|
||||
func (sS *SessionS) BiRPCv1ReAuthorize(ctx *context.Context,
|
||||
// BiRPCv1AlterSessions sends a RAR for the matching sessions
|
||||
func (sS *SessionS) BiRPCv1AlterSessions(ctx *context.Context,
|
||||
args utils.SessionFilterWithEvent, reply *string) (err error) {
|
||||
if args.SessionFilter == nil { //protection in case on nil
|
||||
args.SessionFilter = &utils.SessionFilter{}
|
||||
|
||||
@@ -1664,7 +1664,7 @@ const (
|
||||
SessionSv1ActivateSessions = "SessionSv1.ActivateSessions"
|
||||
SessionSv1DeactivateSessions = "SessionSv1.DeactivateSessions"
|
||||
SMGenericV1InitiateSession = "SMGenericV1.InitiateSession"
|
||||
SessionSv1ReAuthorize = "SessionSv1.ReAuthorize"
|
||||
SessionSv1AlterSessions = "SessionSv1.AlterSessions"
|
||||
SessionSv1DisconnectPeer = "SessionSv1.DisconnectPeer"
|
||||
SessionSv1WarnDisconnect = "SessionSv1.WarnDisconnect"
|
||||
SessionSv1STIRAuthenticate = "SessionSv1.STIRAuthenticate"
|
||||
|
||||
Reference in New Issue
Block a user