mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
SessionSv1.ProcessEvent with *accountsAuthorize functionality
This commit is contained in:
@@ -906,7 +906,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
||||
cchEv[utils.MetaAuthorize] = auth
|
||||
}
|
||||
|
||||
//IPsAuthorizeBool
|
||||
// IPs Authorization
|
||||
if ipsAuthBool, errBool := engine.GetBoolOpts(ctx, apiArgs.Tenant, apiArgs.AsDataProvider(), cchEv,
|
||||
sS.fltrS, sS.cfg.SessionSCfg().Opts.IPsAuthorize,
|
||||
utils.MetaIPsAuthorizeCfg); errBool != nil {
|
||||
@@ -914,15 +914,32 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
||||
} else {
|
||||
cchEv[utils.MetaIPsAuthorizeCfg] = ipsAuthBool
|
||||
}
|
||||
// IPAuthorization
|
||||
if cchEv[utils.MetaIPsAuthorizeCfg].(bool) ||
|
||||
(cchEv[utils.MetaAuthorize].(bool) && cchEv[utils.MetaIPs].(bool)) {
|
||||
var authIP *utils.AllocatedIP
|
||||
if authIP, err = sS.authorizeIPs(ctx, cgrEv); err != nil {
|
||||
if authIP, err = sS.ipsAuthorize(ctx, cgrEv); err != nil {
|
||||
return
|
||||
}
|
||||
apiRply.IPsAllocation[runID] = authIP
|
||||
}
|
||||
|
||||
// AccountS Authorization
|
||||
if acntsAuthBool, errBool := engine.GetBoolOpts(ctx, apiArgs.Tenant, apiArgs.AsDataProvider(), cchEv,
|
||||
sS.fltrS, sS.cfg.SessionSCfg().Opts.AccountsAuthorize,
|
||||
utils.MetaAccountsAuthorizeCfg); errBool != nil {
|
||||
return errBool
|
||||
} else {
|
||||
cchEv[utils.MetaAccountsAuthorizeCfg] = acntsAuthBool
|
||||
}
|
||||
if cchEv[utils.MetaAccountsAuthorizeCfg].(bool) ||
|
||||
(cchEv[utils.MetaAuthorize].(bool) && cchEv[utils.MetaAccounts].(bool)) {
|
||||
var acntCost *utils.EventCharges
|
||||
if acntCost, err = sS.accountsMaxAbstracts(ctx, cgrEv); err != nil {
|
||||
return
|
||||
}
|
||||
maxDur, _ := acntCost.Abstracts.Duration()
|
||||
apiRply.AccountSUsage[runID] = maxDur
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -953,8 +953,8 @@ func (sS *SessionS) processChargerS(ctx *context.Context, cgrEv *utils.CGREvent)
|
||||
return
|
||||
}
|
||||
|
||||
// authorizeIPs will authorize the event with IPs subsystem
|
||||
func (sS *SessionS) authorizeIPs(ctx *context.Context, cgrEv *utils.CGREvent) (rply *utils.AllocatedIP, err error) {
|
||||
// ipsAuthorize will authorize the event with the IPs subsystem
|
||||
func (sS *SessionS) ipsAuthorize(ctx *context.Context, cgrEv *utils.CGREvent) (rply *utils.AllocatedIP, err error) {
|
||||
if len(sS.cfg.SessionSCfg().IPsConns) == 0 {
|
||||
err = errors.New("IPs is disabled")
|
||||
return
|
||||
@@ -968,7 +968,20 @@ func (sS *SessionS) authorizeIPs(ctx *context.Context, cgrEv *utils.CGREvent) (r
|
||||
utils.SessionS, err.Error(), cgrEv))
|
||||
}
|
||||
return &alcIP, nil
|
||||
}
|
||||
|
||||
// accountsMaxAbstracts will query the AccountS cost for Event
|
||||
func (sS *SessionS) accountsMaxAbstracts(ctx *context.Context, cgrEv *utils.CGREvent) (rply *utils.EventCharges, err error) {
|
||||
if len(sS.cfg.SessionSCfg().AccountSConns) == 0 {
|
||||
err = errors.New("AccountS is disabled")
|
||||
return
|
||||
}
|
||||
var acntCost utils.EventCharges
|
||||
if err = sS.connMgr.Call(ctx, sS.cfg.SessionSCfg().AccountSConns,
|
||||
utils.AccountSv1MaxAbstracts, cgrEv, &acntCost); err != nil {
|
||||
return
|
||||
}
|
||||
return &acntCost, nil
|
||||
}
|
||||
|
||||
// getSessions is used to return in a thread-safe manner active or passive sessions
|
||||
|
||||
@@ -2478,6 +2478,7 @@ const (
|
||||
MetaResourcesReleaseCfg = "*resourcesRelease"
|
||||
MetaResourcesDerivedReplyCfg = "*resourcesDerivedReply"
|
||||
MetaIPsAuthorizeCfg = "*ipsAuthorize"
|
||||
MetaAccountsAuthorizeCfg = "*accountsAuthorize"
|
||||
MetaIPsAllocateCfg = "*ipsAllocate"
|
||||
MetaIPsReleaseCfg = "*ipsRelease"
|
||||
MetaRoutesDerivedReplyCfg = "*routesDerivedReply"
|
||||
|
||||
Reference in New Issue
Block a user