mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
Refactoring CDRE and CDRC configurations and functionality
This commit is contained in:
@@ -76,6 +76,7 @@ const (
|
||||
FALLBACK_SEP = ';'
|
||||
INFIELD_SEP = ";"
|
||||
FIELDS_SEP = ","
|
||||
STATIC_HDRVAL_SEP = "::"
|
||||
REGEXP_PREFIX = "~"
|
||||
JSON = "json"
|
||||
GOB = "gob"
|
||||
@@ -105,6 +106,7 @@ const (
|
||||
STATIC_VALUE_PREFIX = "^"
|
||||
CSV = "csv"
|
||||
CDRE_DRYRUN = "dry_run"
|
||||
COMBIMED = "combimed"
|
||||
INTERNAL = "internal"
|
||||
ZERO_RATING_SUBJECT_PREFIX = "*zero"
|
||||
OK = "OK"
|
||||
@@ -159,6 +161,10 @@ const (
|
||||
CREATE_TARIFFPLAN_TABLES_SQL = "create_tariffplan_tables.sql"
|
||||
TEST_SQL = "TEST_SQL"
|
||||
EMPTY = "_empty_"
|
||||
CONSTANT = "constant"
|
||||
FILLER = "filler"
|
||||
METATAG = "metatag"
|
||||
HTTP_POST = "http_post"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -315,3 +315,12 @@ func Unzip(src, dest string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Utilities to provide pointers where we need to define ad-hoc
|
||||
func StringPointer(str string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
func IntPointer(i int) *int {
|
||||
return &i
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ func NewRSRField(fldStr string) (*RSRField, error) {
|
||||
}
|
||||
if strings.HasPrefix(fldStr, STATIC_VALUE_PREFIX) { // Special case when RSR is defined as static header/value
|
||||
var staticHdr, staticVal string
|
||||
if splt := strings.Split(fldStr, "/"); len(splt) == 3 { // Using / as separator since ':' is often use in date/time fields
|
||||
if len(splt[2]) != 0 { // Last split has created empty element
|
||||
return nil, fmt.Errorf("Invalid static header/value combination: %s", fldStr)
|
||||
}
|
||||
if splt := strings.Split(fldStr, STATIC_HDRVAL_SEP); len(splt) == 2 { // Using / as separator since ':' is often use in date/time fields
|
||||
staticHdr, staticVal = splt[0][1:], splt[1] // Strip the / suffix
|
||||
} else if len(splt) == 2 {
|
||||
if strings.HasSuffix(staticVal, "/") { // If value ends with /, strip it since it is a part of the definition syntax
|
||||
staticVal = staticVal[:len(staticVal)-1]
|
||||
}
|
||||
} else if len(splt) > 2 {
|
||||
return nil, fmt.Errorf("Invalid RSRField string: %s", fldStr)
|
||||
} else {
|
||||
staticHdr, staticVal = splt[0][1:], splt[0][1:] // If no split, header will remain as original, value as header without the prefix
|
||||
@@ -102,13 +102,13 @@ func (rsrf *RSRField) RegexpMatched() bool { // Investigate whether we had a reg
|
||||
}
|
||||
|
||||
// Parses list of RSRFields, used for example as multiple filters in derived charging
|
||||
func ParseRSRFields(fldsStr, sep string) ([]*RSRField, error) {
|
||||
func ParseRSRFields(fldsStr, sep string) (RSRFields, error) {
|
||||
//rsrRlsPattern := regexp.MustCompile(`^(~\w+:s/.+/.*/)|(\^.+(/.+/)?)(;(~\w+:s/.+/.*/)|(\^.+(/.+/)?))*$`) //ToDo:Fix here rule able to confirm the content
|
||||
if len(fldsStr) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
rulesSplt := strings.Split(fldsStr, sep)
|
||||
rsrFields := make([]*RSRField, len(rulesSplt))
|
||||
rsrFields := make(RSRFields, len(rulesSplt))
|
||||
for idx, ruleStr := range rulesSplt {
|
||||
if rsrField, err := NewRSRField(ruleStr); err != nil {
|
||||
return nil, err
|
||||
@@ -118,3 +118,5 @@ func ParseRSRFields(fldsStr, sep string) ([]*RSRField, error) {
|
||||
}
|
||||
return rsrFields, nil
|
||||
}
|
||||
|
||||
type RSRFields []*RSRField
|
||||
|
||||
@@ -89,7 +89,7 @@ func TestConvertPlusNationalAnd00(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRSRParseStatic(t *testing.T) {
|
||||
if rsrField, err := NewRSRField("^static_header/static_value/"); err != nil {
|
||||
if rsrField, err := NewRSRField("^static_header::static_value/"); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rsrField, &RSRField{Id: "static_header", staticValue: "static_value"}) {
|
||||
t.Errorf("Unexpected RSRField received: %v", rsrField)
|
||||
@@ -150,14 +150,14 @@ func TestParseRSRFields(t *testing.T) {
|
||||
rsrFld2, _ := NewRSRField(`~subject:s/^0\d{9}$//`)
|
||||
rsrFld3, _ := NewRSRField(`^destination/+4912345/`)
|
||||
rsrFld4, _ := NewRSRField(`~mediation_runid:s/^default$/default/`)
|
||||
eRSRFields := []*RSRField{rsrFld1, rsrFld2, rsrFld3, rsrFld4}
|
||||
eRSRFields := RSRFields{rsrFld1, rsrFld2, rsrFld3, rsrFld4}
|
||||
if rsrFlds, err := ParseRSRFields(fieldsStr1, INFIELD_SEP); err != nil {
|
||||
t.Error("Unexpected error: ", err)
|
||||
} else if !reflect.DeepEqual(eRSRFields, rsrFlds) {
|
||||
t.Errorf("Expecting: %v, received: %v", eRSRFields, rsrFlds)
|
||||
}
|
||||
fields := `host,~sip_redirected_to:s/sip:\+49(\d+)@/0$1/,destination`
|
||||
expectParsedFields := []*RSRField{
|
||||
expectParsedFields := RSRFields{
|
||||
&RSRField{Id: "host"},
|
||||
&RSRField{Id: "sip_redirected_to",
|
||||
RSRules: []*ReSearchReplace{&ReSearchReplace{SearchRegexp: regexp.MustCompile(`sip:\+49(\d+)@`), ReplaceTemplate: "0$1"}}},
|
||||
|
||||
@@ -112,7 +112,7 @@ func TestPassesFieldFilter(t *testing.T) {
|
||||
if pass, _ := cdr.PassesFieldFilter(acntPrefxFltr); pass {
|
||||
t.Error("Passing filter")
|
||||
}
|
||||
torFltr, _ := NewRSRField(`^tor/*voice/`)
|
||||
torFltr, _ := NewRSRField(`^tor::*voice/`)
|
||||
if pass, _ := cdr.PassesFieldFilter(torFltr); !pass {
|
||||
t.Error("Not passing filter")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user