mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
Use only one RequestProcessor for Agents
This commit is contained in:
@@ -244,14 +244,13 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) {
|
||||
writeOnConn(c, a)
|
||||
}
|
||||
|
||||
func (da *DiameterAgent) processRequest(reqProcessor *config.DARequestProcessor,
|
||||
func (da *DiameterAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
agReq *AgentRequest) (processed bool, err error) {
|
||||
if pass, err := da.filterS.Pass(agReq.tenant,
|
||||
reqProcessor.Filters, agReq); err != nil || !pass {
|
||||
return pass, err
|
||||
}
|
||||
if agReq.CGRRequest, err = agReq.AsNavigableMap(reqProcessor.RequestFields); err != nil {
|
||||
fmt.Println("EXIT HERE ???????????? ")
|
||||
return
|
||||
}
|
||||
cgrEv := agReq.CGRRequest.AsCGREvent(agReq.tenant, utils.NestingSep)
|
||||
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
// NewHttpAgent will construct a HTTPAgent
|
||||
func NewHTTPAgent(sessionS rpcclient.RpcClientConnection,
|
||||
filterS *engine.FilterS, dfltTenant, reqPayload, rplyPayload string,
|
||||
reqProcessors []*config.HttpAgntProcCfg) *HTTPAgent {
|
||||
reqProcessors []*config.RequestProcessor) *HTTPAgent {
|
||||
return &HTTPAgent{sessionS: sessionS, filterS: filterS,
|
||||
dfltTenant: dfltTenant,
|
||||
reqPayload: reqPayload, rplyPayload: rplyPayload,
|
||||
@@ -46,7 +46,7 @@ type HTTPAgent struct {
|
||||
dfltTenant,
|
||||
reqPayload,
|
||||
rplyPayload string
|
||||
reqProcessors []*config.HttpAgntProcCfg
|
||||
reqProcessors []*config.RequestProcessor
|
||||
}
|
||||
|
||||
// ServeHTTP implements http.Handler interface
|
||||
@@ -94,7 +94,7 @@ func (ha *HTTPAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
// processRequest represents one processor processing the request
|
||||
func (ha *HTTPAgent) processRequest(reqProcessor *config.HttpAgntProcCfg,
|
||||
func (ha *HTTPAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
agReq *AgentRequest) (processed bool, err error) {
|
||||
if pass, err := ha.filterS.Pass(agReq.tenant,
|
||||
reqProcessor.Filters, agReq); err != nil || !pass {
|
||||
@@ -119,7 +119,7 @@ func (ha *HTTPAgent) processRequest(reqProcessor *config.HttpAgntProcCfg,
|
||||
if reqProcessor.Flags.HasKey(utils.MetaLog) {
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> LOG, processorID: %s, http message: %s",
|
||||
utils.HTTPAgent, reqProcessor.Id, agReq.Request.String()))
|
||||
utils.HTTPAgent, reqProcessor.ID, agReq.Request.String()))
|
||||
}
|
||||
switch reqType {
|
||||
default:
|
||||
@@ -127,7 +127,7 @@ func (ha *HTTPAgent) processRequest(reqProcessor *config.HttpAgntProcCfg,
|
||||
case utils.MetaDryRun:
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> DRY_RUN, processorID: %s, CGREvent: %s",
|
||||
utils.HTTPAgent, reqProcessor.Id, utils.ToJSON(cgrEv)))
|
||||
utils.HTTPAgent, reqProcessor.ID, utils.ToJSON(cgrEv)))
|
||||
case utils.MetaAuth:
|
||||
authArgs := sessions.NewV1AuthorizeArgs(
|
||||
reqProcessor.Flags.HasKey(utils.MetaAttributes),
|
||||
|
||||
@@ -138,7 +138,7 @@ func (ra *RadiusAgent) handleAcct(req *radigo.Packet) (rpl *radigo.Packet, err e
|
||||
}
|
||||
|
||||
// processRequest represents one processor processing the request
|
||||
func (ra *RadiusAgent) processRequest(reqProcessor *config.RARequestProcessor,
|
||||
func (ra *RadiusAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
agReq *AgentRequest, rply *radigo.Packet) (processed bool, err error) {
|
||||
if pass, err := ra.filterS.Pass(agReq.tenant,
|
||||
reqProcessor.Filters, agReq); err != nil || !pass {
|
||||
@@ -163,7 +163,7 @@ func (ra *RadiusAgent) processRequest(reqProcessor *config.RARequestProcessor,
|
||||
if reqProcessor.Flags.HasKey(utils.MetaLog) {
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> LOG, processorID: %s, radius message: %s",
|
||||
utils.RadiusAgent, reqProcessor.Id, agReq.Request.String()))
|
||||
utils.RadiusAgent, reqProcessor.ID, agReq.Request.String()))
|
||||
}
|
||||
switch reqType {
|
||||
default:
|
||||
@@ -171,7 +171,7 @@ func (ra *RadiusAgent) processRequest(reqProcessor *config.RARequestProcessor,
|
||||
case utils.MetaDryRun:
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> DRY_RUN, processorID: %s, CGREvent: %s",
|
||||
utils.RadiusAgent, reqProcessor.Id, utils.ToJSON(cgrEv)))
|
||||
utils.RadiusAgent, reqProcessor.ID, utils.ToJSON(cgrEv)))
|
||||
case utils.MetaAuth:
|
||||
authArgs := sessions.NewV1AuthorizeArgs(
|
||||
reqProcessor.Flags.HasKey(utils.MetaAttributes),
|
||||
|
||||
@@ -692,7 +692,7 @@ func TestDiameterAgentJsonCfg(t *testing.T) {
|
||||
Value: utils.StringPointer("1")},
|
||||
},
|
||||
},
|
||||
Request_processors: &[]*DARequestProcessorJsnCfg{},
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{},
|
||||
}
|
||||
if cfg, err := dfCgrJsonCfg.DiameterAgentJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
@@ -717,7 +717,7 @@ func TestRadiusAgentJsonCfg(t *testing.T) {
|
||||
{
|
||||
Address: utils.StringPointer(utils.MetaInternal),
|
||||
}},
|
||||
Request_processors: &[]*RAReqProcessorJsnCfg{},
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{},
|
||||
}
|
||||
if cfg, err := dfCgrJsonCfg.RadiusAgentJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -18,10 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type DiameterAgentCfg struct {
|
||||
Enabled bool // enables the diameter agent: <true|false>
|
||||
ListenNet string // sctp or tcp
|
||||
@@ -36,7 +32,7 @@ type DiameterAgentCfg struct {
|
||||
SyncedConnReqs bool
|
||||
ASRTemplate string
|
||||
Templates map[string][]*FCTemplate
|
||||
RequestProcessors []*DARequestProcessor
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
func (da *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg, separator string) (err error) {
|
||||
@@ -95,10 +91,10 @@ func (da *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg, separa
|
||||
}
|
||||
if jsnCfg.Request_processors != nil {
|
||||
for _, reqProcJsn := range *jsnCfg.Request_processors {
|
||||
rp := new(DARequestProcessor)
|
||||
rp := new(RequestProcessor)
|
||||
var haveID bool
|
||||
for _, rpSet := range da.RequestProcessors {
|
||||
if reqProcJsn.Id != nil && rpSet.ID == *reqProcJsn.Id {
|
||||
if reqProcJsn.ID != nil && rpSet.ID == *reqProcJsn.ID {
|
||||
rp = rpSet // Will load data into the one set
|
||||
haveID = true
|
||||
break
|
||||
@@ -114,55 +110,3 @@ func (da *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg, separa
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// One Diameter request processor configuration
|
||||
type DARequestProcessor struct {
|
||||
ID string
|
||||
Tenant RSRParsers
|
||||
Filters []string
|
||||
Flags utils.StringMap
|
||||
Timezone string // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB>
|
||||
ContinueOnSuccess bool
|
||||
RequestFields []*FCTemplate
|
||||
ReplyFields []*FCTemplate
|
||||
}
|
||||
|
||||
func (dap *DARequestProcessor) loadFromJsonCfg(jsnCfg *DARequestProcessorJsnCfg, separator string) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Id != nil {
|
||||
dap.ID = *jsnCfg.Id
|
||||
}
|
||||
if jsnCfg.Tenant != nil {
|
||||
if dap.Tenant, err = NewRSRParsers(*jsnCfg.Tenant, true, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if jsnCfg.Filters != nil {
|
||||
dap.Filters = make([]string, len(*jsnCfg.Filters))
|
||||
for i, fltr := range *jsnCfg.Filters {
|
||||
dap.Filters[i] = fltr
|
||||
}
|
||||
}
|
||||
if jsnCfg.Flags != nil {
|
||||
dap.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
|
||||
}
|
||||
if jsnCfg.Timezone != nil {
|
||||
dap.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Continue_on_success != nil {
|
||||
dap.ContinueOnSuccess = *jsnCfg.Continue_on_success
|
||||
}
|
||||
if jsnCfg.Request_fields != nil {
|
||||
if dap.RequestFields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnCfg.Request_fields, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if jsnCfg.Reply_fields != nil {
|
||||
if dap.ReplyFields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnCfg.Reply_fields, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -75,38 +75,3 @@ func TestDiameterAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(dacfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDARequestProcessorloadFromJsonCfg(t *testing.T) {
|
||||
var dareq, expected DARequestProcessor
|
||||
if err := dareq.loadFromJsonCfg(nil, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(dareq, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, dareq)
|
||||
}
|
||||
if err := dareq.loadFromJsonCfg(new(DARequestProcessorJsnCfg), utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(dareq, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, dareq)
|
||||
}
|
||||
json := &DARequestProcessorJsnCfg{
|
||||
Id: utils.StringPointer("cgrates"),
|
||||
Tenant: utils.StringPointer("tenant"),
|
||||
Filters: &[]string{"filter1", "filter2"},
|
||||
Flags: &[]string{"flag1", "flag2"},
|
||||
Timezone: utils.StringPointer("Local"),
|
||||
Continue_on_success: utils.BoolPointer(true),
|
||||
}
|
||||
expected = DARequestProcessor{
|
||||
ID: "cgrates",
|
||||
Tenant: NewRSRParsersMustCompile("tenant", true, utils.INFIELD_SEP),
|
||||
Filters: []string{"filter1", "filter2"},
|
||||
Flags: utils.StringMap{"flag1": true, "flag2": true},
|
||||
Timezone: "Local",
|
||||
ContinueOnSuccess: true,
|
||||
}
|
||||
if err = dareq.loadFromJsonCfg(json, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, dareq) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(dareq))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ type RequestProcessor struct {
|
||||
Filters []string
|
||||
Flags utils.StringMap
|
||||
ContinueOnSuccess bool
|
||||
Timezone string
|
||||
RequestFields []*FCTemplate
|
||||
ReplyFields []*FCTemplate
|
||||
}
|
||||
@@ -103,6 +104,9 @@ func (rp *RequestProcessor) loadFromJsonCfg(jsnCfg *ReqProcessorJsnCfg, sep stri
|
||||
if jsnCfg.Flags != nil {
|
||||
rp.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
|
||||
}
|
||||
if jsnCfg.Timezone != nil {
|
||||
rp.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Continue_on_success != nil {
|
||||
rp.ContinueOnSuccess = *jsnCfg.Continue_on_success
|
||||
}
|
||||
|
||||
@@ -18,10 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type HttpAgentCfgs []*HttpAgentCfg
|
||||
|
||||
func (hcfgs *HttpAgentCfgs) loadFromJsonCfg(jsnHttpAgntCfg *[]*HttpAgentJsonCfg, separator string) (err error) {
|
||||
@@ -58,19 +54,19 @@ type HttpAgentCfg struct {
|
||||
SessionSConns []*RemoteHost
|
||||
RequestPayload string
|
||||
ReplyPayload string
|
||||
RequestProcessors []*HttpAgntProcCfg
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
func (ca *HttpAgentCfg) appendHttpAgntProcCfgs(hps *[]*HttpAgentProcessorJsnCfg, separator string) (err error) {
|
||||
func (ca *HttpAgentCfg) appendHttpAgntProcCfgs(hps *[]*ReqProcessorJsnCfg, separator string) (err error) {
|
||||
if hps == nil {
|
||||
return
|
||||
}
|
||||
for _, reqProcJsn := range *hps {
|
||||
rp := new(HttpAgntProcCfg)
|
||||
rp := new(RequestProcessor)
|
||||
var haveID bool
|
||||
if reqProcJsn.Id != nil {
|
||||
if reqProcJsn.ID != nil {
|
||||
for _, rpSet := range ca.RequestProcessors {
|
||||
if rpSet.Id == *reqProcJsn.Id {
|
||||
if rpSet.ID == *reqProcJsn.ID {
|
||||
rp = rpSet // Will load data into the one set
|
||||
haveID = true
|
||||
break
|
||||
@@ -115,54 +111,3 @@ func (ca *HttpAgentCfg) loadFromJsonCfg(jsnCfg *HttpAgentJsonCfg, separator stri
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type HttpAgntProcCfg struct {
|
||||
Id string
|
||||
Filters []string
|
||||
Tenant RSRParsers
|
||||
Timezone string
|
||||
Flags utils.StringMap
|
||||
ContinueOnSuccess bool
|
||||
RequestFields []*FCTemplate
|
||||
ReplyFields []*FCTemplate
|
||||
}
|
||||
|
||||
func (ha *HttpAgntProcCfg) loadFromJsonCfg(jsnCfg *HttpAgentProcessorJsnCfg, separator string) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Id != nil {
|
||||
ha.Id = *jsnCfg.Id
|
||||
}
|
||||
if jsnCfg.Filters != nil {
|
||||
ha.Filters = make([]string, len(*jsnCfg.Filters))
|
||||
for i, fltr := range *jsnCfg.Filters {
|
||||
ha.Filters[i] = fltr
|
||||
}
|
||||
}
|
||||
if jsnCfg.Tenant != nil {
|
||||
if ha.Tenant, err = NewRSRParsers(*jsnCfg.Tenant, true, separator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if jsnCfg.Timezone != nil {
|
||||
ha.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Flags != nil {
|
||||
ha.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
|
||||
}
|
||||
if jsnCfg.Continue_on_success != nil {
|
||||
ha.ContinueOnSuccess = *jsnCfg.Continue_on_success
|
||||
}
|
||||
if jsnCfg.Request_fields != nil {
|
||||
if ha.RequestFields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnCfg.Request_fields, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if jsnCfg.Reply_fields != nil {
|
||||
if ha.ReplyFields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnCfg.Reply_fields, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "OutboundAUTHDryRun",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -149,8 +149,8 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "OutboundAUTHDryRun",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -163,7 +163,7 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
Mandatory: true,
|
||||
}}},
|
||||
{
|
||||
Id: "mtcall_cdr",
|
||||
ID: "mtcall_cdr",
|
||||
Filters: []string{"*string:*req.request_type:MTCALL_CDR"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*cdrs": true},
|
||||
@@ -188,8 +188,8 @@ func TestHttpAgentCfgsloadFromJsonCfg(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*xml",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "cdr_from_xml",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "cdr_from_xml",
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*cdrs": true},
|
||||
RequestFields: []*FCTemplate{},
|
||||
@@ -226,9 +226,9 @@ func TestHttpAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
Sessions_conns: &[]*RemoteHostJson{{Address: utils.StringPointer("127.0.0.1:2012"), Transport: utils.StringPointer("*json")}},
|
||||
Request_payload: utils.StringPointer("*url"),
|
||||
Reply_payload: utils.StringPointer("*xml"),
|
||||
Request_processors: &[]*HttpAgentProcessorJsnCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
Id: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{"*dryrun"},
|
||||
@@ -243,8 +243,8 @@ func TestHttpAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "OutboundAUTHDryRun",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -267,8 +267,8 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "OutboundAUTHDryRun",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -282,8 +282,8 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
}},
|
||||
}},
|
||||
}
|
||||
proceses := &[]*HttpAgentProcessorJsnCfg{{
|
||||
Id: utils.StringPointer("OutboundAUTHDryRun1"),
|
||||
proceses := &[]*ReqProcessorJsnCfg{{
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun1"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{"*dryrun"},
|
||||
@@ -296,7 +296,7 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
}},
|
||||
}, {
|
||||
Id: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{"*dryrun"},
|
||||
@@ -316,8 +316,8 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "OutboundAUTHDryRun",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -330,7 +330,7 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
Mandatory: false,
|
||||
}},
|
||||
}, {
|
||||
Id: "OutboundAUTHDryRun1",
|
||||
ID: "OutboundAUTHDryRun1",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -351,52 +351,3 @@ func TestHttpAgentCfgappendHttpAgntProcCfgs(t *testing.T) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(initial))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHttpAgntProcCfgloadFromJsonCfg(t *testing.T) {
|
||||
var httpcfg, expected HttpAgntProcCfg
|
||||
if err := httpcfg.loadFromJsonCfg(nil, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(httpcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, httpcfg)
|
||||
}
|
||||
if err := httpcfg.loadFromJsonCfg(new(HttpAgentProcessorJsnCfg), utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(httpcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, httpcfg)
|
||||
}
|
||||
|
||||
jsnhttpCfg := &HttpAgentProcessorJsnCfg{
|
||||
Id: utils.StringPointer("OutboundAUTHDryRun1"),
|
||||
Filters: &[]string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: utils.StringPointer("cgrates.org"),
|
||||
Flags: &[]string{"*dryrun"},
|
||||
Request_fields: &[]*FcTemplateJsonCfg{},
|
||||
Reply_fields: &[]*FcTemplateJsonCfg{{
|
||||
Tag: utils.StringPointer("Allow"),
|
||||
Field_id: utils.StringPointer("response.Allow"),
|
||||
Type: utils.StringPointer("*constant"),
|
||||
Value: utils.StringPointer("1"),
|
||||
Mandatory: utils.BoolPointer(true),
|
||||
}},
|
||||
}
|
||||
expected = HttpAgntProcCfg{
|
||||
Id: "OutboundAUTHDryRun1",
|
||||
Filters: []string{"*string:*req.request_type:OutboundAUTH", "*string:*req.Msisdn:497700056231"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
RequestFields: []*FCTemplate{},
|
||||
ReplyFields: []*FCTemplate{{
|
||||
Tag: "Allow",
|
||||
FieldId: "response.Allow",
|
||||
Type: "*constant",
|
||||
Value: NewRSRParsersMustCompile("1", true, utils.INFIELD_SEP),
|
||||
Mandatory: true,
|
||||
}},
|
||||
}
|
||||
|
||||
if err = httpcfg.loadFromJsonCfg(jsnhttpCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, httpcfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(httpcfg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,19 +335,7 @@ type DiameterAgentJsonCfg struct {
|
||||
Synced_conn_requests *bool
|
||||
Asr_template *string
|
||||
Templates map[string][]*FcTemplateJsonCfg
|
||||
Request_processors *[]*DARequestProcessorJsnCfg
|
||||
}
|
||||
|
||||
// One Diameter request processor configuration
|
||||
type DARequestProcessorJsnCfg struct {
|
||||
Id *string
|
||||
Tenant *string
|
||||
Filters *[]string
|
||||
Flags *[]string
|
||||
Timezone *string
|
||||
Continue_on_success *bool
|
||||
Request_fields *[]*FcTemplateJsonCfg
|
||||
Reply_fields *[]*FcTemplateJsonCfg
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
// Radius Agent configuration section
|
||||
@@ -360,18 +348,7 @@ type RadiusAgentJsonCfg struct {
|
||||
Client_dictionaries *map[string]string
|
||||
Sessions_conns *[]*RemoteHostJson
|
||||
Timezone *string
|
||||
Request_processors *[]*RAReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
type RAReqProcessorJsnCfg struct {
|
||||
Id *string
|
||||
Filters *[]string
|
||||
Tenant *string
|
||||
Timezone *string
|
||||
Flags *[]string
|
||||
Continue_on_success *bool
|
||||
Request_fields *[]*FcTemplateJsonCfg
|
||||
Reply_fields *[]*FcTemplateJsonCfg
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
// Conecto Agent configuration section
|
||||
@@ -381,18 +358,7 @@ type HttpAgentJsonCfg struct {
|
||||
Sessions_conns *[]*RemoteHostJson
|
||||
Request_payload *string
|
||||
Reply_payload *string
|
||||
Request_processors *[]*HttpAgentProcessorJsnCfg
|
||||
}
|
||||
|
||||
type HttpAgentProcessorJsnCfg struct {
|
||||
Id *string
|
||||
Filters *[]string
|
||||
Tenant *string
|
||||
Timezone *string
|
||||
Flags *[]string
|
||||
Continue_on_success *bool
|
||||
Request_fields *[]*FcTemplateJsonCfg
|
||||
Reply_fields *[]*FcTemplateJsonCfg
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
// DNSAgentJsonCfg
|
||||
|
||||
@@ -138,9 +138,9 @@ func TestMfHttpAgentMultipleFields(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.2:2012", Transport: "*json"}},
|
||||
RequestPayload: "*url",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
Id: "OutboundAUTHDryRun",
|
||||
ID: "OutboundAUTHDryRun",
|
||||
Filters: []string{},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*dryrun": true},
|
||||
@@ -154,7 +154,7 @@ func TestMfHttpAgentMultipleFields(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
{
|
||||
Id: "OutboundAUTH",
|
||||
ID: "OutboundAUTH",
|
||||
Filters: []string{"*string:~*req.request_type:OutboundAUTH"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*accounts": true,
|
||||
@@ -179,7 +179,7 @@ func TestMfHttpAgentMultipleFields(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "mtcall_cdr",
|
||||
ID: "mtcall_cdr",
|
||||
Filters: []string{"*string:~*req.request_type:MTCALL_CDR"},
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*cdrs": true},
|
||||
@@ -206,8 +206,8 @@ func TestMfHttpAgentMultipleFields(t *testing.T) {
|
||||
SessionSConns: []*RemoteHost{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
RequestPayload: "*xml",
|
||||
ReplyPayload: "*xml",
|
||||
RequestProcessors: []*HttpAgntProcCfg{{
|
||||
Id: "cdr_from_xml",
|
||||
RequestProcessors: []*RequestProcessor{{
|
||||
ID: "cdr_from_xml",
|
||||
Tenant: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP),
|
||||
Flags: utils.StringMap{"*cdrs": true},
|
||||
RequestFields: []*FCTemplate{
|
||||
|
||||
@@ -18,10 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type RadiusAgentCfg struct {
|
||||
Enabled bool
|
||||
ListenNet string // udp or tcp
|
||||
@@ -30,7 +26,7 @@ type RadiusAgentCfg struct {
|
||||
ClientSecrets map[string]string
|
||||
ClientDictionaries map[string]string
|
||||
SessionSConns []*RemoteHost
|
||||
RequestProcessors []*RARequestProcessor
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
func (self *RadiusAgentCfg) loadFromJsonCfg(jsnCfg *RadiusAgentJsonCfg, separator string) (err error) {
|
||||
@@ -74,10 +70,10 @@ func (self *RadiusAgentCfg) loadFromJsonCfg(jsnCfg *RadiusAgentJsonCfg, separato
|
||||
}
|
||||
if jsnCfg.Request_processors != nil {
|
||||
for _, reqProcJsn := range *jsnCfg.Request_processors {
|
||||
rp := new(RARequestProcessor)
|
||||
rp := new(RequestProcessor)
|
||||
var haveID bool
|
||||
for _, rpSet := range self.RequestProcessors {
|
||||
if reqProcJsn.Id != nil && rpSet.Id == *reqProcJsn.Id {
|
||||
if reqProcJsn.ID != nil && rpSet.ID == *reqProcJsn.ID {
|
||||
rp = rpSet // Will load data into the one set
|
||||
haveID = true
|
||||
break
|
||||
@@ -93,55 +89,3 @@ func (self *RadiusAgentCfg) loadFromJsonCfg(jsnCfg *RadiusAgentJsonCfg, separato
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// One Diameter request processor configuration
|
||||
type RARequestProcessor struct {
|
||||
Id string
|
||||
Tenant RSRParsers
|
||||
Filters []string
|
||||
Timezone string
|
||||
Flags utils.StringMap
|
||||
ContinueOnSuccess bool
|
||||
RequestFields []*FCTemplate
|
||||
ReplyFields []*FCTemplate
|
||||
}
|
||||
|
||||
func (self *RARequestProcessor) loadFromJsonCfg(jsnCfg *RAReqProcessorJsnCfg, separator string) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Id != nil {
|
||||
self.Id = *jsnCfg.Id
|
||||
}
|
||||
if jsnCfg.Filters != nil {
|
||||
self.Filters = make([]string, len(*jsnCfg.Filters))
|
||||
for i, fltr := range *jsnCfg.Filters {
|
||||
self.Filters[i] = fltr
|
||||
}
|
||||
}
|
||||
if jsnCfg.Flags != nil {
|
||||
self.Flags = utils.StringMapFromSlice(*jsnCfg.Flags)
|
||||
}
|
||||
if jsnCfg.Continue_on_success != nil {
|
||||
self.ContinueOnSuccess = *jsnCfg.Continue_on_success
|
||||
}
|
||||
if jsnCfg.Tenant != nil {
|
||||
if self.Tenant, err = NewRSRParsers(*jsnCfg.Tenant, true, separator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if jsnCfg.Timezone != nil {
|
||||
self.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Request_fields != nil {
|
||||
if self.RequestFields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnCfg.Request_fields, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if jsnCfg.Reply_fields != nil {
|
||||
if self.ReplyFields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnCfg.Reply_fields, separator); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -73,38 +73,3 @@ func TestRadiusAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(racfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRARequestProcessorloadFromJsonCfg(t *testing.T) {
|
||||
var rareq, expected RARequestProcessor
|
||||
if err := rareq.loadFromJsonCfg(nil, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rareq, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, rareq)
|
||||
}
|
||||
if err := rareq.loadFromJsonCfg(new(RAReqProcessorJsnCfg), utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rareq, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, rareq)
|
||||
}
|
||||
json := &RAReqProcessorJsnCfg{
|
||||
Id: utils.StringPointer("cgrates"),
|
||||
Tenant: utils.StringPointer("tenant"),
|
||||
Filters: &[]string{"filter1", "filter2"},
|
||||
Flags: &[]string{"flag1", "flag2"},
|
||||
Timezone: utils.StringPointer("Local"),
|
||||
Continue_on_success: utils.BoolPointer(true),
|
||||
}
|
||||
expected = RARequestProcessor{
|
||||
Id: "cgrates",
|
||||
Tenant: NewRSRParsersMustCompile("tenant", true, utils.INFIELD_SEP),
|
||||
Filters: []string{"filter1", "filter2"},
|
||||
Flags: utils.StringMap{"flag1": true, "flag2": true},
|
||||
Timezone: "Local",
|
||||
ContinueOnSuccess: true,
|
||||
}
|
||||
if err = rareq.loadFromJsonCfg(json, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rareq) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(rareq))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user