mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16: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
|
cchEv[utils.MetaAuthorize] = auth
|
||||||
}
|
}
|
||||||
|
|
||||||
//IPsAuthorizeBool
|
// IPs Authorization
|
||||||
if ipsAuthBool, errBool := engine.GetBoolOpts(ctx, apiArgs.Tenant, apiArgs.AsDataProvider(), cchEv,
|
if ipsAuthBool, errBool := engine.GetBoolOpts(ctx, apiArgs.Tenant, apiArgs.AsDataProvider(), cchEv,
|
||||||
sS.fltrS, sS.cfg.SessionSCfg().Opts.IPsAuthorize,
|
sS.fltrS, sS.cfg.SessionSCfg().Opts.IPsAuthorize,
|
||||||
utils.MetaIPsAuthorizeCfg); errBool != nil {
|
utils.MetaIPsAuthorizeCfg); errBool != nil {
|
||||||
@@ -914,15 +914,32 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
|||||||
} else {
|
} else {
|
||||||
cchEv[utils.MetaIPsAuthorizeCfg] = ipsAuthBool
|
cchEv[utils.MetaIPsAuthorizeCfg] = ipsAuthBool
|
||||||
}
|
}
|
||||||
// IPAuthorization
|
|
||||||
if cchEv[utils.MetaIPsAuthorizeCfg].(bool) ||
|
if cchEv[utils.MetaIPsAuthorizeCfg].(bool) ||
|
||||||
(cchEv[utils.MetaAuthorize].(bool) && cchEv[utils.MetaIPs].(bool)) {
|
(cchEv[utils.MetaAuthorize].(bool) && cchEv[utils.MetaIPs].(bool)) {
|
||||||
var authIP *utils.AllocatedIP
|
var authIP *utils.AllocatedIP
|
||||||
if authIP, err = sS.authorizeIPs(ctx, cgrEv); err != nil {
|
if authIP, err = sS.ipsAuthorize(ctx, cgrEv); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiRply.IPsAllocation[runID] = authIP
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -953,8 +953,8 @@ func (sS *SessionS) processChargerS(ctx *context.Context, cgrEv *utils.CGREvent)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// authorizeIPs will authorize the event with IPs subsystem
|
// ipsAuthorize will authorize the event with the IPs subsystem
|
||||||
func (sS *SessionS) authorizeIPs(ctx *context.Context, cgrEv *utils.CGREvent) (rply *utils.AllocatedIP, err error) {
|
func (sS *SessionS) ipsAuthorize(ctx *context.Context, cgrEv *utils.CGREvent) (rply *utils.AllocatedIP, err error) {
|
||||||
if len(sS.cfg.SessionSCfg().IPsConns) == 0 {
|
if len(sS.cfg.SessionSCfg().IPsConns) == 0 {
|
||||||
err = errors.New("IPs is disabled")
|
err = errors.New("IPs is disabled")
|
||||||
return
|
return
|
||||||
@@ -968,7 +968,20 @@ func (sS *SessionS) authorizeIPs(ctx *context.Context, cgrEv *utils.CGREvent) (r
|
|||||||
utils.SessionS, err.Error(), cgrEv))
|
utils.SessionS, err.Error(), cgrEv))
|
||||||
}
|
}
|
||||||
return &alcIP, nil
|
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
|
// getSessions is used to return in a thread-safe manner active or passive sessions
|
||||||
|
|||||||
@@ -2478,6 +2478,7 @@ const (
|
|||||||
MetaResourcesReleaseCfg = "*resourcesRelease"
|
MetaResourcesReleaseCfg = "*resourcesRelease"
|
||||||
MetaResourcesDerivedReplyCfg = "*resourcesDerivedReply"
|
MetaResourcesDerivedReplyCfg = "*resourcesDerivedReply"
|
||||||
MetaIPsAuthorizeCfg = "*ipsAuthorize"
|
MetaIPsAuthorizeCfg = "*ipsAuthorize"
|
||||||
|
MetaAccountsAuthorizeCfg = "*accountsAuthorize"
|
||||||
MetaIPsAllocateCfg = "*ipsAllocate"
|
MetaIPsAllocateCfg = "*ipsAllocate"
|
||||||
MetaIPsReleaseCfg = "*ipsRelease"
|
MetaIPsReleaseCfg = "*ipsRelease"
|
||||||
MetaRoutesDerivedReplyCfg = "*routesDerivedReply"
|
MetaRoutesDerivedReplyCfg = "*routesDerivedReply"
|
||||||
|
|||||||
Reference in New Issue
Block a user