mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Radius consider tenant from RequestProcessor
This commit is contained in:
committed by
Dan Christian Bogos
parent
2524a8c496
commit
b7bd69c6be
@@ -62,12 +62,11 @@ func NewRadiusAgent(cgrCfg *config.CGRConfig, filterS *engine.FilterS,
|
||||
}
|
||||
|
||||
type RadiusAgent struct {
|
||||
cgrCfg *config.CGRConfig // reference for future config reloads
|
||||
sessionS rpcclient.RpcClientConnection // Connection towards CGR-SessionS component
|
||||
tenantCfg config.RSRParsers
|
||||
filterS *engine.FilterS
|
||||
rsAuth *radigo.Server
|
||||
rsAcct *radigo.Server
|
||||
cgrCfg *config.CGRConfig // reference for future config reloads
|
||||
sessionS rpcclient.RpcClientConnection // Connection towards CGR-SessionS component
|
||||
filterS *engine.FilterS
|
||||
rsAuth *radigo.Server
|
||||
rsAcct *radigo.Server
|
||||
}
|
||||
|
||||
// handleAuth handles RADIUS Authorization request
|
||||
@@ -80,12 +79,12 @@ func (ra *RadiusAgent) handleAuth(req *radigo.Packet) (rpl *radigo.Packet, err e
|
||||
utils.RadiusAgent, err.Error()))
|
||||
return
|
||||
}
|
||||
agReq := newAgentRequest(dcdr, ra.tenantCfg, ra.cgrCfg.DefaultTenant, ra.filterS)
|
||||
agReq.Vars.Set([]string{MetaRadReqType}, utils.StringToInterface(MetaRadAuth), true)
|
||||
rpl = req.Reply()
|
||||
rpl.Code = radigo.AccessAccept
|
||||
var processed bool
|
||||
for _, reqProcessor := range ra.cgrCfg.RadiusAgentCfg().RequestProcessors {
|
||||
agReq := newAgentRequest(dcdr, reqProcessor.Tenant, ra.cgrCfg.DefaultTenant, ra.filterS)
|
||||
agReq.Vars.Set([]string{MetaRadReqType}, utils.StringToInterface(MetaRadAuth), true)
|
||||
var lclProcessed bool
|
||||
if lclProcessed, err = ra.processRequest(reqProcessor, agReq, rpl); lclProcessed {
|
||||
processed = lclProcessed
|
||||
@@ -95,12 +94,12 @@ func (ra *RadiusAgent) handleAuth(req *radigo.Packet) (rpl *radigo.Packet, err e
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s> ignoring request: %s, agentRequest: %+v",
|
||||
utils.RadiusAgent, err.Error(), utils.ToJSON(req), utils.ToJSON(agReq)))
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s> ignoring request: %s",
|
||||
utils.RadiusAgent, err.Error(), utils.ToJSON(req)))
|
||||
return nil, nil
|
||||
} else if !processed {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> no request processor enabled, ignoring request %s, agentRequest: %+v",
|
||||
utils.RadiusAgent, utils.ToJSON(req), utils.ToJSON(agReq)))
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> no request processor enabled, ignoring request %s",
|
||||
utils.RadiusAgent, utils.ToJSON(req)))
|
||||
return nil, nil
|
||||
}
|
||||
return
|
||||
@@ -117,11 +116,12 @@ func (ra *RadiusAgent) handleAcct(req *radigo.Packet) (rpl *radigo.Packet, err e
|
||||
utils.RadiusAgent, err.Error()))
|
||||
return
|
||||
}
|
||||
agReq := newAgentRequest(dcdr, ra.tenantCfg, ra.cgrCfg.DefaultTenant, ra.filterS)
|
||||
|
||||
rpl = req.Reply()
|
||||
rpl.Code = radigo.AccountingResponse
|
||||
var processed bool
|
||||
for _, reqProcessor := range ra.cgrCfg.RadiusAgentCfg().RequestProcessors {
|
||||
agReq := newAgentRequest(dcdr, reqProcessor.Tenant, ra.cgrCfg.DefaultTenant, ra.filterS)
|
||||
var lclProcessed bool
|
||||
if lclProcessed, err = ra.processRequest(reqProcessor, agReq, rpl); lclProcessed {
|
||||
processed = lclProcessed
|
||||
@@ -131,12 +131,12 @@ func (ra *RadiusAgent) handleAcct(req *radigo.Packet) (rpl *radigo.Packet, err e
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s> ignoring request: %s, agentRequest: %+v",
|
||||
utils.RadiusAgent, err.Error(), utils.ToJSON(req), utils.ToJSON(agReq)))
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s> ignoring request: %s, ",
|
||||
utils.RadiusAgent, err.Error(), utils.ToJSON(req)))
|
||||
return nil, nil
|
||||
} else if !processed {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> no request processor enabled, ignoring request %s, agentRequest: %+v",
|
||||
utils.RadiusAgent, utils.ToJSON(req), utils.ToJSON(agReq)))
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> no request processor enabled, ignoring request %s",
|
||||
utils.RadiusAgent, utils.ToJSON(req)))
|
||||
return nil, nil
|
||||
}
|
||||
return
|
||||
|
||||
@@ -397,7 +397,6 @@ const CGRATES_CFG_JSON = `
|
||||
{"address": "*internal"} // connection towards SessionService
|
||||
],
|
||||
"cdr_requires_session": false, // only create CDR if there is an active session at terminate
|
||||
"timezone": "", // timezone for timestamps where not specified, empty for general defaults <""|UTC|Local|$IANA_TZ_DB>
|
||||
"request_processors": [],
|
||||
},
|
||||
|
||||
|
||||
@@ -638,7 +638,6 @@ func TestRadiusAgentJsonCfg(t *testing.T) {
|
||||
Address: utils.StringPointer(utils.MetaInternal),
|
||||
}},
|
||||
Cdr_requires_session: utils.BoolPointer(false),
|
||||
Timezone: utils.StringPointer(""),
|
||||
Request_processors: &[]*RAReqProcessorJsnCfg{},
|
||||
}
|
||||
if cfg, err := dfCgrJsonCfg.RadiusAgentJsonCfg(); err != nil {
|
||||
|
||||
@@ -1078,7 +1078,6 @@ func TestRadiusAgentCfg(t *testing.T) {
|
||||
ClientDictionaries: map[string]string{utils.META_DEFAULT: "/usr/share/cgrates/radius/dict/"},
|
||||
SessionSConns: []*HaPoolConfig{&HaPoolConfig{Address: utils.MetaInternal}},
|
||||
CDRRequiresSession: false,
|
||||
Timezone: "",
|
||||
RequestProcessors: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.radiusAgentCfg, testRA) {
|
||||
|
||||
@@ -374,6 +374,8 @@ type RadiusAgentJsonCfg struct {
|
||||
type RAReqProcessorJsnCfg struct {
|
||||
Id *string
|
||||
Filters *[]string
|
||||
Tenant *string
|
||||
Timezone *string
|
||||
Flags *[]string
|
||||
Continue_on_success *bool
|
||||
Request_fields *[]*FcTemplateJsonCfg
|
||||
|
||||
@@ -30,9 +30,7 @@ type RadiusAgentCfg struct {
|
||||
ClientSecrets map[string]string
|
||||
ClientDictionaries map[string]string
|
||||
SessionSConns []*HaPoolConfig
|
||||
Tenant RSRParsers
|
||||
CDRRequiresSession bool
|
||||
Timezone string
|
||||
RequestProcessors []*RARequestProcessor
|
||||
}
|
||||
|
||||
@@ -75,15 +73,9 @@ func (self *RadiusAgentCfg) loadFromJsonCfg(jsnCfg *RadiusAgentJsonCfg) (err err
|
||||
self.SessionSConns[idx].loadFromJsonCfg(jsnHaCfg)
|
||||
}
|
||||
}
|
||||
if jsnCfg.Tenant != nil {
|
||||
self.Tenant = NewRSRParsersMustCompile(*jsnCfg.Tenant, true)
|
||||
}
|
||||
if jsnCfg.Cdr_requires_session != nil {
|
||||
self.CDRRequiresSession = *jsnCfg.Cdr_requires_session
|
||||
}
|
||||
if jsnCfg.Timezone != nil {
|
||||
self.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Request_processors != nil {
|
||||
for _, reqProcJsn := range *jsnCfg.Request_processors {
|
||||
rp := new(RARequestProcessor)
|
||||
@@ -109,7 +101,9 @@ func (self *RadiusAgentCfg) loadFromJsonCfg(jsnCfg *RadiusAgentJsonCfg) (err err
|
||||
// One Diameter request processor configuration
|
||||
type RARequestProcessor struct {
|
||||
Id string
|
||||
Tenant RSRParsers
|
||||
Filters []string
|
||||
Timezone string
|
||||
Flags utils.StringMap
|
||||
ContinueOnSuccess bool
|
||||
RequestFields []*FCTemplate
|
||||
@@ -135,6 +129,12 @@ func (self *RARequestProcessor) loadFromJsonCfg(jsnCfg *RAReqProcessorJsnCfg) (e
|
||||
if jsnCfg.Continue_on_success != nil {
|
||||
self.ContinueOnSuccess = *jsnCfg.Continue_on_success
|
||||
}
|
||||
if jsnCfg.Tenant != nil {
|
||||
self.Tenant = NewRSRParsersMustCompile(*jsnCfg.Tenant, true)
|
||||
}
|
||||
if jsnCfg.Timezone != nil {
|
||||
self.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Request_fields != nil {
|
||||
self.RequestFields = FCTemplatesFromFCTemapltesJsonCfg(*jsnCfg.Request_fields)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user