mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Updated dnsagent AsMapINterface method
This commit is contained in:
committed by
Dan Christian Bogos
parent
692e040f67
commit
ff87ae95fe
@@ -137,7 +137,7 @@ func TestDiameterAgentCfgAsMapInterface1(t *testing.T) {
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := cgrCfg.diameterAgentCfg.AsMapInterface(utils.EmptyString); !reflect.DeepEqual(rcv, eMap) {
|
||||
} else if rcv := cgrCfg.diameterAgentCfg.AsMapInterface(cgrCfg.generalCfg.RSRSep); !reflect.DeepEqual(rcv, eMap) {
|
||||
t.Errorf("Expected %+v \n, received %+v", eMap, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ func TestRequestProcessorloadFromJsonCfg(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDNSAgentCfgAsMapInterface(t *testing.T) {
|
||||
var dnsCfg DNSAgentCfg
|
||||
cfgJSONStr := `{
|
||||
"dns_agent": {
|
||||
"enabled": false,
|
||||
@@ -104,29 +103,27 @@ func TestDNSAgentCfgAsMapInterface(t *testing.T) {
|
||||
"listen_net": "udp",
|
||||
"sessions_conns": ["*internal"],
|
||||
"timezone": "",
|
||||
"request_processors": [
|
||||
],
|
||||
"request_processors": [],
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
"enabled": false,
|
||||
"listen": "127.0.0.1:2053",
|
||||
"listen_net": "udp",
|
||||
"sessions_conns": []string{"*internal"},
|
||||
"timezone": "",
|
||||
"request_processors": []map[string]interface{}{},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnDaCfg, err := jsnCfg.DNSAgentJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = dnsCfg.loadFromJsonCfg(jsnDaCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := dnsCfg.AsMapInterface(utils.EmptyString); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
cfgJSONStr = `{
|
||||
utils.EnabledCfg: false,
|
||||
utils.ListenCfg: "127.0.0.1:2053",
|
||||
utils.ListenNetCfg: "udp",
|
||||
utils.SessionSConnsCfg: []string{"*internal"},
|
||||
utils.TimezoneCfg: "",
|
||||
utils.RequestProcessorsCfg: []map[string]interface{}{},
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := cgrCfg.dnsAgentCfg.AsMapInterface(utils.EmptyString); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("Expecetd %+v, received %+v", eMap, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDNSAgentCfgAsMapInterface1(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"dns_agent": {
|
||||
"enabled": false,
|
||||
"listen": "127.0.0.1:2053",
|
||||
@@ -139,8 +136,8 @@ func TestDNSAgentCfgAsMapInterface(t *testing.T) {
|
||||
"filters": ["*string:~*req.request_type:OutboundAUTH","*string:~*req.Msisdn:497700056231"],
|
||||
"tenant": "cgrates.org",
|
||||
"flags": ["*dryrun"],
|
||||
"request_fields":[
|
||||
],
|
||||
"timezone": "UTC",
|
||||
"request_fields":[],
|
||||
"reply_fields":[
|
||||
{"tag": "Allow", "path": "*rep.response.Allow", "type": "*constant",
|
||||
"value": "1", "mandatory": true},
|
||||
@@ -157,38 +154,33 @@ func TestDNSAgentCfgAsMapInterface(t *testing.T) {
|
||||
],
|
||||
},
|
||||
}`
|
||||
eMap = map[string]interface{}{
|
||||
"enabled": false,
|
||||
"listen": "127.0.0.1:2053",
|
||||
"listen_net": "udp",
|
||||
"sessions_conns": []string{"*internal"},
|
||||
"timezone": "UTC",
|
||||
"request_processors": []map[string]interface{}{
|
||||
eMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
utils.ListenCfg: "127.0.0.1:2053",
|
||||
utils.ListenNetCfg: "udp",
|
||||
utils.SessionSConnsCfg: []string{"*internal"},
|
||||
utils.TimezoneCfg: "UTC",
|
||||
utils.RequestProcessorsCfg: []map[string]interface{}{
|
||||
{
|
||||
"id": "OutboundAUTHDryRun",
|
||||
"filters": []string{"*string:~*req.request_type:OutboundAUTH", "*string:~*req.Msisdn:497700056231"},
|
||||
"tenant": "cgrates.org",
|
||||
"flags": []string{"*dryrun"},
|
||||
"Timezone": "",
|
||||
"request_fields": []map[string]interface{}{},
|
||||
"reply_fields": []map[string]interface{}{
|
||||
{"tag": "Allow", "path": "*rep.response.Allow", "type": "*constant", "value": "1", "mandatory": true},
|
||||
{"tag": "Concatenated1", "path": "*rep.response.Concatenated", "type": "*composed", "value": "~*req.MCC;/", "mandatory": true},
|
||||
{"tag": "Concatenated2", "path": "*rep.response.Concatenated", "type": "*composed", "value": "Val1"},
|
||||
{"tag": "MaxDuration", "path": "*rep.response.MaxDuration", "type": "*constant", "value": "1200", "blocker": true},
|
||||
{"tag": "Unused", "path": "*rep.response.Unused", "type": "*constant", "value": "0"},
|
||||
utils.IdCfg: "OutboundAUTHDryRun",
|
||||
utils.FilterSCfg: []string{"*string:~*req.request_type:OutboundAUTH", "*string:~*req.Msisdn:497700056231"},
|
||||
utils.TenantCfg: "cgrates.org",
|
||||
utils.FlagsCfg: []string{"*dryrun"},
|
||||
utils.TimezoneCfg: "UTC",
|
||||
utils.RequestFieldsCfg: []map[string]interface{}{},
|
||||
utils.ReplyFieldsCfg: []map[string]interface{}{
|
||||
{utils.TagCfg: "Allow", utils.PathCfg: "*rep.response.Allow", utils.TypeCfg: "*constant", utils.ValueCfg: "1", utils.MandatoryCfg: true},
|
||||
{utils.TagCfg: "Concatenated1", utils.PathCfg: "*rep.response.Concatenated", utils.TypeCfg: "*composed", utils.ValueCfg: "~*req.MCC;/", utils.MandatoryCfg: true},
|
||||
{utils.TagCfg: "Concatenated2", utils.PathCfg: "*rep.response.Concatenated", utils.TypeCfg: "*composed", utils.ValueCfg: "Val1"},
|
||||
{utils.TagCfg: "MaxDuration", utils.PathCfg: "*rep.response.MaxDuration", utils.TypeCfg: "*constant", utils.ValueCfg: "1200", utils.BlockerCfg: true},
|
||||
{utils.TagCfg: "Unused", utils.PathCfg: "*rep.response.Unused", utils.TypeCfg: "*constant", utils.ValueCfg: "0"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnDaCfg, err := jsnCfg.DNSAgentJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = dnsCfg.loadFromJsonCfg(jsnDaCfg, utils.INFIELD_SEP); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := dnsCfg.AsMapInterface(";"); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
} else if rcv := cgrCfg.dnsAgentCfg.AsMapInterface(cgrCfg.generalCfg.RSRSep); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("Expecetd %+v \n, received %+v", utils.ToIJSON(eMap), utils.ToIJSON(rcv))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -82,30 +82,32 @@ func (da *DNSAgentCfg) loadFromJsonCfg(jsnCfg *DNSAgentJsonCfg, sep string) (err
|
||||
return
|
||||
}
|
||||
|
||||
func (da *DNSAgentCfg) AsMapInterface(separator string) map[string]interface{} {
|
||||
func (da *DNSAgentCfg) AsMapInterface(separator string) (initialMP map[string]interface{}) {
|
||||
initialMP = map[string]interface{}{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.ListenCfg: da.Listen,
|
||||
utils.ListenNetCfg: da.ListenNet,
|
||||
utils.TimezoneCfg: da.Timezone,
|
||||
}
|
||||
|
||||
requestProcessors := make([]map[string]interface{}, len(da.RequestProcessors))
|
||||
for i, item := range da.RequestProcessors {
|
||||
requestProcessors[i] = item.AsMapInterface(separator)
|
||||
}
|
||||
sessionSConns := make([]string, len(da.SessionSConns))
|
||||
for i, item := range da.SessionSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS)
|
||||
if item == buf {
|
||||
sessionSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaSessionS, utils.EmptyString)
|
||||
} else {
|
||||
sessionSConns[i] = item
|
||||
initialMP[utils.RequestProcessorsCfg] = requestProcessors
|
||||
|
||||
if da.SessionSConns != nil {
|
||||
sessionSConns := make([]string, len(da.SessionSConns))
|
||||
for i, item := range da.SessionSConns {
|
||||
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) {
|
||||
sessionSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaSessionS, utils.EmptyString)
|
||||
} else {
|
||||
sessionSConns[i] = item
|
||||
}
|
||||
}
|
||||
initialMP[utils.SessionSConnsCfg] = sessionSConns
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.ListenCfg: da.Listen,
|
||||
utils.ListenNetCfg: da.ListenNet,
|
||||
utils.SessionSConnsCfg: sessionSConns,
|
||||
utils.TimezoneCfg: da.Timezone,
|
||||
utils.RequestProcessorsCfg: requestProcessors,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// RequestProcessor is the request processor configuration
|
||||
@@ -156,33 +158,37 @@ func (rp *RequestProcessor) loadFromJsonCfg(jsnCfg *ReqProcessorJsnCfg, sep stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rp *RequestProcessor) AsMapInterface(separator string) map[string]interface{} {
|
||||
replyFields := make([]map[string]interface{}, len(rp.ReplyFields))
|
||||
for i, item := range rp.ReplyFields {
|
||||
replyFields[i] = item.AsMapInterface(separator)
|
||||
func (rp *RequestProcessor) AsMapInterface(separator string) (initialMP map[string]interface{}) {
|
||||
initialMP = map[string]interface{}{
|
||||
utils.IDCfg: rp.ID,
|
||||
utils.FiltersCfg: rp.Filters,
|
||||
utils.FlagsCfg: rp.Flags.SliceFlags(),
|
||||
utils.TimezoneCfg: rp.Timezone,
|
||||
}
|
||||
|
||||
requestFields := make([]map[string]interface{}, len(rp.RequestFields))
|
||||
for i, item := range rp.RequestFields {
|
||||
requestFields[i] = item.AsMapInterface(separator)
|
||||
}
|
||||
var tenant string
|
||||
if rp.Tenant != nil {
|
||||
values := make([]string, len(rp.Tenant))
|
||||
for i, item := range rp.Tenant {
|
||||
values[i] = item.Rules
|
||||
var tenant string
|
||||
if rp.Tenant != nil {
|
||||
values := make([]string, len(rp.Tenant))
|
||||
for i, item := range rp.Tenant {
|
||||
values[i] = item.Rules
|
||||
}
|
||||
tenant = strings.Join(values, separator)
|
||||
}
|
||||
tenant = strings.Join(values, separator)
|
||||
initialMP[utils.TenantCfg] = tenant
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
utils.IDCfg: rp.ID,
|
||||
utils.TenantCfg: tenant,
|
||||
utils.FiltersCfg: rp.Filters,
|
||||
utils.FlagsCfg: rp.Flags.SliceFlags(),
|
||||
utils.TimezoneCfgC: rp.Timezone,
|
||||
utils.RequestFieldsCfg: requestFields,
|
||||
utils.ReplyFieldsCfg: replyFields,
|
||||
if rp.RequestFields != nil {
|
||||
requestFields := make([]map[string]interface{}, len(rp.RequestFields))
|
||||
for i, item := range rp.RequestFields {
|
||||
requestFields[i] = item.AsMapInterface(separator)
|
||||
}
|
||||
initialMP[utils.RequestFieldsCfg] = requestFields
|
||||
}
|
||||
|
||||
if rp.ReplyFields != nil {
|
||||
replyFields := make([]map[string]interface{}, len(rp.ReplyFields))
|
||||
for i, item := range rp.ReplyFields {
|
||||
replyFields[i] = item.AsMapInterface(separator)
|
||||
}
|
||||
initialMP[utils.ReplyFieldsCfg] = replyFields
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user