diff --git a/agents/astagent.go b/agents/astagent.go index 84663accf..f269ebf6f 100644 --- a/agents/astagent.go +++ b/agents/astagent.go @@ -179,6 +179,7 @@ func (sma *AsteriskAgent) handleStasisStart(ev *SMAsteriskEvent) { } if authReply.Attributes != nil { for _, fldName := range authReply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if _, has := authReply.Attributes.CGREvent.Event[fldName]; !has { continue //maybe removed } diff --git a/agents/diamagent_test.go b/agents/diamagent_test.go index 2d678e492..5e89f7d65 100644 --- a/agents/diamagent_test.go +++ b/agents/diamagent_test.go @@ -182,7 +182,7 @@ func TestProcessRequest(t *testing.T) { *prply = sessions.V1InitSessionReply{ Attributes: &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_SESSIONAUTH"}, - AlteredFields: []string{"Password", "PaypalAccount", "RequestType", "LCRProfile"}, + AlteredFields: []string{"*req.Password", "*req.PaypalAccount", "*req.RequestType", "*req.LCRProfile"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "e7d35bf", @@ -274,7 +274,7 @@ func TestProcessRequest(t *testing.T) { *prply = sessions.V1UpdateSessionReply{ Attributes: &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_SESSIONAUTH"}, - AlteredFields: []string{"Password", "PaypalAccount", "RequestType", "LCRProfile"}, + AlteredFields: []string{"*req.Password", "*req.PaypalAccount", "*req.RequestType", "*req.LCRProfile"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "e7d35bf", @@ -464,7 +464,7 @@ func TestProcessRequest(t *testing.T) { *prply = sessions.V1ProcessMessageReply{ Attributes: &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_SESSIONAUTH"}, - AlteredFields: []string{"Password", "PaypalAccount", "RequestType", "LCRProfile"}, + AlteredFields: []string{"*req.Password", "*req.PaypalAccount", "*req.RequestType", "*req.LCRProfile"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "e7d35bf", diff --git a/agents/fsagent.go b/agents/fsagent.go index 587cb6a77..ee55c92e2 100644 --- a/agents/fsagent.go +++ b/agents/fsagent.go @@ -155,6 +155,7 @@ func (sm *FSsessions) onChannelPark(fsev FSEvent, connIdx int) { } if authReply.Attributes != nil { for _, fldName := range authReply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if _, has := authReply.Attributes.CGREvent.Event[fldName]; !has { continue //maybe removed } diff --git a/agents/kamevent_test.go b/agents/kamevent_test.go index d1065d069..97c548ac1 100644 --- a/agents/kamevent_test.go +++ b/agents/kamevent_test.go @@ -243,7 +243,7 @@ func TestKamEvAsKamAuthReply(t *testing.T) { authRply = &sessions.V1AuthorizeReply{ Attributes: &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_ACCOUNT_PROFILE"}, - AlteredFields: []string{"Password", utils.RequestType}, + AlteredFields: []string{"*req.Password", utils.MetaReq + utils.NestingSep + utils.RequestType}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestKamEvAsKamAuthReply", @@ -430,7 +430,7 @@ func TestKamEvAsKamProcessEventReply(t *testing.T) { procEvhRply = &sessions.V1ProcessMessageReply{ Attributes: &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_ACCOUNT_PROFILE"}, - AlteredFields: []string{"Password", utils.RequestType}, + AlteredFields: []string{"*req.Password", utils.MetaReq + utils.NestingSep + utils.RequestType}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestKamEvAsKamAuthReply", diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index bee3adf54..9a6087840 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -151,7 +151,7 @@ func testAPIerVerifyAttributesAfterLoad(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{}, - FieldName: "Password", + Path: utils.MetaReq + utils.NestingSep + "Password", Type: utils.META_CONSTANT, Value: config.NewRSRParsersMustCompile("CGRateS.org", true, utils.INFIELD_SEP), }, diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index d44f08cd0..eb601e74b 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -188,12 +188,12 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)}, Attributes: []*engine.Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 10.0, @@ -240,8 +240,8 @@ func testAttributeSGetAttributeForEventNotFound(t *testing.T) { ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)}, Attributes: []*engine.Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 10.0, @@ -292,8 +292,8 @@ func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) { ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)}, Attributes: []*engine.Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 10.0, @@ -340,7 +340,8 @@ func testAttributeSProcessEvent(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{utils.Subject, utils.Account}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.Subject, + utils.MetaReq + utils.NestingSep + utils.Account}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -353,7 +354,8 @@ func testAttributeSProcessEvent(t *testing.T) { } eRply2 := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{utils.Account, utils.Subject}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.Account, + utils.MetaReq + utils.NestingSep + utils.Subject}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -441,12 +443,12 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1008"}, - FieldName: utils.Account, + Path: utils.MetaReq + utils.NestingSep + utils.Account, Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -461,7 +463,8 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"AttributeWithNonSubstitute"}, - AlteredFields: []string{utils.Account, utils.Subject}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.Account, + utils.MetaReq + utils.NestingSep + utils.Subject}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -508,12 +511,12 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1008"}, - FieldName: utils.Account, + Path: utils.MetaReq + utils.NestingSep + utils.Account, Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -527,7 +530,7 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"AttributeWithNonSubstitute"}, - AlteredFields: []string{"Account", "Subject"}, + AlteredFields: []string{"*req.Account", "*req.Subject"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -539,7 +542,8 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { } eRply2 := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"AttributeWithNonSubstitute"}, - AlteredFields: []string{utils.Subject, utils.Account}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.Subject, + utils.MetaReq + utils.NestingSep + utils.Account}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -586,12 +590,12 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1008"}, - FieldName: utils.Account, + Path: utils.MetaReq + utils.NestingSep + utils.Account, Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { FilterIDs: []string{"*string:~*req.Subject:1008"}, - FieldName: utils.Subject, + Path: utils.MetaReq + utils.NestingSep + utils.Subject, Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), }, }, @@ -606,7 +610,7 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"AttributeWithNonSubstitute"}, - AlteredFields: []string{"Account"}, + AlteredFields: []string{"*req.Account"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -639,8 +643,8 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("~Field1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("~*req.Field1", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -666,7 +670,7 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_Header"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{"*req.Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "HeaderEventForAttribute", @@ -721,8 +725,8 @@ func testAttributeSSetAlsPrf(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "FL1", - Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FL1", + Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -749,12 +753,12 @@ func testAttributeSSetAlsPrf(t *testing.T) { func testAttributeSUpdateAlsPrf(t *testing.T) { alsPrf.Attributes = []*engine.Attribute{ { - FieldName: "FL1", - Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FL1", + Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, { - FieldName: "FL2", - Value: config.NewRSRParsersMustCompile("Al2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FL2", + Value: config.NewRSRParsersMustCompile("Al2", true, utils.INFIELD_SEP), }, } alsPrf.Compile() @@ -814,7 +818,7 @@ func testAttributeSSetAlsPrf2(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, + Path: utils.MetaReq + utils.NestingSep + utils.Subject, Value: config.RSRParsers{ &config.RSRParser{ Rules: "roam", @@ -858,7 +862,7 @@ func testAttributeSSetAlsPrf3(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, + Path: utils.MetaReq + utils.NestingSep + utils.Subject, Value: config.RSRParsers{ &config.RSRParser{ Rules: "", @@ -889,7 +893,7 @@ func testAttributeSSetAlsPrf4(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, + Path: utils.MetaReq + utils.NestingSep + utils.Subject, Value: config.RSRParsers{ &config.RSRParser{}, }, @@ -926,8 +930,8 @@ func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Category", - Value: config.NewRSRParsersMustCompile("~Category:s/(.*)/${1}_suffix/", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Category", + Value: config.NewRSRParsersMustCompile("~*req.Category:s/(.*)/${1}_suffix/", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -953,7 +957,7 @@ func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_Search_and_replace"}, - AlteredFields: []string{"Category"}, + AlteredFields: []string{"*req.Category"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "HeaderEventForAttribute", @@ -984,8 +988,8 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1002,8 +1006,8 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1020,8 +1024,8 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -1057,7 +1061,7 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, - AlteredFields: []string{"Field1", "Field2"}, + AlteredFields: []string{"*req.Field1", "*req.Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1094,8 +1098,8 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1112,8 +1116,8 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1130,8 +1134,8 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -1167,7 +1171,7 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_3"}, - AlteredFields: []string{"Field1", "Field2", "Field3"}, + AlteredFields: []string{"*req.Field1", "*req.Field2", "*req.Field3"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1213,8 +1217,8 @@ func testAttributeSCachingMetaNone(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1272,8 +1276,8 @@ func testAttributeSCachingMetaLoad(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1364,8 +1368,8 @@ func testAttributeSCachingMetaReload1(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1423,8 +1427,8 @@ func testAttributeSCachingMetaReload2(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1463,8 +1467,8 @@ func testAttributeSCachingMetaReload2(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1502,8 +1506,8 @@ func testAttributeSCachingMetaRemove(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -1552,8 +1556,8 @@ func testAttributeSCachingMetaRemove(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, diff --git a/apier/v1/cdre_it_test.go b/apier/v1/cdre_it_test.go index 852668e80..0049e36eb 100755 --- a/apier/v1/cdre_it_test.go +++ b/apier/v1/cdre_it_test.go @@ -291,12 +291,12 @@ func testCDReAddAttributes(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("ATTR_SUBJECT", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("ATTR_SUBJECT", true, utils.INFIELD_SEP), }, { - FieldName: utils.Category, - Value: config.NewRSRParsersMustCompile("ATTR_CATEGORY", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Category, + Value: config.NewRSRParsersMustCompile("ATTR_CATEGORY", true, utils.INFIELD_SEP), }, }, Weight: 20, diff --git a/apier/v1/chargers_it_test.go b/apier/v1/chargers_it_test.go index 8b16f77af..0d9cd8194 100755 --- a/apier/v1/chargers_it_test.go +++ b/apier/v1/chargers_it_test.go @@ -166,7 +166,7 @@ func testChargerSLoadAddCharger(t *testing.T) { Contexts: []string{"simpleauth"}, Attributes: []*engine.Attribute{ { - FieldName: "Password", + Path: utils.MetaReq + utils.NestingSep + "Password", Value: config.RSRParsers{ &config.RSRParser{ Rules: "CGRateS.org", @@ -217,7 +217,7 @@ func testChargerSProcessEvent(t *testing.T) { { ChargerSProfile: "Charger1", AttributeSProfiles: []string{"ATTR_1001_SIMPLEAUTH"}, - AlteredFields: []string{"Password"}, + AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ // matching Charger1 Tenant: "cgrates.org", ID: "event1", diff --git a/apier/v1/dm_remote_it_test.go b/apier/v1/dm_remote_it_test.go index 02562ebfd..aa6a9ee38 100644 --- a/apier/v1/dm_remote_it_test.go +++ b/apier/v1/dm_remote_it_test.go @@ -239,7 +239,7 @@ func testInternalRemoteITGetAttribute(t *testing.T) { Attributes: []*engine.Attribute{ { - FieldName: "Password", + Path: utils.MetaReq + utils.NestingSep + "Password", FilterIDs: []string{}, Type: utils.META_CONSTANT, Value: config.NewRSRParsersMustCompile("CGRateS.org", true, utils.INFIELD_SEP), @@ -463,9 +463,9 @@ func testInternalRemoteITGetFilter(t *testing.T) { ID: "FLTR_ACNT_1001", Rules: []*engine.FilterRule{ { - Type: "*string", - FieldName: "~*req.Account", - Values: []string{"1001"}, + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{"1001"}, }, }, ActivationInterval: &utils.ActivationInterval{ diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go index 86ba9e370..06083d158 100644 --- a/apier/v1/filter_indexes.go +++ b/apier/v1/filter_indexes.go @@ -492,9 +492,9 @@ func (api *ApierV1) computeThresholdIndexes(tenant string, thIDs *[]string, ID: th.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -562,9 +562,9 @@ func (api *ApierV1) computeAttributeIndexes(tenant, context string, attrIDs *[]s ID: ap.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -628,9 +628,9 @@ func (api *ApierV1) computeResourceIndexes(tenant string, rsIDs *[]string, ID: rp.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -694,9 +694,9 @@ func (api *ApierV1) computeStatIndexes(tenant string, stIDs *[]string, ID: sqp.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -760,9 +760,9 @@ func (api *ApierV1) computeSupplierIndexes(tenant string, sppIDs *[]string, ID: spp.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -826,9 +826,9 @@ func (api *ApierV1) computeChargerIndexes(tenant string, cppIDs *[]string, ID: cpp.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -896,9 +896,9 @@ func (api *ApierV1) computeDispatcherIndexes(tenant, context string, dspIDs *[]s ID: dsp.ID, Rules: []*engine.FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index 4067bd642..8eb9853d4 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -158,9 +158,9 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { Tenant: tenant, ID: "TestFilter", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -252,9 +252,9 @@ func testV1FIdxSetSecondThresholdProfile(t *testing.T) { Tenant: tenant, ID: "TestFilter2", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1002"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1002"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -417,9 +417,9 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_1", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -520,9 +520,9 @@ func testV1FIdxSetSecondStatQueueProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_2", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -666,9 +666,9 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_RES_RCFG1", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -759,9 +759,9 @@ func testV1FIdxSetSecondResourceProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_2", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -895,9 +895,9 @@ func testV1FIdxSetSupplierProfileIndexes(t *testing.T) { ID: "FLTR_1", Rules: []*engine.FilterRule{ { - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -994,9 +994,9 @@ func testV1FIdxSetSecondSupplierProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_2", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -1137,9 +1137,9 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_1", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -1171,7 +1171,7 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.FL1:In1"}, - FieldName: "FL1", + Path: "FL1", Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, }, @@ -1245,9 +1245,9 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { Tenant: tenant, ID: "FLTR_2", Rules: []*engine.FilterRule{{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), @@ -1279,7 +1279,7 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { }, Attributes: []*engine.Attribute{{ FilterIDs: []string{"*string:~*req.FL1:In1"}, - FieldName: "FL1", + Path: "FL1", Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }}, Weight: 20, diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 0d450f575..c0b01503c 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -163,14 +163,14 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { ID: "TestFilter", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1001"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1001"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, - Type: "*string", - Values: []string{utils.BalanceUpdate}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, + Type: utils.MetaString, + Values: []string{utils.BalanceUpdate}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -257,14 +257,14 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { ID: "TestFilter2", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1002"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1002"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, - Type: "*string", - Values: []string{utils.AccountUpdate}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, + Type: utils.MetaString, + Values: []string{utils.AccountUpdate}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -337,14 +337,14 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { ID: "TestFilter3", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1003"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1003"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, - Type: "*string", - Values: []string{utils.BalanceUpdate}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, + Type: utils.MetaString, + Values: []string{utils.BalanceUpdate}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -500,14 +500,14 @@ func testV1FIdxCaSetStatQueueProfile(t *testing.T) { ID: "FLTR_1", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1001"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1001"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, - Type: "*string", - Values: []string{utils.AccountUpdate}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, + Type: utils.MetaString, + Values: []string{utils.AccountUpdate}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -654,14 +654,14 @@ func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) { ID: "FLTR_2", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1003"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1003"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, - Type: "*string", - Values: []string{utils.BalanceUpdate}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, + Type: utils.MetaString, + Values: []string{utils.BalanceUpdate}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -729,14 +729,14 @@ func testV1FIdxCaUpdateStatQueueProfileFromTP(t *testing.T) { ID: "FLTR_3", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1003"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1003"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, - Type: "*string", - Values: []string{utils.AccountUpdate}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType, + Type: utils.MetaString, + Values: []string{utils.AccountUpdate}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -890,14 +890,14 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { ID: "TestFilter", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1009"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1009"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Type: "*string", - Values: []string{"+491511231234"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaString, + Values: []string{"+491511231234"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -922,12 +922,12 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -983,14 +983,14 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { ID: "TestFilter2", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"2009"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"2009"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Type: "*string", - Values: []string{"+492511231234"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaString, + Values: []string{"+492511231234"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1015,12 +1015,12 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1056,14 +1056,14 @@ func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) { ID: "TestFilter3", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"3009"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"3009"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Type: "*string", - Values: []string{"+492511231234"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaString, + Values: []string{"+492511231234"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1209,19 +1209,19 @@ func testV1FIdxCaSetResourceProfile(t *testing.T) { ID: "FLTR_RES_RCFG1", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1001"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1001"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject, - Type: "*string", - Values: []string{"1002"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaString, + Values: []string{"1002"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Type: "*string", - Values: []string{"1001"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaString, + Values: []string{"1001"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1338,19 +1338,19 @@ func testV1FIdxCaUpdateResourceProfile(t *testing.T) { ID: "FLTR_RES_RCFG2", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"2002"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"2002"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject, - Type: "*string", - Values: []string{"2001"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaString, + Values: []string{"2001"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Type: "*string", - Values: []string{"2002"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaString, + Values: []string{"2002"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1414,19 +1414,19 @@ func testV1FIdxCaUpdateResourceProfileFromTP(t *testing.T) { ID: "FLTR_RES_RCFG3", Rules: []*engine.FilterRule{ { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Type: "*string", - Values: []string{"1002"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaString, + Values: []string{"1002"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject, - Type: "*string", - Values: []string{"1001"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaString, + Values: []string{"1001"}, }, { - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Type: "*string", - Values: []string{"1002"}, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaString, + Values: []string{"1002"}, }, }, ActivationInterval: &utils.ActivationInterval{ diff --git a/apier/v1/filters_it_test.go b/apier/v1/filters_it_test.go index 2937499db..c765c4f40 100644 --- a/apier/v1/filters_it_test.go +++ b/apier/v1/filters_it_test.go @@ -125,9 +125,9 @@ func testFilterSetFilter(t *testing.T) { ID: "Filter1", Rules: []*engine.FilterRule{ { - FieldName: "*string", - Type: "~Account", - Values: []string{"1001", "1002"}, + Element: utils.MetaString, + Type: "~Account", + Values: []string{"1001", "1002"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -167,14 +167,14 @@ func testFilterGetFilterAfterSet(t *testing.T) { func testFilterUpdateFilter(t *testing.T) { filter.Rules = []*engine.FilterRule{ { - FieldName: utils.MetaString, - Type: "~Account", - Values: []string{"1001", "1002"}, + Element: utils.MetaString, + Type: "~Account", + Values: []string{"1001", "1002"}, }, { - FieldName: utils.MetaPrefix, - Type: "~Destination", - Values: []string{"10", "20"}, + Element: utils.MetaPrefix, + Type: "~Destination", + Values: []string{"10", "20"}, }, } var result string diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go index 1a1638243..aa73ff037 100644 --- a/apier/v1/sessions_process_event_it_test.go +++ b/apier/v1/sessions_process_event_it_test.go @@ -202,7 +202,7 @@ func testSSv1ItProcessEventAuth(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventAuth", @@ -264,7 +264,7 @@ func testSSv1ItProcessEventInitiateSession(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventInitiateSession", @@ -323,7 +323,7 @@ func testSSv1ItProcessEventUpdateSession(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventUpdateSession", diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 0b9fe5720..ccf482941 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -254,7 +254,7 @@ func testSSv1ItAuth(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItAuth", @@ -363,7 +363,7 @@ func testSSv1ItInitiateSession(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItInitiateSession", @@ -473,7 +473,7 @@ func testSSv1ItUpdateSession(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItUpdateSession", @@ -617,7 +617,7 @@ func testSSv1ItProcessEvent(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItProcessEvent", @@ -772,7 +772,7 @@ func testSSv1ItForceUpdateSession(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItUpdateSession", diff --git a/apier/v1/stats_it_test.go b/apier/v1/stats_it_test.go index 97d410af3..1599df60b 100644 --- a/apier/v1/stats_it_test.go +++ b/apier/v1/stats_it_test.go @@ -340,9 +340,9 @@ func testV1STSSetStatQueueProfile(t *testing.T) { ID: "FLTR_1", Rules: []*engine.FilterRule{ { - FieldName: "~*req.Account", - Type: "*string", - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -420,9 +420,9 @@ func testV1STSUpdateStatQueueProfile(t *testing.T) { ID: "FLTR_2", Rules: []*engine.FilterRule{ { - FieldName: "~*req.Account", - Type: "*string", - Values: []string{"1001"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001"}, }, }, ActivationInterval: &utils.ActivationInterval{ diff --git a/apier/v1/tpattributes_it_test.go b/apier/v1/tpattributes_it_test.go index 8c42b1740..1155cd844 100644 --- a/apier/v1/tpattributes_it_test.go +++ b/apier/v1/tpattributes_it_test.go @@ -138,7 +138,7 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) { Contexts: []string{"con1"}, Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", FilterIDs: []string{}, }, @@ -180,12 +180,12 @@ func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) { func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) { tpAlsPrf.Attributes = []*utils.TPAttribute{ &utils.TPAttribute{ - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", FilterIDs: []string{}, }, &utils.TPAttribute{ - FieldName: "FL2", + Path: utils.MetaReq + utils.NestingSep + "FL2", Value: "Al2", FilterIDs: []string{}, }, @@ -212,12 +212,12 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { Contexts: []string{"con1"}, Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ - FieldName: "FL2", + Path: utils.MetaReq + utils.NestingSep + "FL2", Value: "Al2", FilterIDs: []string{}, }, &utils.TPAttribute{ - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", FilterIDs: []string{}, }, @@ -226,7 +226,7 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { } sort.Strings(revTPAlsPrf.FilterIDs) sort.Slice(revTPAlsPrf.Attributes, func(i, j int) bool { - return strings.Compare(revTPAlsPrf.Attributes[i].FieldName, revTPAlsPrf.Attributes[j].FieldName) == -1 + return strings.Compare(revTPAlsPrf.Attributes[i].Path, revTPAlsPrf.Attributes[j].Path) == -1 }) if err := tpAlsPrfRPC.Call(utils.ApierV1GetTPAttributeProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err != nil { @@ -234,7 +234,7 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { } sort.Strings(reply.FilterIDs) sort.Slice(reply.Attributes, func(i, j int) bool { - return strings.Compare(reply.Attributes[i].FieldName, reply.Attributes[j].FieldName) == -1 + return strings.Compare(reply.Attributes[i].Path, reply.Attributes[j].Path) == -1 }) if !reflect.DeepEqual(tpAlsPrf, reply) && !reflect.DeepEqual(revTPAlsPrf, reply) { t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpAlsPrf), utils.ToJSON(reply)) diff --git a/apier/v1/tpfilters_it_test.go b/apier/v1/tpfilters_it_test.go index 2bea05161..69d696913 100644 --- a/apier/v1/tpfilters_it_test.go +++ b/apier/v1/tpfilters_it_test.go @@ -141,9 +141,9 @@ func testTPFilterSetTPFilter(t *testing.T) { ID: "Filter", Filters: []*utils.TPFilter{ &utils.TPFilter{ - Type: utils.MetaString, - FieldName: "Account", - Values: []string{"1001", "1002"}, + Type: utils.MetaString, + Element: "Account", + Values: []string{"1001", "1002"}, }, }, ActivationInterval: &utils.TPActivationInterval{ @@ -187,20 +187,20 @@ func testTPFilterGetFilterIds(t *testing.T) { func testTPFilterUpdateTPFilter(t *testing.T) { tpFilter.Filters = []*utils.TPFilter{ &utils.TPFilter{ - Type: utils.MetaString, - FieldName: "Account", - Values: []string{"1001", "1002"}, + Type: utils.MetaString, + Element: "Account", + Values: []string{"1001", "1002"}, }, &utils.TPFilter{ - Type: utils.MetaPrefix, - FieldName: "Destination", - Values: []string{"10", "20"}, + Type: utils.MetaPrefix, + Element: "Destination", + Values: []string{"10", "20"}, }, } sort.Slice(tpFilter.Filters, func(i, j int) bool { sort.Strings(tpFilter.Filters[i].Values) sort.Strings(tpFilter.Filters[j].Values) - return strings.Compare(tpFilter.Filters[i].FieldName, tpFilter.Filters[j].FieldName) == -1 + return strings.Compare(tpFilter.Filters[i].Element, tpFilter.Filters[j].Element) == -1 }) var result string if err := tpFilterRPC.Call(utils.ApierV1SetTPFilterProfile, tpFilter, &result); err != nil { @@ -219,7 +219,7 @@ func testTPFilterGetTPFilterAfterUpdate(t *testing.T) { sort.Slice(reply.Filters, func(i, j int) bool { sort.Strings(reply.Filters[i].Values) sort.Strings(reply.Filters[j].Values) - return strings.Compare(reply.Filters[i].FieldName, reply.Filters[j].FieldName) == -1 + return strings.Compare(reply.Filters[i].Element, reply.Filters[j].Element) == -1 }) if !reflect.DeepEqual(tpFilter, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpFilter), utils.ToJSON(reply)) diff --git a/apier/v2/attributes_it_test.go b/apier/v2/attributes_it_test.go index f6162e1a6..e050e1b66 100644 --- a/apier/v2/attributes_it_test.go +++ b/apier/v2/attributes_it_test.go @@ -120,15 +120,15 @@ func testAttributeSSetAlsPrf(t *testing.T) { Tenant: "cgrates.org", ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), }, Attributes: []*engine.ExternalAttribute{ { - FieldName: "Account", - Value: "1001", + Path: utils.MetaReq + utils.NestingSep + "Account", + Value: "1001", }, }, Weight: 20, @@ -146,15 +146,15 @@ func testAttributeSSetAlsPrf(t *testing.T) { Tenant: "cgrates.org", ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), }, Attributes: []*engine.Attribute{ { - FieldName: "Account", - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Account", + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -178,19 +178,19 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { Tenant: "cgrates.org", ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), }, Attributes: []*engine.ExternalAttribute{ { - FieldName: "Account", - Value: "1001", + Path: utils.MetaReq + utils.NestingSep + "Account", + Value: "1001", }, { - FieldName: "Subject", - Value: "~Account", + Path: utils.MetaReq + utils.NestingSep + "Subject", + Value: "~*req.Account", }, }, Weight: 20, @@ -208,19 +208,19 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { Tenant: "cgrates.org", ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), }, Attributes: []*engine.Attribute{ { - FieldName: "Account", - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Account", + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, { - FieldName: "Subject", - Value: config.NewRSRParsersMustCompile("~Account", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Subject", + Value: config.NewRSRParsersMustCompile("~*req.Account", true, utils.INFIELD_SEP), }, }, Weight: 20, diff --git a/apier/v2/cdrs_it_test.go b/apier/v2/cdrs_it_test.go index 5c2dc1f13..f8c015af4 100644 --- a/apier/v2/cdrs_it_test.go +++ b/apier/v2/cdrs_it_test.go @@ -408,8 +408,8 @@ func testV2CDRsDifferentTenants(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.MetaTenant, - Type: utils.META_CONSTANT, + Path: utils.MetaTenant, + Type: utils.META_CONSTANT, Value: config.RSRParsers{ &config.RSRParser{ Rules: "CustomTenant", @@ -418,8 +418,8 @@ func testV2CDRsDifferentTenants(t *testing.T) { }, }, { - FieldName: utils.Tenant, - Type: utils.META_CONSTANT, + Path: utils.MetaReq + utils.NestingSep + utils.Tenant, + Type: utils.META_CONSTANT, Value: config.RSRParsers{ &config.RSRParser{ Rules: "CustomTenant", diff --git a/cdrc/csv_it_test.go b/cdrc/csv_it_test.go index 2e040aa41..fc5ff534e 100644 --- a/cdrc/csv_it_test.go +++ b/cdrc/csv_it_test.go @@ -517,9 +517,9 @@ func TestCsvIT5AddFilters(t *testing.T) { ID: "FLTR_CDRC_ACC", Rules: []*engine.FilterRule{ { - Type: "*string", - FieldName: "~*req.3", - Values: []string{"1002"}, + Type: utils.MetaString, + Element: "~*req.3", + Values: []string{"1002"}, }, }, }, @@ -536,9 +536,9 @@ func TestCsvIT5AddFilters(t *testing.T) { ID: "FLTR_CDRC_ACC", Rules: []*engine.FilterRule{ { - Type: "*string", - FieldName: "~*req.3", - Values: []string{"1001"}, + Type: utils.MetaString, + Element: "~*req.3", + Values: []string{"1001"}, }, }, }, diff --git a/cdrc/fwv_it_test.go b/cdrc/fwv_it_test.go index 658278e0f..225c4864d 100644 --- a/cdrc/fwv_it_test.go +++ b/cdrc/fwv_it_test.go @@ -331,9 +331,9 @@ func TestFwvit3AddFilters(t *testing.T) { ID: "FLTR_FWV", Rules: []*engine.FilterRule{ { - Type: "*string", - FieldName: "0-10", - Values: []string{"CDR0000010"}, + Type: utils.MetaString, + Element: "0-10", + Values: []string{"CDR0000010"}, }, }, }, diff --git a/cdrc/xml_it_test.go b/cdrc/xml_it_test.go index 3faa4429f..d2be26e5f 100644 --- a/cdrc/xml_it_test.go +++ b/cdrc/xml_it_test.go @@ -467,14 +467,14 @@ func TestXmlIT5AddFilters(t *testing.T) { ID: "FLTR_XML", Rules: []*engine.FilterRule{ { - Type: "*string", - FieldName: "~*req.broadWorksCDR.cdrData.basicModule.userNumber", - Values: []string{"1002"}, + Type: utils.MetaString, + Element: "~*req.broadWorksCDR.cdrData.basicModule.userNumber", + Values: []string{"1002"}, }, { - Type: "*string", - FieldName: "~*req.broadWorksCDR.cdrData.headerModule.type", - Values: []string{"Normal"}, + Type: utils.MetaString, + Element: "~*req.broadWorksCDR.cdrData.headerModule.type", + Values: []string{"Normal"}, }, }, }, diff --git a/config/config_defaults.go b/config/config_defaults.go index 07297ee60..f16ad0684 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -644,7 +644,7 @@ const CGRATES_CFG_JSON = ` {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*variable", "value": "~3"}, {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~4"}, {"tag": "AttributeFilterIDs", "field_id": "AttributeFilterIDs", "type": "*variable", "value": "~5"}, - {"tag": "FieldName", "field_id": "FieldName", "type": "*variable", "value": "~6"}, + {"tag": "Path", "field_id": "Path", "type": "*variable", "value": "~6"}, {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~7"}, {"tag": "Value", "field_id": "Value", "type": "*variable", "value": "~8"}, {"tag": "Blocker", "field_id": "Blocker", "type": "*variable", "value": "~9"}, @@ -657,9 +657,9 @@ const CGRATES_CFG_JSON = ` "fields": [ {"tag": "Tenant", "field_id": "Tenant", "type": "*variable", "value": "~0", "mandatory": true}, {"tag": "ID", "field_id": "ID", "type": "*variable", "value": "~1", "mandatory": true}, - {"tag": "FilterType", "field_id": "FilterType", "type": "*variable", "value": "~2"}, - {"tag": "FilterFieldName", "field_id": "FilterFieldName", "type": "*variable", "value": "~3"}, - {"tag": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*variable", "value": "~4"}, + {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~2"}, + {"tag": "Element", "field_id": "Element", "type": "*variable", "value": "~3"}, + {"tag": "Values", "field_id": "Values", "type": "*variable", "value": "~4"}, {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~5"}, ], }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 5a6e59128..88c192450 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -1050,8 +1050,8 @@ func TestDfLoaderJsonCfg(t *testing.T) { Field_id: utils.StringPointer("AttributeFilterIDs"), Type: utils.StringPointer(utils.MetaVariable), Value: utils.StringPointer("~5")}, - {Tag: utils.StringPointer("FieldName"), - Field_id: utils.StringPointer(utils.FieldName), + {Tag: utils.StringPointer("Path"), + Field_id: utils.StringPointer(utils.Path), Type: utils.StringPointer(utils.MetaVariable), Value: utils.StringPointer("~6")}, {Tag: utils.StringPointer("Type"), @@ -1086,16 +1086,16 @@ func TestDfLoaderJsonCfg(t *testing.T) { Type: utils.StringPointer(utils.MetaVariable), Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - {Tag: utils.StringPointer("FilterType"), - Field_id: utils.StringPointer("FilterType"), + {Tag: utils.StringPointer("Type"), + Field_id: utils.StringPointer("Type"), Type: utils.StringPointer(utils.MetaVariable), Value: utils.StringPointer("~2")}, - {Tag: utils.StringPointer("FilterFieldName"), - Field_id: utils.StringPointer("FilterFieldName"), + {Tag: utils.StringPointer("Element"), + Field_id: utils.StringPointer("Element"), Type: utils.StringPointer(utils.MetaVariable), Value: utils.StringPointer("~3")}, - {Tag: utils.StringPointer("FilterFieldValues"), - Field_id: utils.StringPointer("FilterFieldValues"), + {Tag: utils.StringPointer("Values"), + Field_id: utils.StringPointer("Values"), Type: utils.StringPointer(utils.MetaVariable), Value: utils.StringPointer("~4")}, {Tag: utils.StringPointer("ActivationInterval"), diff --git a/config/config_test.go b/config/config_test.go index 17cbce757..d9ac1d03f 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -1083,8 +1083,8 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) { FieldId: "AttributeFilterIDs", Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~5", true, utils.INFIELD_SEP)}, - {Tag: "FieldName", - FieldId: "FieldName", + {Tag: "Path", + FieldId: "Path", Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~6", true, utils.INFIELD_SEP)}, {Tag: "Type", @@ -1119,16 +1119,16 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) { Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~1", true, utils.INFIELD_SEP), Mandatory: true}, - {Tag: "FilterType", - FieldId: "FilterType", + {Tag: "Type", + FieldId: "Type", Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~2", true, utils.INFIELD_SEP)}, - {Tag: "FilterFieldName", - FieldId: "FilterFieldName", + {Tag: "Element", + FieldId: "Element", Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~3", true, utils.INFIELD_SEP)}, - {Tag: "FilterFieldValues", - FieldId: "FilterFieldValues", + {Tag: "Values", + FieldId: "Values", Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~4", true, utils.INFIELD_SEP)}, {Tag: "ActivationInterval", diff --git a/config/navigablemap.go b/config/navigablemap.go index 30ed581c4..9d3125349 100644 --- a/config/navigablemap.go +++ b/config/navigablemap.go @@ -524,3 +524,39 @@ func (nM *NavigableMap) GetKeys() (keys []string) { } return } + +// Remove will remove the items from the given path +func (nM *NavigableMap) Remove(path []string) { + // if ordered { + // nM.order = append(nM.order, path) + // } + mp := nM.data + for i, spath := range path { + oData, has := mp[spath] + if !has { // no need to remove + return + } + if i == len(path)-1 { // last path + delete(mp, spath) + return + } + defer func(np map[string]interface{}, p string) { + o, has := np[p] + if !has { + return + } + if o == nil { + delete(np, p) + return + } + v, ok := o.(map[string]interface{}) + if !ok { + return + } + if len(v) == 0 { + delete(np, p) + } + }(mp, spath) + mp = oData.(map[string]interface{}) // so we can check further down + } +} diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index cd07354e7..d6d88690f 100755 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -597,7 +597,7 @@ // {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*variable", "value": "~3"}, // {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~4"}, // {"tag": "AttributeFilterIDs", "field_id": "AttributeFilterIDs", "type": "*variable", "value": "~5"}, -// {"tag": "FieldName", "field_id": "FieldName", "type": "*variable", "value": "~6"}, +// {"tag": "Path", "field_id": "Path", "type": "*variable", "value": "~6"}, // {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~7"}, // {"tag": "Value", "field_id": "Value", "type": "*variable", "value": "~8"}, // {"tag": "Blocker", "field_id": "Blocker", "type": "*variable", "value": "~9"}, @@ -610,9 +610,9 @@ // "fields": [ // {"tag": "Tenant", "field_id": "Tenant", "type": "*variable", "value": "~0", "mandatory": true}, // {"tag": "ID", "field_id": "ID", "type": "*variable", "value": "~1", "mandatory": true}, -// {"tag": "FilterType", "field_id": "FilterType", "type": "*variable", "value": "~2"}, -// {"tag": "FilterFieldName", "field_id": "FilterFieldName", "type": "*variable", "value": "~3"}, -// {"tag": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*variable", "value": "~4"}, +// {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~2"}, +// {"tag": "Element", "field_id": "Element", "type": "*variable", "value": "~3"}, +// {"tag": "Values", "field_id": "Values", "type": "*variable", "value": "~4"}, // {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~5"}, // ], // }, diff --git a/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json b/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json index c31e657ac..7c4efb2f7 100644 --- a/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json +++ b/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json @@ -50,19 +50,13 @@ "enabled": true, }, - "rpc_conns": { - "conn1": { - "strategy": "*first", - "conns": [{"address": "127.0.0.1:2012", "transport":"*json"}], - }, - }, "sessions": { "enabled": true, - "attributes_conns": ["conn1"], - "rals_conns": ["conn1"], - "resources_conns": ["conn1"], - "chargers_conns": ["conn1"], + "attributes_conns": ["*localhost"], + "rals_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "chargers_conns": ["*localhost"], "listen_bijson": ":3014", }, diff --git a/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json index a991c2a98..a61e81682 100644 --- a/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json +++ b/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json @@ -53,19 +53,12 @@ "enabled": true, }, -"rpc_conns": { - "conn1": { - "strategy": "*first", - "conns": [{"address": "127.0.0.1:2012", "transport":"*json"}], - }, -}, - "sessions": { "enabled": true, - "attributes_conns": ["conn1"], - "rals_conns": ["conn1"], - "resources_conns": ["conn1"], - "chargers_conns": ["conn1"], + "attributes_conns": ["*localhost"], + "rals_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "chargers_conns": ["*localhost"], "listen_bijson": ":3014", }, diff --git a/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json index 386e45435..1fd1c9de9 100755 --- a/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json +++ b/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json @@ -44,19 +44,12 @@ "enabled": true, }, -"rpc_conns": { - "conn1": { - "strategy": "*first", - "conns": [{"address": "127.0.0.1:2012", "transport":"*json"}], - }, -}, - "sessions": { "enabled": true, - "attributes_conns": ["conn1"], - "rals_conns": ["conn1"], - "resources_conns": ["conn1"], - "chargers_conns": ["conn1"], + "attributes_conns": ["*localhost"], + "rals_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "chargers_conns": ["*localhost"], "listen_bijson": ":3014", }, diff --git a/data/conf/samples/loaders/tutmongo/cgrates.json b/data/conf/samples/loaders/tutmongo/cgrates.json index 039737224..107343c63 100644 --- a/data/conf/samples/loaders/tutmongo/cgrates.json +++ b/data/conf/samples/loaders/tutmongo/cgrates.json @@ -126,7 +126,7 @@ {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*variable", "value": "~3"}, {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~4"}, {"tag": "AttributeFilterIDs", "field_id": "AttributeFilterIDs", "type": "*variable", "value": "~5"}, - {"tag": "FieldName", "field_id": "FieldName", "type": "*variable", "value": "~6"}, + {"tag": "Path", "field_id": "Path", "type": "*variable", "value": "~6"}, {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~7"}, {"tag": "Value", "field_id": "Value", "type": "*variable", "value": "~8"}, {"tag": "Blocker", "field_id": "Blocker", "type": "*variable", "value": "~9"}, diff --git a/data/conf/samples/loaders/tutmysql/cgrates.json b/data/conf/samples/loaders/tutmysql/cgrates.json index 9e450d7ff..a30852813 100644 --- a/data/conf/samples/loaders/tutmysql/cgrates.json +++ b/data/conf/samples/loaders/tutmysql/cgrates.json @@ -86,7 +86,7 @@ {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*variable", "value": "~3"}, {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~4"}, {"tag": "AttributeFilterIDs", "field_id": "AttributeFilterIDs", "type": "*variable", "value": "~5"}, - {"tag": "FieldName", "field_id": "FieldName", "type": "*variable", "value": "~6"}, + {"tag": "Path", "field_id": "Path", "type": "*variable", "value": "~6"}, {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~7"}, {"tag": "Value", "field_id": "Value", "type": "*variable", "value": "~8"}, {"tag": "Blocker", "field_id": "Blocker", "type": "*variable", "value": "~9"}, diff --git a/data/conf/samples/tutmysql_internal/cgrates.json b/data/conf/samples/tutmysql_internal/cgrates.json index fb4e6fa8a..afc4fbe6e 100644 --- a/data/conf/samples/tutmysql_internal/cgrates.json +++ b/data/conf/samples/tutmysql_internal/cgrates.json @@ -168,9 +168,9 @@ "fields": [ {"tag": "Tenant", "field_id": "Tenant", "type": "*variable", "value": "~0", "mandatory": true}, {"tag": "ID", "field_id": "ID", "type": "*variable", "value": "~1", "mandatory": true}, - {"tag": "FilterType", "field_id": "FilterType", "type": "*variable", "value": "~2"}, - {"tag": "FilterFieldName", "field_id": "FilterFieldName", "type": "*variable", "value": "~3"}, - {"tag": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*variable", "value": "~4"}, + {"tag": "Type", "field_id": "Type", "type": "*variable", "value": "~2"}, + {"tag": "Element", "field_id": "Element", "type": "*variable", "value": "~3"}, + {"tag": "Values", "field_id": "Values", "type": "*variable", "value": "~4"}, {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*variable", "value": "~5"}, ], }, diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 455c58e47..a203d7090 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -329,14 +329,14 @@ CREATE TABLE tp_filters ( `tpid` varchar(64) NOT NULL, `tenant` varchar(64) NOT NULL, `id` varchar(64) NOT NULL, - `filter_type` varchar(16) NOT NULL, - `filter_field_name` varchar(64) NOT NULL, - `filter_field_values` varchar(256) NOT NULL, + `type` varchar(16) NOT NULL, + `element` varchar(64) NOT NULL, + `values` varchar(256) NOT NULL, `activation_interval` varchar(64) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`pk`), KEY `tpid` (`tpid`), - UNIQUE KEY `unique_tp_filters` (`tpid`,`tenant`, `id`, `filter_type`, `filter_field_name`) + UNIQUE KEY `unique_tp_filters` (`tpid`,`tenant`, `id`, `type`, `element`) ); -- @@ -386,7 +386,7 @@ CREATE TABLE tp_attributes ( `filter_ids` varchar(64) NOT NULL, `activation_interval` varchar(64) NOT NULL, `attribute_filter_ids` varchar(64) NOT NULL, - `field_name` varchar(64) NOT NULL, + `path` varchar(64) NOT NULL, `type` varchar(64) NOT NULL, `value` varchar(64) NOT NULL, `blocker` BOOLEAN NOT NULL, @@ -395,7 +395,7 @@ CREATE TABLE tp_attributes ( PRIMARY KEY (`pk`), KEY `tpid` (`tpid`), UNIQUE KEY `unique_tp_attributes` (`tpid`,`tenant`, - `id`,`filter_ids`,`field_name`,`value` ) + `id`,`filter_ids`,`path`,`value` ) ); -- diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index c6d7d60ad..29a9502df 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -323,14 +323,14 @@ CREATE TABLE tp_filters ( "tpid" varchar(64) NOT NULL, "tenant" varchar(64) NOT NULL, "id" varchar(64) NOT NULL, - "filter_type" varchar(16) NOT NULL, - "filter_field_name" varchar(64) NOT NULL, - "filter_field_values" varchar(256) NOT NULL, + "type" varchar(16) NOT NULL, + "element" varchar(64) NOT NULL, + "values" varchar(256) NOT NULL, "activation_interval" varchar(64) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE ); CREATE INDEX tp_filters_idx ON tp_filters (tpid); - CREATE INDEX tp_filters_unique ON tp_filters ("tpid","tenant", "id", "filter_type", "filter_field_name"); + CREATE INDEX tp_filters_unique ON tp_filters ("tpid","tenant", "id", "type", "element"); -- -- Table structure for table `tp_suppliers` @@ -377,7 +377,7 @@ CREATE INDEX tp_suppliers_unique ON tp_suppliers ("tpid", "tenant", "id", "filter_ids" varchar(64) NOT NULL, "activation_interval" varchar(64) NOT NULL, "attribute_filter_ids" varchar(64) NOT NULL, - "field_name" varchar(64) NOT NULL, + "path" varchar(64) NOT NULL, "type" varchar(64) NOT NULL, "value" varchar(64) NOT NULL, "blocker" BOOLEAN NOT NULL, @@ -386,7 +386,7 @@ CREATE INDEX tp_suppliers_unique ON tp_suppliers ("tpid", "tenant", "id", ); CREATE INDEX tp_attributes_ids ON tp_attributes (tpid); CREATE INDEX tp_attributes_unique ON tp_attributes ("tpid", "tenant", "id", - "filter_ids","field_name","value"); + "filter_ids","path","value"); -- -- Table structure for table `tp_chargers` diff --git a/data/tariffplans/cluelrn/Attributes.csv b/data/tariffplans/cluelrn/Attributes.csv index 2917b14d4..cc128ac6e 100644 --- a/data/tariffplans/cluelrn/Attributes.csv +++ b/data/tariffplans/cluelrn/Attributes.csv @@ -1,8 +1,8 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,LRN_Dst3125650565,lrn,*string:~*req.Destination:3125650565,,,Destination,*constant,13128543000,false,10 -cgrates.org,LRN_Dst3125650565,,,,,OriginalDestination,*constant,3125650565,false,10 -cgrates.org,LRN_LATA_Dst13128543000,lrn,*string:~*req.Destination:13128543000;*rsr::~*req.OriginalDestination(!^$),,,DestinationLATA,*constant,358,false,20 -cgrates.org,LRN_LATA_Cli9174269000,lrn,*string:~*req.Account:9174269000;*rsr::~*req.DestinationLATA(!^$),,,CallerLATA,*constant,132,false,30 -cgrates.org,LRN_JURISDICTION_NY,lrn,FLTR_INTRALATA_NEWYORK,,,LRNJurisdiction,*constant,INTRA,false,50 -cgrates.org,LRN_JURISDICTION_IL,lrn,FLTR_INTRALATA_ILLINOIS,,,LRNJurisdiction,*constant,INTRA,false,50 -cgrates.org,LRN_JURISDICTION_INTER,lrn,*string:~*req.Destination:13128543000;*rsr::~*req.CallerLATA(!^$),,,LRNJurisdiction,*constant,INTER,false,40 +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,LRN_Dst3125650565,lrn,*string:~*req.Destination:3125650565,,,*req.Destination,*constant,13128543000,false,10 +cgrates.org,LRN_Dst3125650565,,,,,*req.OriginalDestination,*constant,3125650565,false,10 +cgrates.org,LRN_LATA_Dst13128543000,lrn,*string:~*req.Destination:13128543000;*rsr::~*req.OriginalDestination(!^$),,,*req.DestinationLATA,*constant,358,false,20 +cgrates.org,LRN_LATA_Cli9174269000,lrn,*string:~*req.Account:9174269000;*rsr::~*req.DestinationLATA(!^$),,,*req.CallerLATA,*constant,132,false,30 +cgrates.org,LRN_JURISDICTION_NY,lrn,FLTR_INTRALATA_NEWYORK,,,*req.LRNJurisdiction,*constant,INTRA,false,50 +cgrates.org,LRN_JURISDICTION_IL,lrn,FLTR_INTRALATA_ILLINOIS,,,*req.LRNJurisdiction,*constant,INTRA,false,50 +cgrates.org,LRN_JURISDICTION_INTER,lrn,*string:~*req.Destination:13128543000;*rsr::~*req.CallerLATA(!^$),,,*req.LRNJurisdiction,*constant,INTER,false,40 diff --git a/data/tariffplans/cluelrn/Filters.csv b/data/tariffplans/cluelrn/Filters.csv index 916436222..e85258894 100644 --- a/data/tariffplans/cluelrn/Filters.csv +++ b/data/tariffplans/cluelrn/Filters.csv @@ -1,4 +1,4 @@ -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Path[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_INTRALATA_NEWYORK,*string,~*req.CallerLATA,224;222;220;132, cgrates.org,FLTR_INTRALATA_NEWYORK,*string,~*req.DestinationLATA,224;222;220;132, cgrates.org,FLTR_INTRALATA_ILLINOIS,*string,~*req.CallerLATA,358;359, diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index 3f4e362d4..defe079eb 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -1,22 +1,22 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_1001_SIMPLEAUTH,*any,*string:~*req.Account:1001,,,Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1001_SIMPLEAUTH,*any,,,,EventName,*constant,*remove,false,20 -cgrates.org,ATTR_1003_SIMPLEAUTH,*any,*string:~*req.Account:1003,,,Password,*constant,CGRateS.com,false,20 -cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:~*req.APIKey:12345,,,APIMethods,*constant,,false,20 -cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:~*req.APIKey:attr12345,,,APIMethods,*constant,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,false,20 -cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:~*req.APIKey:chrg12345,,,APIMethods,*constant,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,false,20 -cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~*req.APIKey:thr12345,,,APIMethods,*constant,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent&ThresholdSv1.GetThreshold&ThresholdSv1.GetThresholdIDs,false,20 -cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~*req.APIKey:sup12345,,,APIMethods,*constant,SupplierSv1.Ping&SupplierSv1.GetSuppliers&SupplierSv1.GetSupplierProfilesForEvent,false,20 -cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.APIKey:stat12345,,,APIMethods,*constant,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20 -cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.APIKey:res12345,,,APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,false,20 -cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent,false,20 -cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.APIKey:rsp12345,,,APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20 -cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.APIKey:chc12345,,,APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20 -cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.APIKey:grd12345,,,APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 -cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~*req.APIKey:sched12345,,,APIMethods,*constant,SchedulerSv1.Ping,false,20 -cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~*req.APIKey:cdrs12345,,,APIMethods,*constant,CDRsV1.Ping&CDRsV1.ProcessEvent&CDRsV1.GetCDRs&CDRsV1.GetCDRsCount&CDRsV1.ProcessCDR&CDRsV1.ProcessExternalCDR,false,20 -cgrates.org,ATTR_API_DSP_AUTH,*auth,*string:~*req.APIKey:dsp12345,,,APIMethods,*constant,DispatcherSv1.Ping&DispatcherSv1.GetProfileForEvent,false,20 -cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&AttributeSv1.ProcessEvent&Responder.Debit&ResourceSv1.AllocateResources&ChargerSv1.ProcessEvent&Responder.MaxDebit,false,20 -cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 -cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,APIMethods,*constant,ApierV1.GetAttributeProfile&ApierV1.SetAttributeProfile,false,20 -cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_1001_SIMPLEAUTH,*any,*string:~*req.Account:1001,,,*req.Password,*constant,CGRateS.org,false,20 +cgrates.org,ATTR_1001_SIMPLEAUTH,*any,,,,*req.EventName,*constant,*remove,false,20 +cgrates.org,ATTR_1003_SIMPLEAUTH,*any,*string:~*req.Account:1003,,,*req.Password,*constant,CGRateS.com,false,20 +cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:~*req.APIKey:12345,,,*req.APIMethods,*constant,,false,20 +cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:~*req.APIKey:attr12345,,,*req.APIMethods,*constant,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,false,20 +cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:~*req.APIKey:chrg12345,,,*req.APIMethods,*constant,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,false,20 +cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~*req.APIKey:thr12345,,,*req.APIMethods,*constant,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent&ThresholdSv1.GetThreshold&ThresholdSv1.GetThresholdIDs,false,20 +cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~*req.APIKey:sup12345,,,*req.APIMethods,*constant,SupplierSv1.Ping&SupplierSv1.GetSuppliers&SupplierSv1.GetSupplierProfilesForEvent,false,20 +cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.APIKey:stat12345,,,*req.APIMethods,*constant,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20 +cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.APIKey:res12345,,,*req.APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,false,20 +cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent,false,20 +cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.APIKey:rsp12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20 +cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.APIKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20 +cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.APIKey:grd12345,,,*req.APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 +cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~*req.APIKey:sched12345,,,*req.APIMethods,*constant,SchedulerSv1.Ping,false,20 +cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~*req.APIKey:cdrs12345,,,*req.APIMethods,*constant,CDRsV1.Ping&CDRsV1.ProcessEvent&CDRsV1.GetCDRs&CDRsV1.GetCDRsCount&CDRsV1.ProcessCDR&CDRsV1.ProcessExternalCDR,false,20 +cgrates.org,ATTR_API_DSP_AUTH,*auth,*string:~*req.APIKey:dsp12345,,,*req.APIMethods,*constant,DispatcherSv1.Ping&DispatcherSv1.GetProfileForEvent,false,20 +cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&AttributeSv1.ProcessEvent&Responder.Debit&ResourceSv1.AllocateResources&ChargerSv1.ProcessEvent&Responder.MaxDebit,false,20 +cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,*req.APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 +cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,*req.APIMethods,*constant,ApierV1.GetAttributeProfile&ApierV1.SetAttributeProfile,false,20 +cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,*req.APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 diff --git a/data/tariffplans/dispatchers_gob/Attributes.csv b/data/tariffplans/dispatchers_gob/Attributes.csv index 3f4e362d4..610f17c9d 100644 --- a/data/tariffplans/dispatchers_gob/Attributes.csv +++ b/data/tariffplans/dispatchers_gob/Attributes.csv @@ -1,22 +1,22 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_1001_SIMPLEAUTH,*any,*string:~*req.Account:1001,,,Password,*constant,CGRateS.org,false,20 +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_1001_SIMPLEAUTH,*any,*string:~*req.Account:1001,,,*req.Password,*constant,CGRateS.org,false,20 cgrates.org,ATTR_1001_SIMPLEAUTH,*any,,,,EventName,*constant,*remove,false,20 -cgrates.org,ATTR_1003_SIMPLEAUTH,*any,*string:~*req.Account:1003,,,Password,*constant,CGRateS.com,false,20 -cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:~*req.APIKey:12345,,,APIMethods,*constant,,false,20 -cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:~*req.APIKey:attr12345,,,APIMethods,*constant,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,false,20 -cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:~*req.APIKey:chrg12345,,,APIMethods,*constant,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,false,20 -cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~*req.APIKey:thr12345,,,APIMethods,*constant,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent&ThresholdSv1.GetThreshold&ThresholdSv1.GetThresholdIDs,false,20 -cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~*req.APIKey:sup12345,,,APIMethods,*constant,SupplierSv1.Ping&SupplierSv1.GetSuppliers&SupplierSv1.GetSupplierProfilesForEvent,false,20 -cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.APIKey:stat12345,,,APIMethods,*constant,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20 -cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.APIKey:res12345,,,APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,false,20 -cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent,false,20 -cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.APIKey:rsp12345,,,APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20 -cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.APIKey:chc12345,,,APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20 -cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.APIKey:grd12345,,,APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 -cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~*req.APIKey:sched12345,,,APIMethods,*constant,SchedulerSv1.Ping,false,20 -cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~*req.APIKey:cdrs12345,,,APIMethods,*constant,CDRsV1.Ping&CDRsV1.ProcessEvent&CDRsV1.GetCDRs&CDRsV1.GetCDRsCount&CDRsV1.ProcessCDR&CDRsV1.ProcessExternalCDR,false,20 -cgrates.org,ATTR_API_DSP_AUTH,*auth,*string:~*req.APIKey:dsp12345,,,APIMethods,*constant,DispatcherSv1.Ping&DispatcherSv1.GetProfileForEvent,false,20 -cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&AttributeSv1.ProcessEvent&Responder.Debit&ResourceSv1.AllocateResources&ChargerSv1.ProcessEvent&Responder.MaxDebit,false,20 -cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 -cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,APIMethods,*constant,ApierV1.GetAttributeProfile&ApierV1.SetAttributeProfile,false,20 -cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 +cgrates.org,ATTR_1003_SIMPLEAUTH,*any,*string:~*req.Account:1003,,,*req.Password,*constant,CGRateS.com,false,20 +cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:~*req.APIKey:12345,,,*req.APIMethods,*constant,,false,20 +cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:~*req.APIKey:attr12345,,,*req.APIMethods,*constant,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,false,20 +cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:~*req.APIKey:chrg12345,,,*req.APIMethods,*constant,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,false,20 +cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~*req.APIKey:thr12345,,,*req.APIMethods,*constant,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent&ThresholdSv1.GetThreshold&ThresholdSv1.GetThresholdIDs,false,20 +cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~*req.APIKey:sup12345,,,*req.APIMethods,*constant,SupplierSv1.Ping&SupplierSv1.GetSuppliers&SupplierSv1.GetSupplierProfilesForEvent,false,20 +cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.APIKey:stat12345,,,*req.APIMethods,*constant,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20 +cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.APIKey:res12345,,,*req.APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,false,20 +cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent,false,20 +cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.APIKey:rsp12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20 +cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.APIKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20 +cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.APIKey:grd12345,,,*req.APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 +cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~*req.APIKey:sched12345,,,*req.APIMethods,*constant,SchedulerSv1.Ping,false,20 +cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~*req.APIKey:cdrs12345,,,*req.APIMethods,*constant,CDRsV1.Ping&CDRsV1.ProcessEvent&CDRsV1.GetCDRs&CDRsV1.GetCDRsCount&CDRsV1.ProcessCDR&CDRsV1.ProcessExternalCDR,false,20 +cgrates.org,ATTR_API_DSP_AUTH,*auth,*string:~*req.APIKey:dsp12345,,,*req.APIMethods,*constant,DispatcherSv1.Ping&DispatcherSv1.GetProfileForEvent,false,20 +cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.APIKey:pse12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&AttributeSv1.ProcessEvent&Responder.Debit&ResourceSv1.AllocateResources&ChargerSv1.ProcessEvent&Responder.MaxDebit,false,20 +cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.APIKey:cfg12345,,,*req.APIMethods,*constant,ConfigSv1.GetJSONSection&ConfigSv1.ReloadConfig,false,20 +cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.APIKey:apier12345,,,*req.APIMethods,*constant,ApierV1.GetAttributeProfile&ApierV1.SetAttributeProfile,false,20 +cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.APIKey:rals12345,,,*req.APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20 diff --git a/data/tariffplans/dnsagent/Attributes.csv b/data/tariffplans/dnsagent/Attributes.csv index 651b27d1c..12f1c7d1e 100644 --- a/data/tariffplans/dnsagent/Attributes.csv +++ b/data/tariffplans/dnsagent/Attributes.csv @@ -1,3 +1,3 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_NAPTR_ADDR,*any,*string:~*req.E164Address:4986517174964,,,NAPTRAddress,*constant,sip:\1@172.16.1.1.,false,20 +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_NAPTR_ADDR,*any,*string:~*req.E164Address:4986517174964,,,*req.NAPTRAddress,*constant,sip:\1@172.16.1.1.,false,20 diff --git a/data/tariffplans/oldtutorial/Attributes.csv b/data/tariffplans/oldtutorial/Attributes.csv index 41db7b3e4..b96c5799a 100644 --- a/data/tariffplans/oldtutorial/Attributes.csv +++ b/data/tariffplans/oldtutorial/Attributes.csv @@ -1,3 +1,3 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_1,*sessions;*cdrs,*string:~*req.Account:1007,2014-01-14T00:00:00Z,,Account,*constant,1001,false,10 -cgrates.org,ATTR_1,,,,,Subject,*constant,1001,, +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_1,*sessions;*cdrs,*string:~*req.Account:1007,2014-01-14T00:00:00Z,,*req.Account,*constant,1001,false,10 +cgrates.org,ATTR_1,,,,,*req.Subject,*constant,1001,, diff --git a/data/tariffplans/oldtutorial/Filters.csv b/data/tariffplans/oldtutorial/Filters.csv index 78c286f68..8cb901d2e 100644 --- a/data/tariffplans/oldtutorial/Filters.csv +++ b/data/tariffplans/oldtutorial/Filters.csv @@ -1,4 +1,4 @@ -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Path[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20, cgrates.org,FLTR_1,*rsr,,~*req.Subject(~^1.*1$);~*req.Destination(1002), diff --git a/data/tariffplans/precache/Attributes.csv b/data/tariffplans/precache/Attributes.csv index 41db7b3e4..b96c5799a 100644 --- a/data/tariffplans/precache/Attributes.csv +++ b/data/tariffplans/precache/Attributes.csv @@ -1,3 +1,3 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_1,*sessions;*cdrs,*string:~*req.Account:1007,2014-01-14T00:00:00Z,,Account,*constant,1001,false,10 -cgrates.org,ATTR_1,,,,,Subject,*constant,1001,, +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_1,*sessions;*cdrs,*string:~*req.Account:1007,2014-01-14T00:00:00Z,,*req.Account,*constant,1001,false,10 +cgrates.org,ATTR_1,,,,,*req.Subject,*constant,1001,, diff --git a/data/tariffplans/precache/Filters.csv b/data/tariffplans/precache/Filters.csv index 71490d627..2782f4fe2 100644 --- a/data/tariffplans/precache/Filters.csv +++ b/data/tariffplans/precache/Filters.csv @@ -1,4 +1,4 @@ -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Path[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20, cgrates.org,FLTR_1,*rsr,,~*req.Subject(~^1.*1$);~Destination(1002), diff --git a/data/tariffplans/testit/Attributes.csv b/data/tariffplans/testit/Attributes.csv index 5be22cc2f..b93e70ff2 100644 --- a/data/tariffplans/testit/Attributes.csv +++ b/data/tariffplans/testit/Attributes.csv @@ -1,4 +1,4 @@ -#Tenant,ID,Context,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_ACNT_1001,*sessions,FLTR_ACCOUNT_1001,,,OfficeGroup,*constant,Marketing,false,10 -cgrates.org,ATTR_SUPPLIER1,*chargers,,,,Subject,*constant,SUPPLIER1,false,10 -cgrates.org,ATTR_PAYPAL,*cdrs,*string:~*req.Subject:ANY2CNT,,,PayPalAccount,*constant,paypal@cgrates.org,false,10 +#Tenant,ID,Context,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_ACNT_1001,*sessions,FLTR_ACCOUNT_1001,,,*req.OfficeGroup,*constant,Marketing,false,10 +cgrates.org,ATTR_SUPPLIER1,*chargers,,,,*req.Subject,*constant,SUPPLIER1,false,10 +cgrates.org,ATTR_PAYPAL,*cdrs,*string:~*req.Subject:ANY2CNT,,,*req.PayPalAccount,*constant,paypal@cgrates.org,false,10 diff --git a/data/tariffplans/testit/Chargers.csv b/data/tariffplans/testit/Chargers.csv index fc5456b60..df4000134 100644 --- a/data/tariffplans/testit/Chargers.csv +++ b/data/tariffplans/testit/Chargers.csv @@ -1,4 +1,4 @@ #Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight -cgrates.org,Raw,,,*raw,*constant:RequestType:*none,20 +cgrates.org,Raw,,,*raw,*constant:*req.RequestType:*none,20 cgrates.org,CustomerCharges,,,CustomerCharges,*none,20 cgrates.org,SupplierCharges,,,SupplierCharges,ATTR_SUPPLIER1,10 \ No newline at end of file diff --git a/data/tariffplans/testit/Filters.csv b/data/tariffplans/testit/Filters.csv index 8b6c7652d..80ed6745e 100644 --- a/data/tariffplans/testit/Filters.csv +++ b/data/tariffplans/testit/Filters.csv @@ -1,4 +1,4 @@ -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Path[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_ACCOUNT_1001,*string,~*req.Account,1001,2014-07-29T15:00:00Z cgrates.org,FLTR_DST_DE,*destinations,~*req.Destination,DST_DE_MOBILE,2014-07-29T15:00:00Z cgrates.org,FLTR_1,*string,~*req.Account,1003;1002,2014-07-29T15:00:00Z diff --git a/data/tariffplans/testtp/Attributes.csv b/data/tariffplans/testtp/Attributes.csv index 65fd8af84..c6abdd8c3 100644 --- a/data/tariffplans/testtp/Attributes.csv +++ b/data/tariffplans/testtp/Attributes.csv @@ -1,3 +1,3 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ALS1,con1,FLTR_1,2014-07-29T15:00:00Z,*string:Field1:Initial1,Field1,*constant,Sub1,false,20 -cgrates.org,ALS1,,,,*string:Field1:Initial2,Field2,*constant,Sub2,, +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ALS1,con1,FLTR_1,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial1,*req.Field1,*constant,Sub1,false,20 +cgrates.org,ALS1,,,,*string:~*req.Field1:Initial2,*req.Field2,*constant,Sub2,, diff --git a/data/tariffplans/testtp/Filters.csv b/data/tariffplans/testtp/Filters.csv index 74926470d..3442e65b4 100644 --- a/data/tariffplans/testtp/Filters.csv +++ b/data/tariffplans/testtp/Filters.csv @@ -1,4 +1,4 @@ -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Path[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20, cgrates.org,FLTR_1,*rsr,,~*req.Subject(~^1.*1$);~Destination(1002), diff --git a/data/tariffplans/tutorial/Attributes.csv b/data/tariffplans/tutorial/Attributes.csv index a52b9d86a..2a7a41590 100644 --- a/data/tariffplans/tutorial/Attributes.csv +++ b/data/tariffplans/tutorial/Attributes.csv @@ -1,24 +1,24 @@ -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ATTR_1001_SIMPLEAUTH,simpleauth,*string:~*req.Account:1001,,,Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1002_SIMPLEAUTH,simpleauth,*string:~*req.Account:1002,,,Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1003_SIMPLEAUTH,simpleauth,*string:~*req.Account:1003,,,Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1001_SESSIONAUTH,*sessions,*string:~*req.Account:1001,,,Password,*constant,CGRateS.org,false,10 -cgrates.org,ATTR_1001_SESSIONAUTH,,,,,RequestType,*constant,*prepaid,, -cgrates.org,ATTR_1001_SESSIONAUTH,,,,,PaypalAccount,*constant,cgrates@paypal.com,, -cgrates.org,ATTR_1001_SESSIONAUTH,,,,,LCRProfile,*constant,premium_cli,, -cgrates.org,ATTR_1002_SESSIONAUTH,*sessions,*string:~*req.Account:1002,,,Password,*constant,CGRateS.org,false,10 -cgrates.org,ATTR_1002_SESSIONAUTH,,,,,RequestType,*constant,*postpaid,, -cgrates.org,ATTR_1002_SESSIONAUTH,,,,,PaypalAccount,*constant,cgrates@paypal.com,, -cgrates.org,ATTR_1002_SESSIONAUTH,,,,,LCRProfile,*constant,premium_cli,, +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ATTR_1001_SIMPLEAUTH,simpleauth,*string:~*req.Account:1001,,,*req.Password,*constant,CGRateS.org,false,20 +cgrates.org,ATTR_1002_SIMPLEAUTH,simpleauth,*string:~*req.Account:1002,,,*req.Password,*constant,CGRateS.org,false,20 +cgrates.org,ATTR_1003_SIMPLEAUTH,simpleauth,*string:~*req.Account:1003,,,*req.Password,*constant,CGRateS.org,false,20 +cgrates.org,ATTR_1001_SESSIONAUTH,*sessions,*string:~*req.Account:1001,,,*req.Password,*constant,CGRateS.org,false,10 +cgrates.org,ATTR_1001_SESSIONAUTH,,,,,*req.RequestType,*constant,*prepaid,, +cgrates.org,ATTR_1001_SESSIONAUTH,,,,,*req.PaypalAccount,*constant,cgrates@paypal.com,, +cgrates.org,ATTR_1001_SESSIONAUTH,,,,,*req.LCRProfile,*constant,premium_cli,, +cgrates.org,ATTR_1002_SESSIONAUTH,*sessions,*string:~*req.Account:1002,,,*req.Password,*constant,CGRateS.org,false,10 +cgrates.org,ATTR_1002_SESSIONAUTH,,,,,*req.RequestType,*constant,*postpaid,, +cgrates.org,ATTR_1002_SESSIONAUTH,,,,,*req.PaypalAccount,*constant,cgrates@paypal.com,, +cgrates.org,ATTR_1002_SESSIONAUTH,,,,,*req.LCRProfile,*constant,premium_cli,, cgrates.org,ATTR_1002_SESSIONAUTH,,,,,ResourceAllocation,*constant,"ResGroup1",, -cgrates.org,ATTR_1003_SESSIONAUTH,*sessions,*string:~*req.Account:1003,,,Password,*constant,CGRateS.org,false,10 -cgrates.org,ATTR_1003_SESSIONAUTH,,,,,RequestType,*constant,*prepaid,, -cgrates.org,ATTR_1003_SESSIONAUTH,,,,,PaypalAccount,*constant,cgrates@paypal.com,, -cgrates.org,ATTR_1003_SESSIONAUTH,,,,,LCRProfile,*constant,premium_cli,, -cgrates.org,ATTR_ACC_ALIAS,*any,*string:~*req.SubscriberId:1006,,,Account,*constant,1001,false,10 -cgrates.org,ATTR_ACC_ALIAS,*any,,,,RequestType,*constant,*prepaid,, -cgrates.com,ATTR_TNT_ALIAS,*any,*string:~*req.SubscriberId:1006,,,Account,*constant,1001,false,10 -cgrates.com,ATTR_TNT_ALIAS,*any,,,,RequestType,*constant,*prepaid,, +cgrates.org,ATTR_1003_SESSIONAUTH,*sessions,*string:~*req.Account:1003,,,*req.Password,*constant,CGRateS.org,false,10 +cgrates.org,ATTR_1003_SESSIONAUTH,,,,,*req.RequestType,*constant,*prepaid,, +cgrates.org,ATTR_1003_SESSIONAUTH,,,,,*req.PaypalAccount,*constant,cgrates@paypal.com,, +cgrates.org,ATTR_1003_SESSIONAUTH,,,,,*req.LCRProfile,*constant,premium_cli,, +cgrates.org,ATTR_ACC_ALIAS,*any,*string:~*req.SubscriberId:1006,,,*req.Account,*constant,1001,false,10 +cgrates.org,ATTR_ACC_ALIAS,*any,,,,*req.RequestType,*constant,*prepaid,, +cgrates.com,ATTR_TNT_ALIAS,*any,*string:~*req.SubscriberId:1006,,,*req.Account,*constant,1001,false,10 +cgrates.com,ATTR_TNT_ALIAS,*any,,,,*req.RequestType,*constant,*prepaid,, cgrates.com,ATTR_TNT_ALIAS,*any,,,,*tenant,*constant,cgrates.org,, cgrates.com,ATTR_TNT_1001,*any,*string:~*req.Account:1001,,,*tenant,*constant,cgrates.org,, cgrates.com,ATTR_TNT_DISC,*any,*string:~*req.Account:testDiamInitWithSessionDisconnect,,,*tenant,*constant,cgrates.org,, diff --git a/data/tariffplans/tutorial/Chargers.csv b/data/tariffplans/tutorial/Chargers.csv index c58b582cb..7145717c7 100644 --- a/data/tariffplans/tutorial/Chargers.csv +++ b/data/tariffplans/tutorial/Chargers.csv @@ -1,3 +1,3 @@ #Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight cgrates.org,DEFAULT,,,*default,*none,0 -cgrates.org,Raw,,,*raw,*constant:RequestType:*none,0 \ No newline at end of file +cgrates.org,Raw,,,*raw,*constant:*req.RequestType:*none,0 \ No newline at end of file diff --git a/data/tariffplans/tutorial/Filters.csv b/data/tariffplans/tutorial/Filters.csv index d889e87f1..b5f8c0a21 100644 --- a/data/tariffplans/tutorial/Filters.csv +++ b/data/tariffplans/tutorial/Filters.csv @@ -1,4 +1,4 @@ -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Element[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_RES,*string,~*req.Account,1001;1002;1003,2014-07-29T15:00:00Z cgrates.org,FLTR_DST_FS,*string,~*req.Account,1001,2014-07-29T15:00:00Z cgrates.org,FLTR_DST_FS,*destinations,~*req.Destination,DST_FS, diff --git a/data/tariffplans/tutorial2/Attributes.csv b/data/tariffplans/tutorial2/Attributes.csv index 66d04458c..bb841477c 100644 --- a/data/tariffplans/tutorial2/Attributes.csv +++ b/data/tariffplans/tutorial2/Attributes.csv @@ -1,11 +1,11 @@ -# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight +# Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight # ATTR_CRG_SUPPLIER1 replaces Category->supplier1 and RequestType->*constant for *sessions and *cdrs events -cgrates.org,ATTR_CRG_SUPPLIER1,*sessions;*cdrs,,,,Category,*constant,supplier1,false,0 -cgrates.org,ATTR_CRG_SUPPLIER1,,,,,RequestType,*constant,*rated,, +cgrates.org,ATTR_CRG_SUPPLIER1,*sessions;*cdrs,,,,*req.Category,*constant,supplier1,false,0 +cgrates.org,ATTR_CRG_SUPPLIER1,,,,,*req.RequestType,*constant,*rated,, # ATTR_1001_AUTH returns the Password value for the account 1001 in context -cgrates.org,ATTR_1001_AUTH,auth,*string:~*req.Account:1001,,,Password,*constant,CGRateS.org,false,20 +cgrates.org,ATTR_1001_AUTH,auth,*string:~*req.Account:1001,,,*req.Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1002_AUTH,auth,*string:~*req.Account:1002,,,Password,*constant,CGRateS.org,false,20 -cgrates.org,ATTR_1003_AUTH,auth,*string:~*req.Account:1003,,,Password,*constant,CGRateS.org,false,20 \ No newline at end of file +cgrates.org,ATTR_1002_AUTH,auth,*string:~*req.Account:1002,,,*req.Password,*constant,CGRateS.org,false,20 +cgrates.org,ATTR_1003_AUTH,auth,*string:~*req.Account:1003,,,*req.Password,*constant,CGRateS.org,false,20 \ No newline at end of file diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index 43c5e1296..77aa96f05 100755 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -142,7 +142,7 @@ func testDspAttrGetAttrFailover(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{}, - FieldName: "Password", + Path: utils.MetaReq + utils.NestingSep + "Password", Type: utils.META_CONSTANT, Value: config.NewRSRParsersMustCompile("CGRateS.org", true, utils.INFIELD_SEP), }, @@ -156,7 +156,7 @@ func testDspAttrGetAttrFailover(t *testing.T) { eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1002_SIMPLEAUTH"}, - AlteredFields: []string{"Password"}, + AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -332,7 +332,7 @@ func testDspAttrTestAuthKey2(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{}, - FieldName: "Password", + Path: utils.MetaReq + utils.NestingSep + "Password", Type: utils.META_CONSTANT, Value: config.NewRSRParsersMustCompile("CGRateS.org", true, utils.INFIELD_SEP), }, @@ -357,7 +357,7 @@ func testDspAttrTestAuthKey2(t *testing.T) { eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_SIMPLEAUTH"}, - AlteredFields: []string{"Password"}, + AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -423,7 +423,7 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{}, - FieldName: "Password", + Path: utils.MetaReq + utils.NestingSep + "Password", Type: utils.META_CONSTANT, Value: config.NewRSRParsersMustCompile("CGRateS.org", true, utils.INFIELD_SEP), }, @@ -437,7 +437,7 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1002_SIMPLEAUTH"}, - AlteredFields: []string{"Password"}, + AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -506,7 +506,7 @@ func testDspAttrGetAttrInternal(t *testing.T) { eRply := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1003_SIMPLEAUTH"}, - AlteredFields: []string{"Password"}, + AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", diff --git a/dispatchers/chargers_it_test.go b/dispatchers/chargers_it_test.go index 27a9e9f26..2973afa1a 100755 --- a/dispatchers/chargers_it_test.go +++ b/dispatchers/chargers_it_test.go @@ -133,7 +133,7 @@ func testDspCppGetChtgFailover(t *testing.T) { ID: "Raw", FilterIDs: []string{}, RunID: utils.MetaRaw, - AttributeIDs: []string{"*constant:RequestType:*none"}, + AttributeIDs: []string{"*constant:*req.RequestType:*none"}, Weight: 0, }, ) @@ -222,7 +222,7 @@ func testDspCppTestAuthKey2(t *testing.T) { ID: "Raw", FilterIDs: []string{}, RunID: utils.MetaRaw, - AttributeIDs: []string{"*constant:RequestType:*none"}, + AttributeIDs: []string{"*constant:*req.RequestType:*none"}, Weight: 0, }, } @@ -285,7 +285,7 @@ func testDspCppGetChtgRoundRobin(t *testing.T) { ID: "Raw", FilterIDs: []string{}, RunID: utils.MetaRaw, - AttributeIDs: []string{"*constant:RequestType:*none"}, + AttributeIDs: []string{"*constant:*req.RequestType:*none"}, Weight: 0, }, ) diff --git a/dispatchers/dispatchers_it_test.go b/dispatchers/dispatchers_it_test.go index ad59caaa8..a5c3327ec 100644 --- a/dispatchers/dispatchers_it_test.go +++ b/dispatchers/dispatchers_it_test.go @@ -61,7 +61,7 @@ func testDspApierSetAttributes(t *testing.T) { }, "Attributes": []*engine.Attribute{ { - FieldName: utils.Subject, + Path: utils.MetaReq + utils.NestingSep + utils.Subject, Value: config.RSRParsers{ &config.RSRParser{ Rules: "roam", @@ -95,7 +95,7 @@ func testDspApierGetAttributes(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, + Path: utils.MetaReq + utils.NestingSep + utils.Subject, Value: config.RSRParsers{ &config.RSRParser{ Rules: "roam", diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go index ea4bbd9f0..6d6f560ae 100755 --- a/dispatchers/sessions_it_test.go +++ b/dispatchers/sessions_it_test.go @@ -365,7 +365,7 @@ func testDspSessionUpdate(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItUpdateSession", @@ -432,7 +432,7 @@ func testDspSessionUpdate2(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_SESSIONAUTH"}, - AlteredFields: []string{"LCRProfile", "Password", "RequestType", "PaypalAccount"}, + AlteredFields: []string{"*req.LCRProfile", "*req.Password", "*req.RequestType", "*req.PaypalAccount"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItUpdateSession", @@ -581,7 +581,7 @@ func testDspSessionProcessEvent(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItProcessEvent", @@ -654,7 +654,7 @@ func testDspSessionProcessEvent2(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1001_SIMPLEAUTH"}, - AlteredFields: []string{"Password", "EventName"}, + AlteredFields: []string{"*req.Password", "*req.EventName"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItProcessEvent", diff --git a/docs/filters.rst b/docs/filters.rst index 9f6d4d6f4..5d0dc4ffc 100644 --- a/docs/filters.rst +++ b/docs/filters.rst @@ -35,7 +35,7 @@ Definition:: type FilterRule struct { Type string // Filter type - FieldName string // Name of the field providing us the Values to check (used in case of some ) + Element string // Name of the field providing us the Values to check (used in case of some ) Values []string // Filter definition } @@ -44,31 +44,31 @@ The matching logic of each FilterRule is given by it's type. The following types are implemented: -- *\*string* will match in full the *FieldName* with at least one value defined inside *Values*. Any of the values matching will have the FilterRule as *matched*. +- *\*string* will match in full the *Element* with at least one value defined inside *Values*. Any of the values matching will have the FilterRule as *matched*. - *\*notstring* is the negation of *\*string*. -- *\*prefix* will match at beginning of *FieldName* one of the values defined inside *Values*. +- *\*prefix* will match at beginning of *Element* one of the values defined inside *Values*. - *\*notprefix* is the negation of *\*prefix*. -- *\*suffix* will match at end of *FieldName* one of the values defined inside *Values*. +- *\*suffix* will match at end of *Element* one of the values defined inside *Values*. - *\*notsuffix* is the negation of *\*suffix*. -- *\*empty* will make sure that *FieldName* is empty or it does not exist in the event. +- *\*empty* will make sure that *Element* is empty or it does not exist in the event. - *\*notempty* is the negation of *\*empty*. -- *\*exists* will make sure that *FieldName* exists in the event. +- *\*exists* will make sure that *Element* exists in the event. - *\*notexists* is the negation of *\*exists*. -- *\*timings* will compare the time contained in *FieldName* with one of the TimingIDs defined in Values. +- *\*timings* will compare the time contained in *Element* with one of the TimingIDs defined in Values. - *\*nottimings* is the negation of *\*timings*. -- *\*destinations* will make sure that the *FieldName* is a prefix contained inside one of the destination IDs as *Values*. +- *\*destinations* will make sure that the *Element* is a prefix contained inside one of the destination IDs as *Values*. - *\*notdestinations* is the negation of *\*destinations*. @@ -76,7 +76,7 @@ The following types are implemented: - *\*notrsr* is the negation of *\*rsr*. -- *\*lt* (less than), *\*lte* (less than or equal), *\*gt* (greather than), *\*gte* (greather than or equal) are comparison operators and they pass if at least one of the values defined in *Values* are passing for the *FieldName* of event. The operators are able to compare string, float, int, time.Time, time.Duration, however both types need to be the same, otherwise the filter will raise *incomparable* as error. +- *\*lt* (less than), *\*lte* (less than or equal), *\*gt* (greather than), *\*gte* (greather than or equal) are comparison operators and they pass if at least one of the values defined in *Values* are passing for the *Element* of event. The operators are able to compare string, float, int, time.Time, time.Duration, however both types need to be the same, otherwise the filter will raise *incomparable* as error. Inline Filter diff --git a/docs/tariff_plans.rst b/docs/tariff_plans.rst index 9212af832..a4be2f063 100644 --- a/docs/tariff_plans.rst +++ b/docs/tariff_plans.rst @@ -860,13 +860,13 @@ TBD [0] - Tag TBD -[1] - FilterType +[1] - Type TBD -[2] - FilterFieldName +[2] - Element TBD -[3] - FilterFieldValues +[3] - Values TBD [4] - ActivationTime diff --git a/engine/action.go b/engine/action.go index d50b6352d..b509b4501 100644 --- a/engine/action.go +++ b/engine/action.go @@ -1000,7 +1000,7 @@ func removeSessionCosts(_ *Account, action *Action, _ Actions, _ interface{}) er continue } for _, rule := range fltr.Rules { - smcFilter, err = utils.AppendToSMCostFilter(smcFilter, rule.Type, rule.FieldName, rule.Values, config.CgrConfig().GeneralCfg().DefaultTimezone) + smcFilter, err = utils.AppendToSMCostFilter(smcFilter, rule.Type, rule.Element, rule.Values, config.CgrConfig().GeneralCfg().DefaultTimezone) if err != nil { utils.Logger.Warning(fmt.Sprintf("<%s> %s in action: <%s>", utils.Actions, err.Error(), utils.MetaRemoveSessionCosts)) } diff --git a/engine/attributes.go b/engine/attributes.go index 6078256fd..393deb7ed 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -22,6 +22,7 @@ import ( "fmt" "math" "strconv" + "strings" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" @@ -136,6 +137,7 @@ type AttrSProcessEventReply struct { // format fldName1:fldVal1,fldName2:fldVal2 func (attrReply *AttrSProcessEventReply) Digest() (rplyDigest string) { for i, fld := range attrReply.AlteredFields { + fld = strings.TrimPrefix(fld, utils.MetaReq+utils.NestingSep) if _, has := attrReply.CGREvent.Event[fld]; !has { continue //maybe removed } @@ -166,10 +168,9 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( } rply = &AttrSProcessEventReply{ MatchedProfiles: []string{attrPrf.ID}, - CGREvent: args.Clone(), + CGREvent: args.CGREvent, blocker: attrPrf.Blocker} - evNm := config.NewNavigableMap(nil) - evNm.Set([]string{utils.MetaReq}, args.Event, false, false) + evNm := config.NewNavigableMap(map[string]interface{}{utils.MetaReq: rply.CGREvent.Event}) for _, attribute := range attrPrf.Attributes { //in case that we have filter for attribute send them to FilterS to be processed if len(attribute.FilterIDs) != 0 { @@ -186,16 +187,16 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( case utils.META_CONSTANT: substitute, err = attribute.Value.ParseValue(utils.EmptyString) case utils.MetaVariable, utils.META_COMPOSED: - substitute, err = attribute.Value.ParseEvent(args.Event) + substitute, err = attribute.Value.ParseDataProvider(evNm, utils.NestingSep) case utils.META_USAGE_DIFFERENCE: if len(attribute.Value) != 2 { return nil, fmt.Errorf("invalid arguments <%s>", utils.ToJSON(attribute.Value)) } - strVal1, err := attribute.Value[0].ParseEvent(args.Event) + strVal1, err := attribute.Value[0].ParseDataProvider(evNm, utils.NestingSep) if err != nil { return nil, err } - strVal2, err := attribute.Value[1].ParseEvent(args.Event) + strVal2, err := attribute.Value[1].ParseDataProvider(evNm, utils.NestingSep) if err != nil { return nil, err } @@ -211,7 +212,7 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( case utils.MetaSum: iFaceVals := make([]interface{}, len(attribute.Value)) for i, val := range attribute.Value { - strVal, err := val.ParseEvent(args.Event) + strVal, err := val.ParseDataProvider(evNm, utils.NestingSep) if err != nil { return nil, err } @@ -227,7 +228,7 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( return nil, fmt.Errorf("invalid arguments <%s> to %s", utils.ToJSON(attribute.Value), utils.MetaValueExponent) } - strVal1, err := attribute.Value[0].ParseEvent(args.Event) // String Value + strVal1, err := attribute.Value[0].ParseDataProvider(evNm, utils.NestingSep) // String Value if err != nil { return nil, err } @@ -236,7 +237,7 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( return nil, fmt.Errorf("invalid value <%s> to %s", strVal1, utils.MetaValueExponent) } - strVal2, err := attribute.Value[1].ParseEvent(args.Event) // String Exponent + strVal2, err := attribute.Value[1].ParseDataProvider(evNm, utils.NestingSep) // String Exponent if err != nil { return nil, err } @@ -247,25 +248,34 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) ( substitute = strconv.FormatFloat(utils.Round(val*math.Pow10(exp), config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), 'f', -1, 64) default: // backwards compatible in case that Type is empty - substitute, err = attribute.Value.ParseEvent(args.Event) + substitute, err = attribute.Value.ParseDataProvider(evNm, utils.NestingSep) } if err != nil { return nil, err } - //add only once the FieldName in AlteredFields - if !utils.IsSliceMember(rply.AlteredFields, attribute.FieldName) { - rply.AlteredFields = append(rply.AlteredFields, attribute.FieldName) + //add only once the Path in AlteredFields + if !utils.IsSliceMember(rply.AlteredFields, attribute.Path) { + rply.AlteredFields = append(rply.AlteredFields, attribute.Path) + } + if attribute.Path == utils.MetaTenant { + if attribute.Type == utils.META_COMPOSED { + rply.CGREvent.Tenant += substitute + } else { + rply.CGREvent.Tenant = substitute + } + continue } if substitute == utils.MetaRemove { - delete(rply.CGREvent.Event, attribute.FieldName) + evNm.Remove(strings.Split(attribute.Path, utils.NestingSep)) continue } if attribute.Type == utils.META_COMPOSED { - substitute = utils.IfaceAsString(rply.CGREvent.Event[attribute.FieldName]) + substitute + var val string + val, err = evNm.FieldAsString(strings.Split(attribute.Path, utils.NestingSep)) + substitute = val + substitute } - rply.CGREvent.Event[attribute.FieldName] = substitute - + evNm.Set(strings.Split(attribute.Path, utils.NestingSep), substitute, false, false) } return } @@ -300,6 +310,7 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, args.ProcessRuns = utils.IntPointer(alS.cgrcfg.AttributeSCfg().ProcessRuns) } var apiRply *AttrSProcessEventReply // aggregate response here + args.CGREvent = args.CGREvent.Clone() for i := 0; i < *args.ProcessRuns; i++ { var evRply *AttrSProcessEventReply evRply, err = alS.processEvent(args) @@ -311,9 +322,6 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, } break } - if len(evRply.AlteredFields) != 0 { - args.CGREvent = evRply.CGREvent // for next loop - } if apiRply == nil { // first reply apiRply = evRply if apiRply.blocker { @@ -328,10 +336,9 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, apiRply.MatchedProfiles = append(apiRply.MatchedProfiles, evRply.MatchedProfiles[0]) apiRply.CGREvent = evRply.CGREvent for _, fldName := range evRply.AlteredFields { - if utils.IsSliceMember(apiRply.AlteredFields, fldName) { - continue // only add processed fieldName once + if !utils.IsSliceMember(apiRply.AlteredFields, fldName) { + apiRply.AlteredFields = append(apiRply.AlteredFields, fldName) // only add processed fieldName once } - apiRply.AlteredFields = append(apiRply.AlteredFields, fldName) } if evRply.blocker { break diff --git a/engine/attributes_test.go b/engine/attributes_test.go index d7d88ca43..ecca46bd2 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -87,8 +87,8 @@ var ( }, Attributes: []*Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -104,8 +104,8 @@ var ( }, Attributes: []*Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -121,8 +121,8 @@ var ( }, Attributes: []*Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -138,8 +138,8 @@ var ( }, Attributes: []*Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -167,19 +167,19 @@ func TestAttributeAddFilters(t *testing.T) { ID: "FLTR_ATTR_1", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Attribute", - Values: []string{"AttributeProfile1"}, + Type: utils.MetaString, + Element: "~*req.Attribute", + Values: []string{"AttributeProfile1"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.UsageInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.UsageInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req." + utils.Weight, - Values: []string{"9.0"}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req." + utils.Weight, + Values: []string{"9.0"}, }, }, } @@ -189,9 +189,9 @@ func TestAttributeAddFilters(t *testing.T) { ID: "FLTR_ATTR_2", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Attribute", - Values: []string{"AttributeProfile2"}, + Type: utils.MetaString, + Element: "~*req.Attribute", + Values: []string{"AttributeProfile2"}, }, }, } @@ -201,9 +201,9 @@ func TestAttributeAddFilters(t *testing.T) { ID: "FLTR_ATTR_3", Rules: []*FilterRule{ { - Type: utils.MetaPrefix, - FieldName: "~*req.Attribute", - Values: []string{"AttributeProfilePrefix"}, + Type: utils.MetaPrefix, + Element: "~*req.Attribute", + Values: []string{"AttributeProfilePrefix"}, }, }, } @@ -213,9 +213,9 @@ func TestAttributeAddFilters(t *testing.T) { ID: "FLTR_ATTR_4", Rules: []*FilterRule{ { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req." + utils.Weight, - Values: []string{"200.00"}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req." + utils.Weight, + Values: []string{"200.00"}, }, }, } @@ -269,7 +269,7 @@ func TestAttributeProcessEvent(t *testing.T) { attrEvs[0].CGREvent.Event["Account"] = "1010" //Field added in event after process eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"AttributeProfile1"}, - AlteredFields: []string{"Account"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Account"}, CGREvent: attrEvs[0].CGREvent, } atrp, err := attrService.processEvent(attrEvs[0]) @@ -293,7 +293,7 @@ func TestAttributeProcessEventWithIDs(t *testing.T) { attrEvs[3].AttributeIDs = []string{"AttributeIDMatch"} eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"AttributeIDMatch"}, - AlteredFields: []string{"Account"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Account"}, CGREvent: attrEvs[3].CGREvent, } if atrp, err := attrService.processEvent(attrEvs[3]); err != nil { @@ -347,7 +347,7 @@ func TestAttributeEventReplyDigest2(t *testing.T) { func TestAttributeEventReplyDigest3(t *testing.T) { eRpl := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Subject"}, + AlteredFields: []string{"*req.Subject"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -368,7 +368,7 @@ func TestAttributeEventReplyDigest3(t *testing.T) { func TestAttributeEventReplyDigest4(t *testing.T) { eRpl := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Subject"}, + AlteredFields: []string{"*req.Subject"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -406,8 +406,8 @@ func TestAttributeIndexer(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: utils.Account, - Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Value: config.NewRSRParsersMustCompile("1010", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -474,8 +474,8 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -490,8 +490,8 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -506,8 +506,8 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -535,7 +535,11 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_3"}, - AlteredFields: []string{"Field1", "Field2", "Field3"}, + AlteredFields: []string{ + utils.MetaReq + utils.NestingSep + "Field1", + utils.MetaReq + utils.NestingSep + "Field2", + utils.MetaReq + utils.NestingSep + "Field3", + }, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -552,7 +556,7 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { - t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) + t.Fatalf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) } if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) { t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields) @@ -582,8 +586,8 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -598,8 +602,8 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -614,8 +618,8 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -643,7 +647,8 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, - AlteredFields: []string{"Field1", "Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1", + utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -689,8 +694,8 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -705,8 +710,8 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -721,8 +726,8 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -750,7 +755,8 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, - AlteredFields: []string{"Field1", "Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1", + utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -796,8 +802,8 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -812,8 +818,8 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -838,7 +844,8 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, - AlteredFields: []string{"Field1", "Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1", + utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -886,8 +893,8 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Weight: 10, @@ -902,8 +909,8 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -919,8 +926,8 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -948,7 +955,8 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, - AlteredFields: []string{"Field1", "Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1", + utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -995,8 +1003,8 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field1", - Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field1", + Value: config.NewRSRParsersMustCompile("Value1", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1012,8 +1020,8 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("Value2", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1028,8 +1036,8 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field3", - Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field3", + Value: config.NewRSRParsersMustCompile("Value3", true, utils.INFIELD_SEP), }, }, Weight: 30, @@ -1057,7 +1065,7 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field1"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1103,8 +1111,8 @@ func TestAttributeProcessValue(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Value: config.NewRSRParsersMustCompile("~Field1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Value: config.NewRSRParsersMustCompile("~*req.Field1", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1127,7 +1135,7 @@ func TestAttributeProcessValue(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1173,17 +1181,17 @@ func TestAttributeAttributeFilterIDs(t *testing.T) { Attributes: []*Attribute{ { FilterIDs: []string{"*string:~*req.PassField:Test"}, - FieldName: "PassField", + Path: utils.MetaReq + utils.NestingSep + "PassField", Value: config.NewRSRParsersMustCompile("Pass", true, utils.INFIELD_SEP), }, { FilterIDs: []string{"*string:~*req.PassField:RandomValue"}, - FieldName: "NotPassField", + Path: utils.MetaReq + utils.NestingSep + "NotPassField", Value: config.NewRSRParsersMustCompile("NotPass", true, utils.INFIELD_SEP), }, { FilterIDs: []string{"*notexists:~*req.RandomField:"}, - FieldName: "RandomField", + Path: utils.MetaReq + utils.NestingSep + "RandomField", Value: config.NewRSRParsersMustCompile("RandomValue", true, utils.INFIELD_SEP), }, }, @@ -1206,7 +1214,8 @@ func TestAttributeAttributeFilterIDs(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"PassField", "RandomField"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "PassField", + utils.MetaReq + utils.NestingSep + "RandomField"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1252,9 +1261,9 @@ func TestAttributeProcessEventConstant(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.META_CONSTANT, - Value: config.NewRSRParsersMustCompile("ConstVal", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile("ConstVal", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1277,7 +1286,7 @@ func TestAttributeProcessEventConstant(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1323,14 +1332,14 @@ func TestAttributeProcessEventVariable(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("~Field1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("~*req.Field1", true, utils.INFIELD_SEP), }, { - FieldName: "Field2", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("~TheField", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("~*req.TheField", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1354,7 +1363,7 @@ func TestAttributeProcessEventVariable(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1401,19 +1410,19 @@ func TestAttributeProcessEventComposed(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.META_COMPOSED, - Value: config.NewRSRParsersMustCompile("~Field1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.META_COMPOSED, + Value: config.NewRSRParsersMustCompile("~*req.Field1", true, utils.INFIELD_SEP), }, { - FieldName: "Field2", - Type: utils.META_COMPOSED, - Value: config.NewRSRParsersMustCompile("_", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.META_COMPOSED, + Value: config.NewRSRParsersMustCompile("_", true, utils.INFIELD_SEP), }, { - FieldName: "Field2", - Type: utils.META_COMPOSED, - Value: config.NewRSRParsersMustCompile("~TheField", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.META_COMPOSED, + Value: config.NewRSRParsersMustCompile("~*req.TheField", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1437,7 +1446,7 @@ func TestAttributeProcessEventComposed(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1484,9 +1493,9 @@ func TestAttributeProcessEventSum(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.MetaSum, - Value: config.NewRSRParsersMustCompile("10;~NumField;20", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaSum, + Value: config.NewRSRParsersMustCompile("10;~*req.NumField;20", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1511,7 +1520,7 @@ func TestAttributeProcessEventSum(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1559,9 +1568,9 @@ func TestAttributeProcessEventUsageDifference(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.META_USAGE_DIFFERENCE, - Value: config.NewRSRParsersMustCompile("~UnixTimeStamp;~UnixTimeStamp2", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.META_USAGE_DIFFERENCE, + Value: config.NewRSRParsersMustCompile("~*req.UnixTimeStamp;~*req.UnixTimeStamp2", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1587,7 +1596,7 @@ func TestAttributeProcessEventUsageDifference(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1636,9 +1645,9 @@ func TestAttributeProcessEventValueExponent(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.MetaValueExponent, - Value: config.NewRSRParsersMustCompile("~Multiplier;~Pow", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaValueExponent, + Value: config.NewRSRParsersMustCompile("~*req.Multiplier;~*req.Pow", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1664,7 +1673,7 @@ func TestAttributeProcessEventValueExponent(t *testing.T) { } eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_1"}, - AlteredFields: []string{"Field2"}, + AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1721,9 +1730,9 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.META_CONSTANT, - Value: config.NewRSRParsersMustCompile("ConstVal", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile("ConstVal", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1782,9 +1791,9 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) { }, Attributes: []*Attribute{ { - FieldName: "Field2", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("~Field1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("~*req.Field1", true, utils.INFIELD_SEP), }, }, Blocker: true, @@ -1825,15 +1834,15 @@ func TestGetAttributeProfileFromInline(t *testing.T) { } else if test != true { t.Errorf("\nExpecting: true got :%+v", test) } - attrID := "*sum:Field2:10;~NumField;20" + attrID := "*sum:*req.Field2:10;~*req.NumField;20" expAttrPrf1 := &AttributeProfile{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: attrID, Contexts: []string{utils.META_ANY}, Attributes: []*Attribute{&Attribute{ - FieldName: "Field2", - Type: utils.MetaSum, - Value: config.NewRSRParsersMustCompile("10;~NumField;20", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaSum, + Value: config.NewRSRParsersMustCompile("10;~*req.NumField;20", true, utils.INFIELD_SEP), }}, } attr, err := dm.GetAttributeProfile(config.CgrConfig().GeneralCfg().DefaultTenant, attrID, false, false, "") diff --git a/engine/cdr.go b/engine/cdr.go index 9f09fe104..dc027bfc7 100644 --- a/engine/cdr.go +++ b/engine/cdr.go @@ -23,6 +23,7 @@ import ( "fmt" "math" "strconv" + "strings" "time" "github.com/cgrates/cgrates/config" @@ -537,6 +538,7 @@ func (cdr *CDR) AsCGREvent() *utils.CGREvent { // UpdateFromCGREvent will update CDR with event fields from CGREvent func (cdr *CDR) UpdateFromCGREvent(cgrEv *utils.CGREvent, fields []string) (err error) { for _, fldName := range fields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if _, has := cgrEv.Event[fldName]; !has { continue //maybe removed } diff --git a/engine/cdrs.go b/engine/cdrs.go index 0d263bac3..dcbd111b0 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -344,11 +344,6 @@ func (cdrS *CDRServer) attrSProcessEvent(cgrEv *utils.CGREventWithArgDispatcher) utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 { cgrEv.CGREvent = rplyEv.CGREvent - if tntIface, has := cgrEv.CGREvent.Event[utils.MetaTenant]; has { - // special case when we want to overwrite the tenant - cgrEv.CGREvent.Tenant = tntIface.(string) - delete(cgrEv.CGREvent.Event, utils.MetaTenant) - } } else if err.Error() == utils.ErrNotFound.Error() { err = nil // cancel ErrNotFound } diff --git a/engine/chargers_test.go b/engine/chargers_test.go index 2056a327b..9a612cd11 100755 --- a/engine/chargers_test.go +++ b/engine/chargers_test.go @@ -117,14 +117,14 @@ func TestChargerAddFilter(t *testing.T) { ID: "FLTR_CP_1", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Charger", - Values: []string{"ChargerProfile1"}, + Type: utils.MetaString, + Element: "~*req.Charger", + Values: []string{"ChargerProfile1"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.UsageInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.UsageInterval", + Values: []string{(1 * time.Second).String()}, }, }, } @@ -134,9 +134,9 @@ func TestChargerAddFilter(t *testing.T) { ID: "FLTR_CP_2", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Charger", - Values: []string{"ChargerProfile2"}, + Type: utils.MetaString, + Element: "~*req.Charger", + Values: []string{"ChargerProfile2"}, }, }, } @@ -146,9 +146,9 @@ func TestChargerAddFilter(t *testing.T) { ID: "FLTR_CP_3", Rules: []*FilterRule{ { - Type: utils.MetaPrefix, - FieldName: "~*req.harger", - Values: []string{"Charger"}, + Type: utils.MetaPrefix, + Element: "~*req.harger", + Values: []string{"Charger"}, }, }, } @@ -158,9 +158,9 @@ func TestChargerAddFilter(t *testing.T) { ID: "FLTR_CP_4", Rules: []*FilterRule{ { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"200.00"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"200.00"}, }, }, } diff --git a/engine/filterindexer.go b/engine/filterindexer.go index 963e4c3c2..c5d7a960f 100644 --- a/engine/filterindexer.go +++ b/engine/filterindexer.go @@ -49,7 +49,7 @@ func (rfi *FilterIndexer) IndexTPFilter(tpFltr *utils.TPFilterProfile, itemID st switch fltr.Type { case utils.MetaString: for _, fldVal := range fltr.Values { - concatKey := utils.ConcatenatedKey(fltr.Type, fltr.FieldName, fldVal) + concatKey := utils.ConcatenatedKey(fltr.Type, fltr.Element, fldVal) if _, hasIt := rfi.indexes[concatKey]; !hasIt { rfi.indexes[concatKey] = make(utils.StringMap) } @@ -58,7 +58,7 @@ func (rfi *FilterIndexer) IndexTPFilter(tpFltr *utils.TPFilterProfile, itemID st } case utils.MetaPrefix: for _, fldVal := range fltr.Values { - concatKey := utils.ConcatenatedKey(fltr.Type, fltr.FieldName, fldVal) + concatKey := utils.ConcatenatedKey(fltr.Type, fltr.Element, fldVal) if _, hasIt := rfi.indexes[concatKey]; !hasIt { rfi.indexes[concatKey] = make(utils.StringMap) } @@ -232,9 +232,9 @@ func (rfi *FilterIndexer) RemoveItemFromIndex(tenant, itemID string, oldFilters ID: itemID, Rules: []*FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -250,7 +250,7 @@ func (rfi *FilterIndexer) RemoveItemFromIndex(tenant, itemID string, oldFilters var fldType, fldName string var fldVals []string if utils.SliceHasMember([]string{utils.META_NONE, utils.MetaPrefix, utils.MetaString}, flt.Type) { - fldType, fldName = flt.Type, flt.FieldName + fldType, fldName = flt.Type, flt.Element fldVals = flt.Values } for _, fldVal := range fldVals { @@ -293,9 +293,9 @@ func createAndIndex(itemPrefix, tenant, context, itemID string, filterIDs []stri ID: itemID, Rules: []*FilterRule{ { - Type: utils.META_NONE, - FieldName: utils.META_ANY, - Values: []string{utils.META_ANY}, + Type: utils.META_NONE, + Element: utils.META_ANY, + Values: []string{utils.META_ANY}, }, }, } @@ -311,7 +311,7 @@ func createAndIndex(itemPrefix, tenant, context, itemID string, filterIDs []stri var fldType, fldName string var fldVals []string if utils.SliceHasMember([]string{utils.META_NONE, utils.MetaPrefix, utils.MetaString}, flt.Type) { - fldType, fldName = flt.Type, flt.FieldName + fldType, fldName = flt.Type, flt.Element fldVals = flt.Values } for _, fldVal := range fldVals { diff --git a/engine/filterindexer_it_test.go b/engine/filterindexer_it_test.go index b732807e6..21ded98f6 100644 --- a/engine/filterindexer_it_test.go +++ b/engine/filterindexer_it_test.go @@ -225,9 +225,9 @@ func testITTestThresholdFilterIndexes(t *testing.T) { ID: "Filter1", Rules: []*FilterRule{ { - FieldName: "EventType", - Type: "*string", - Values: []string{"Event1", "Event2"}, + Element: "EventType", + Type: utils.MetaString, + Values: []string{"Event1", "Event2"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -292,9 +292,9 @@ func testITTestThresholdFilterIndexes(t *testing.T) { ID: "Filter2", Rules: []*FilterRule{ { - FieldName: "Account", - Type: "*string", - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -339,9 +339,9 @@ func testITTestThresholdFilterIndexes(t *testing.T) { ID: "Filter3", Rules: []*FilterRule{ { - FieldName: "Destination", - Type: "*string", - Values: []string{"10", "20"}, + Element: "Destination", + Type: utils.MetaString, + Values: []string{"10", "20"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -405,9 +405,9 @@ func testITTestAttributeProfileFilterIndexes(t *testing.T) { ID: "AttrFilter", Rules: []*FilterRule{ { - FieldName: "EventType", - Type: "*string", - Values: []string{"Event1", "Event2"}, + Element: "EventType", + Type: utils.MetaString, + Values: []string{"Event1", "Event2"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -428,8 +428,8 @@ func testITTestAttributeProfileFilterIndexes(t *testing.T) { Contexts: []string{"con1", "con2"}, Attributes: []*Attribute{ { - FieldName: "FN1", - Value: config.NewRSRParsersMustCompile("Val1", true, utils.INFIELD_SEP), + Path: "FN1", + Value: config.NewRSRParsersMustCompile("Val1", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -505,9 +505,9 @@ func testITTestThresholdInlineFilterIndexing(t *testing.T) { ID: "Filter1", Rules: []*FilterRule{ { - FieldName: "EventType", - Type: "*string", - Values: []string{"Event1", "Event2"}, + Element: "EventType", + Type: utils.MetaString, + Values: []string{"Event1", "Event2"}, }, }, ActivationInterval: &utils.ActivationInterval{ diff --git a/engine/filters.go b/engine/filters.go index 784fba526..ff2fd760b 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -25,6 +25,7 @@ import ( "github.com/cgrates/cgrates/utils" ) +// NewFilterS initializtes the filter service func NewFilterS(cfg *config.CGRConfig, connMgr *ConnManager, dm *DataManager) (fS *FilterS) { fS = &FilterS{ dm: dm, @@ -67,7 +68,7 @@ func (fS *FilterS) Pass(tenant string, filterIDs []string, continue } for _, fltr := range f.Rules { - fieldNameDP, err = fS.getFieldNameDataProvider(ev, fltr.FieldName, tenant) + fieldNameDP, err = fS.getFieldNameDataProvider(ev, fltr.Element, tenant) if err != nil { return pass, err } @@ -94,9 +95,9 @@ func NewFilterFromInline(tenant, inlnRule string) (f *Filter, err error) { Tenant: tenant, ID: inlnRule, Rules: []*FilterRule{{ - Type: ruleSplt[0], - FieldName: ruleSplt[1], - Values: strings.Split(strings.Join(ruleSplt[2:], utils.InInFieldSep), utils.INFIELD_SEP), + Type: ruleSplt[0], + Element: ruleSplt[1], + Values: strings.Split(strings.Join(ruleSplt[2:], utils.InInFieldSep), utils.INFIELD_SEP), }}, } if err = f.Compile(); err != nil { @@ -105,6 +106,7 @@ func NewFilterFromInline(tenant, inlnRule string) (f *Filter, err error) { return } +// Filter structure to define a basic filter type Filter struct { Tenant string ID string @@ -112,13 +114,14 @@ type Filter struct { ActivationInterval *utils.ActivationInterval } -func (flt *Filter) TenantID() string { - return utils.ConcatenatedKey(flt.Tenant, flt.ID) +// TenantID returns the tenant wit the ID +func (fltr *Filter) TenantID() string { + return utils.ConcatenatedKey(fltr.Tenant, fltr.ID) } // Compile will compile the underlaying request filters where necessary (ie. regexp rules) -func (f *Filter) Compile() (err error) { - for _, rf := range f.Rules { +func (fltr *Filter) Compile() (err error) { + for _, rf := range fltr.Rules { if err = rf.CompileValues(); err != nil { return } @@ -140,6 +143,7 @@ var needsValues *utils.StringSet = utils.NewStringSet([]string{utils.MetaString, utils.MetaLessThan, utils.MetaLessOrEqual, utils.MetaGreaterThan, utils.MetaGreaterOrEqual, utils.MetaEqual, utils.MetaNotEqual}) +// NewFilterRule returns a new filter func NewFilterRule(rfType, fieldName string, vals []string) (*FilterRule, error) { var negative bool rType := rfType @@ -151,16 +155,16 @@ func NewFilterRule(rfType, fieldName string, vals []string) (*FilterRule, error) return nil, fmt.Errorf("Unsupported filter Type: %s", rfType) } if fieldName == "" && needsFieldName.Has(rType) { - return nil, fmt.Errorf("FieldName is mandatory for Type: %s", rfType) + return nil, fmt.Errorf("Element is mandatory for Type: %s", rfType) } if len(vals) == 0 && needsValues.Has(rType) { return nil, fmt.Errorf("Values is mandatory for Type: %s", rfType) } rf := &FilterRule{ - Type: rfType, - FieldName: fieldName, - Values: vals, - negative: utils.BoolPointer(negative), + Type: rfType, + Element: fieldName, + Values: vals, + negative: utils.BoolPointer(negative), } if err := rf.CompileValues(); err != nil { return nil, err @@ -172,17 +176,17 @@ func NewFilterRule(rfType, fieldName string, vals []string) (*FilterRule, error) // Pass rule: default negative, one mathing rule should pass the filter type FilterRule struct { Type string // Filter type (*string, *timing, *rsr_filters, *stats, *lt, *lte, *gt, *gte) - FieldName string // Name of the field providing us the Values to check (used in case of some ) + Element string // Name of the field providing us the Values to check (used in case of some ) Values []string // Filter definition rsrFields config.RSRParsers // Cache here the RSRFilter Values negative *bool } -// Separate method to compile RSR fields -func (rf *FilterRule) CompileValues() (err error) { - switch rf.Type { +// CompileValues compiles RSR fields +func (fltr *FilterRule) CompileValues() (err error) { + switch fltr.Type { case utils.MetaRSR, utils.MetaNotRSR: - if rf.rsrFields, err = config.NewRSRParsersFromSlice(rf.Values, true); err != nil { + if fltr.rsrFields, err = config.NewRSRParsersFromSlice(fltr.Values, true); err != nil { return } } @@ -227,7 +231,7 @@ func (fltr *FilterRule) Pass(fieldNameDP config.DataProvider, } func (fltr *FilterRule) passString(fielNameDP config.DataProvider, fieldValuesDP []config.DataProvider) (bool, error) { - strVal, err := config.DPDynamicString(fltr.FieldName, fielNameDP) + strVal, err := config.DPDynamicString(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil @@ -247,7 +251,7 @@ func (fltr *FilterRule) passString(fielNameDP config.DataProvider, fieldValuesDP } func (fltr *FilterRule) passExists(fielNameDP config.DataProvider) (bool, error) { - _, err := config.DPDynamicInterface(fltr.FieldName, fielNameDP) + _, err := config.DPDynamicInterface(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil @@ -258,7 +262,7 @@ func (fltr *FilterRule) passExists(fielNameDP config.DataProvider) (bool, error) } func (fltr *FilterRule) passEmpty(fielNameDP config.DataProvider) (bool, error) { - val, err := config.DPDynamicInterface(fltr.FieldName, fielNameDP) + val, err := config.DPDynamicInterface(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return true, nil @@ -288,7 +292,7 @@ func (fltr *FilterRule) passEmpty(fielNameDP config.DataProvider) (bool, error) } func (fltr *FilterRule) passStringPrefix(fielNameDP config.DataProvider, fieldValuesDP []config.DataProvider) (bool, error) { - strVal, err := config.DPDynamicString(fltr.FieldName, fielNameDP) + strVal, err := config.DPDynamicString(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil @@ -308,7 +312,7 @@ func (fltr *FilterRule) passStringPrefix(fielNameDP config.DataProvider, fieldVa } func (fltr *FilterRule) passStringSuffix(fielNameDP config.DataProvider, fieldValuesDP []config.DataProvider) (bool, error) { - strVal, err := config.DPDynamicString(fltr.FieldName, fielNameDP) + strVal, err := config.DPDynamicString(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil @@ -333,7 +337,7 @@ func (fltr *FilterRule) passTimings(fielNameDP config.DataProvider, fieldValuesD } func (fltr *FilterRule) passDestinations(fielNameDP config.DataProvider, fieldValuesDP []config.DataProvider) (bool, error) { - dst, err := config.DPDynamicString(fltr.FieldName, fielNameDP) + dst, err := config.DPDynamicString(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil @@ -370,7 +374,7 @@ func (fltr *FilterRule) passRSR(fieldValuesDP []config.DataProvider) (bool, erro } func (fltr *FilterRule) passGreaterThan(fielNameDP config.DataProvider, fieldValuesDP []config.DataProvider) (bool, error) { - fldIf, err := config.DPDynamicInterface(fltr.FieldName, fielNameDP) + fldIf, err := config.DPDynamicInterface(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil @@ -402,7 +406,7 @@ func (fltr *FilterRule) passGreaterThan(fielNameDP config.DataProvider, fieldVal } func (fltr *FilterRule) passEqualTo(fielNameDP config.DataProvider, fieldValuesDP []config.DataProvider) (bool, error) { - fldIf, err := config.DPDynamicInterface(fltr.FieldName, fielNameDP) + fldIf, err := config.DPDynamicInterface(fltr.Element, fielNameDP) if err != nil { if err == utils.ErrNotFound { return false, nil diff --git a/engine/filters_test.go b/engine/filters_test.go index f8f1c0975..806a30393 100644 --- a/engine/filters_test.go +++ b/engine/filters_test.go @@ -35,14 +35,14 @@ func TestFilterPassString(t *testing.T) { ExtraFields: map[string]string{"navigation": "off"}, } rf := &FilterRule{Type: utils.MetaString, - FieldName: "~Category", Values: []string{"call"}} + Element: "~Category", Values: []string{"call"}} if passes, err := rf.passString(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } rf = &FilterRule{Type: utils.MetaString, - FieldName: "~Category", Values: []string{"cal"}} + Element: "~Category", Values: []string{"cal"}} if passes, err := rf.passString(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { @@ -50,14 +50,14 @@ func TestFilterPassString(t *testing.T) { } //not rf = &FilterRule{Type: utils.MetaNotString, - FieldName: "~Category", Values: []string{"call"}} + Element: "~Category", Values: []string{"call"}} if passes, err := rf.Pass(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { t.Error("Filter passes") } rf = &FilterRule{Type: utils.MetaNotString, - FieldName: "~Category", Values: []string{"cal"}} + Element: "~Category", Values: []string{"cal"}} if passes, err := rf.Pass(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { @@ -76,27 +76,27 @@ func TestFilterPassEmpty(t *testing.T) { DurationIndex: 132 * time.Second, ExtraFields: map[string]string{"navigation": "off"}, } - rf := &FilterRule{Type: utils.MetaEmpty, FieldName: "~Category", Values: []string{}} + rf := &FilterRule{Type: utils.MetaEmpty, Element: "~Category", Values: []string{}} if passes, err := rf.passEmpty(cd); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaEmpty, FieldName: "~ExtraFields", Values: []string{}} + rf = &FilterRule{Type: utils.MetaEmpty, Element: "~ExtraFields", Values: []string{}} if passes, err := rf.passEmpty(cd); err != nil { t.Error(err) } else if passes { t.Error("Filter passes") } cd.ExtraFields = map[string]string{} - rf = &FilterRule{Type: utils.MetaEmpty, FieldName: "~ExtraFields", Values: []string{}} + rf = &FilterRule{Type: utils.MetaEmpty, Element: "~ExtraFields", Values: []string{}} if passes, err := rf.passEmpty(cd); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } //not - rf = &FilterRule{Type: utils.MetaNotEmpty, FieldName: "~Category", Values: []string{}} + rf = &FilterRule{Type: utils.MetaNotEmpty, Element: "~Category", Values: []string{}} if passes, err := rf.Pass(cd, []config.DataProvider{}); err != nil { t.Error(err) } else if passes { @@ -115,27 +115,27 @@ func TestFilterPassExists(t *testing.T) { DurationIndex: 132 * time.Second, ExtraFields: map[string]string{"navigation": "off"}, } - rf := &FilterRule{Type: utils.MetaExists, FieldName: "~Category", Values: []string{}} + rf := &FilterRule{Type: utils.MetaExists, Element: "~Category", Values: []string{}} if passes, err := rf.passExists(cd); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaExists, FieldName: "~ExtraFields1", Values: []string{}} + rf = &FilterRule{Type: utils.MetaExists, Element: "~ExtraFields1", Values: []string{}} if passes, err := rf.passExists(cd); err != nil { t.Error(err) } else if passes { t.Error("Filter passes") } cd.ExtraFields = map[string]string{} - rf = &FilterRule{Type: utils.MetaExists, FieldName: "~ExtraFields", Values: []string{}} + rf = &FilterRule{Type: utils.MetaExists, Element: "~ExtraFields", Values: []string{}} if passes, err := rf.passExists(cd); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } //not - rf = &FilterRule{Type: utils.MetaNotExists, FieldName: "~Category1", Values: []string{}} + rf = &FilterRule{Type: utils.MetaNotExists, Element: "~Category1", Values: []string{}} if passes, err := rf.Pass(cd, []config.DataProvider{}); err != nil { t.Error(err) } else if !passes { @@ -154,44 +154,44 @@ func TestFilterPassStringPrefix(t *testing.T) { DurationIndex: 132 * time.Second, ExtraFields: map[string]string{"navigation": "off"}, } - rf := &FilterRule{Type: utils.MetaPrefix, FieldName: "~Category", Values: []string{"call"}} + rf := &FilterRule{Type: utils.MetaPrefix, Element: "~Category", Values: []string{"call"}} if passes, err := rf.passStringPrefix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaPrefix, FieldName: "~Category", Values: []string{"premium"}} + rf = &FilterRule{Type: utils.MetaPrefix, Element: "~Category", Values: []string{"premium"}} if passes, err := rf.passStringPrefix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { t.Error("Passes filter") } - rf = &FilterRule{Type: utils.MetaPrefix, FieldName: "~Destination", Values: []string{"+49"}} + rf = &FilterRule{Type: utils.MetaPrefix, Element: "~Destination", Values: []string{"+49"}} if passes, err := rf.passStringPrefix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaPrefix, FieldName: "~Destination", Values: []string{"+499"}} + rf = &FilterRule{Type: utils.MetaPrefix, Element: "~Destination", Values: []string{"+499"}} if passes, err := rf.passStringPrefix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { t.Error("Passes filter") } - rf = &FilterRule{Type: utils.MetaPrefix, FieldName: "~navigation", Values: []string{"off"}} + rf = &FilterRule{Type: utils.MetaPrefix, Element: "~navigation", Values: []string{"off"}} if passes, err := rf.passStringPrefix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaPrefix, FieldName: "~nonexisting", Values: []string{"off"}} + rf = &FilterRule{Type: utils.MetaPrefix, Element: "~nonexisting", Values: []string{"off"}} if passing, err := rf.passStringPrefix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passing { t.Error("Passes filter") } //not - rf = &FilterRule{Type: utils.MetaNotPrefix, FieldName: "~Category", Values: []string{"premium"}} + rf = &FilterRule{Type: utils.MetaNotPrefix, Element: "~Category", Values: []string{"premium"}} if passes, err := rf.Pass(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { @@ -210,44 +210,44 @@ func TestFilterPassStringSuffix(t *testing.T) { DurationIndex: 132 * time.Second, ExtraFields: map[string]string{"navigation": "off"}, } - rf := &FilterRule{Type: utils.MetaSuffix, FieldName: "~Category", Values: []string{"call"}} + rf := &FilterRule{Type: utils.MetaSuffix, Element: "~Category", Values: []string{"call"}} if passes, err := rf.passStringSuffix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaSuffix, FieldName: "~Category", Values: []string{"premium"}} + rf = &FilterRule{Type: utils.MetaSuffix, Element: "~Category", Values: []string{"premium"}} if passes, err := rf.passStringSuffix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { t.Error("Passes filter") } - rf = &FilterRule{Type: utils.MetaSuffix, FieldName: "~Destination", Values: []string{"963"}} + rf = &FilterRule{Type: utils.MetaSuffix, Element: "~Destination", Values: []string{"963"}} if passes, err := rf.passStringSuffix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaSuffix, FieldName: "~Destination", Values: []string{"4966"}} + rf = &FilterRule{Type: utils.MetaSuffix, Element: "~Destination", Values: []string{"4966"}} if passes, err := rf.passStringSuffix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { t.Error("Passes filter") } - rf = &FilterRule{Type: utils.MetaSuffix, FieldName: "~navigation", Values: []string{"off"}} + rf = &FilterRule{Type: utils.MetaSuffix, Element: "~navigation", Values: []string{"off"}} if passes, err := rf.passStringSuffix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if !passes { t.Error("Not passes filter") } - rf = &FilterRule{Type: utils.MetaSuffix, FieldName: "~nonexisting", Values: []string{"off"}} + rf = &FilterRule{Type: utils.MetaSuffix, Element: "~nonexisting", Values: []string{"off"}} if passing, err := rf.passStringSuffix(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passing { t.Error("Passes filter") } //not - rf = &FilterRule{Type: utils.MetaNotSuffix, FieldName: "~Destination", Values: []string{"963"}} + rf = &FilterRule{Type: utils.MetaNotSuffix, Element: "~Destination", Values: []string{"963"}} if passes, err := rf.Pass(cd, []config.DataProvider{cd}); err != nil { t.Error(err) } else if passes { @@ -517,7 +517,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf := &FilterRule{Type: utils.MetaString, FieldName: "~MetaString", Values: []string{"String"}, negative: utils.BoolPointer(false)} + erf := &FilterRule{Type: utils.MetaString, Element: "~MetaString", Values: []string{"String"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -525,7 +525,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaEmpty, FieldName: "~MetaEmpty", Values: []string{}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaEmpty, Element: "~MetaEmpty", Values: []string{}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -533,7 +533,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaExists, FieldName: "~MetaExists", Values: []string{}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaExists, Element: "~MetaExists", Values: []string{}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -541,7 +541,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaPrefix, FieldName: "~MetaPrefix", Values: []string{"stringPrefix"}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaPrefix, Element: "~MetaPrefix", Values: []string{"stringPrefix"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -549,7 +549,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaSuffix, FieldName: "~MetaSuffix", Values: []string{"stringSuffix"}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaSuffix, Element: "~MetaSuffix", Values: []string{"stringSuffix"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -557,7 +557,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaTimings, FieldName: "~MetaTimings", Values: []string{""}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaTimings, Element: "~MetaTimings", Values: []string{""}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -565,7 +565,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaDestinations, FieldName: "~MetaDestinations", Values: []string{""}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaDestinations, Element: "~MetaDestinations", Values: []string{""}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -573,7 +573,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaLessThan, FieldName: "~MetaLessThan", Values: []string{"20"}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaLessThan, Element: "~MetaLessThan", Values: []string{"20"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -581,7 +581,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaLessOrEqual, FieldName: "~MetaLessOrEqual", Values: []string{"20"}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaLessOrEqual, Element: "~MetaLessOrEqual", Values: []string{"20"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -589,7 +589,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaGreaterThan, FieldName: "~MetaGreaterThan", Values: []string{"20"}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaGreaterThan, Element: "~MetaGreaterThan", Values: []string{"20"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } @@ -597,7 +597,7 @@ func TestFilterNewRequestFilter(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - erf = &FilterRule{Type: utils.MetaGreaterOrEqual, FieldName: "~MetaGreaterOrEqual", Values: []string{"20"}, negative: utils.BoolPointer(false)} + erf = &FilterRule{Type: utils.MetaGreaterOrEqual, Element: "~MetaGreaterOrEqual", Values: []string{"20"}, negative: utils.BoolPointer(false)} if !reflect.DeepEqual(erf, rf) { t.Errorf("Expecting: %+v, received: %+v", erf, rf) } diff --git a/engine/libattributes.go b/engine/libattributes.go index 3d2a9409c..3587494ac 100644 --- a/engine/libattributes.go +++ b/engine/libattributes.go @@ -27,13 +27,15 @@ import ( "github.com/cgrates/cgrates/utils" ) +// Attribute used by AttributeProfile to describe a single attribute type Attribute struct { FilterIDs []string - FieldName string + Path string Type string Value config.RSRParsers } +// AttributeProfile the profile definition for the attributes type AttributeProfile struct { Tenant string ID string @@ -59,8 +61,9 @@ func (ap *AttributeProfile) Compile() error { return ap.compileSubstitutes() } -func (als *AttributeProfile) TenantID() string { - return utils.ConcatenatedKey(als.Tenant, als.ID) +// TenantID returns the tenant wit the ID +func (ap *AttributeProfile) TenantID() string { + return utils.ConcatenatedKey(ap.Tenant, ap.ID) } // AttributeProfiles is a sortable list of Attribute profiles @@ -71,13 +74,15 @@ func (aps AttributeProfiles) Sort() { sort.Slice(aps, func(i, j int) bool { return aps[i].Weight > aps[j].Weight }) } +// ExternalAttribute the attribute for external profile type ExternalAttribute struct { FilterIDs []string - FieldName string + Path string Type string Value string } +// ExternalAttributeProfile used by APIs type ExternalAttributeProfile struct { Tenant string ID string @@ -89,6 +94,7 @@ type ExternalAttributeProfile struct { Weight float64 } +// AsAttributeProfile converts the external attribute format to the actual AttributeProfile func (ext *ExternalAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, err error) { attr = new(AttributeProfile) if len(ext.Attributes) == 0 { @@ -105,7 +111,7 @@ func (ext *ExternalAttributeProfile) AsAttributeProfile() (attr *AttributeProfil } attr.Attributes[i].Type = extAttr.Type attr.Attributes[i].FilterIDs = extAttr.FilterIDs - attr.Attributes[i].FieldName = extAttr.FieldName + attr.Attributes[i].Path = extAttr.Path } attr.Tenant = ext.Tenant attr.ID = ext.ID @@ -132,9 +138,9 @@ func NewAttributeFromInline(tenant, inlnRule string) (attr *AttributeProfile, er ID: inlnRule, Contexts: []string{utils.META_ANY}, Attributes: []*Attribute{&Attribute{ - FieldName: ruleSplt[1], - Type: ruleSplt[0], - Value: vals, + Path: ruleSplt[1], + Type: ruleSplt[0], + Value: vals, }}, } if err = attr.Compile(); err != nil { diff --git a/engine/libattributes_test.go b/engine/libattributes_test.go index edd3a1577..a50befebf 100644 --- a/engine/libattributes_test.go +++ b/engine/libattributes_test.go @@ -39,8 +39,8 @@ func TestConvertExternalToProfile(t *testing.T) { }, Attributes: []*ExternalAttribute{ &ExternalAttribute{ - FieldName: "Account", - Value: "1001", + Path: utils.MetaReq + utils.NestingSep + "Account", + Value: "1001", }, }, Weight: 20, @@ -57,8 +57,8 @@ func TestConvertExternalToProfile(t *testing.T) { }, Attributes: []*Attribute{ { - FieldName: "Account", - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Account", + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -108,7 +108,7 @@ func TestConvertExternalToProfileMissing2(t *testing.T) { }, Attributes: []*ExternalAttribute{ &ExternalAttribute{ - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", }, }, Weight: 20, @@ -122,15 +122,15 @@ func TestConvertExternalToProfileMissing2(t *testing.T) { } func TestNewAttributeFromInline(t *testing.T) { - attrID := "*sum:Field2:10;~NumField;20" + attrID := "*sum:*req.Field2:10;~*req.NumField;20" expAttrPrf1 := &AttributeProfile{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: attrID, Contexts: []string{utils.META_ANY}, Attributes: []*Attribute{&Attribute{ - FieldName: "Field2", - Type: utils.MetaSum, - Value: config.NewRSRParsersMustCompile("10;~NumField;20", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaSum, + Value: config.NewRSRParsersMustCompile("10;~*req.NumField;20", true, utils.INFIELD_SEP), }}, } attr, err := NewAttributeFromInline(config.CgrConfig().GeneralCfg().DefaultTenant, attrID) diff --git a/engine/libtest.go b/engine/libtest.go index bfaa1d902..de35b29ee 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -246,7 +246,7 @@ cgrates.org,Threshold1,*string:~*req.Account:1001;*string:~*req.RunID:*default,2 ` FiltersCSVContent = ` -#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +#Tenant[0],ID[1],Type[2],Element[3],Values[4],ActivationInterval[5] cgrates.org,FLTR_1,*string,~*req.Account,1001;1002,2014-07-29T15:00:00Z cgrates.org,FLTR_1,*prefix,~*req.Destination,10;20,2014-07-29T15:00:00Z cgrates.org,FLTR_1,*rsr,,~*req.Subject(~^1.*1$);~*req.Destination(1002), @@ -262,9 +262,9 @@ cgrates.org,SPP_1,,,,,supplier1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,,, cgrates.org,SPP_1,,,,,supplier1,,,,ResGroup4,Stat3,10,,, ` AttributesCSVContent = ` -#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Value,Blocker,Weight -cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,Field1,*variable,Sub1,true,20 -cgrates.org,ALS1,con2;con3,,,,Field2,*variable,Sub2,true,20 +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight +cgrates.org,ALS1,con1,*string:~*req.Account:1001,2014-07-29T15:00:00Z,*string:~*req.Field1:Initial,*req.Field1,*variable,Sub1,true,20 +cgrates.org,ALS1,con2;con3,,,,*req.Field2,*variable,Sub2,true,20 ` ChargersCSVContent = ` #Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index c5d87b6b6..221fd5ebf 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1151,19 +1151,19 @@ func TestLoadFilters(t *testing.T) { ID: "FLTR_1", Filters: []*utils.TPFilter{ &utils.TPFilter{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"1001", "1002"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, &utils.TPFilter{ - FieldName: "~*req.Destination", - Type: utils.MetaPrefix, - Values: []string{"10", "20"}, + Element: "~*req.Destination", + Type: utils.MetaPrefix, + Values: []string{"10", "20"}, }, &utils.TPFilter{ - FieldName: "", - Type: utils.MetaRSR, - Values: []string{"~*req.Subject(~^1.*1$)", "~*req.Destination(1002)"}, + Element: "", + Type: utils.MetaRSR, + Values: []string{"~*req.Subject(~^1.*1$)", "~*req.Destination(1002)"}, }, }, ActivationInterval: &utils.TPActivationInterval{ @@ -1176,9 +1176,9 @@ func TestLoadFilters(t *testing.T) { ID: "FLTR_ACNT_dan", Filters: []*utils.TPFilter{ &utils.TPFilter{ - FieldName: "~*req.Account", - Type: utils.MetaString, - Values: []string{"dan"}, + Element: "~*req.Account", + Type: utils.MetaString, + Values: []string{"dan"}, }, }, ActivationInterval: &utils.TPActivationInterval{ @@ -1191,9 +1191,9 @@ func TestLoadFilters(t *testing.T) { ID: "FLTR_DST_DE", Filters: []*utils.TPFilter{ &utils.TPFilter{ - FieldName: "~*req.Destination", - Type: utils.MetaDestinations, - Values: []string{"DST_DE"}, + Element: "~*req.Destination", + Type: utils.MetaDestinations, + Values: []string{"DST_DE"}, }, }, ActivationInterval: &utils.TPActivationInterval{ @@ -1206,9 +1206,9 @@ func TestLoadFilters(t *testing.T) { ID: "FLTR_DST_NL", Filters: []*utils.TPFilter{ &utils.TPFilter{ - FieldName: "~*req.Destination", - Type: utils.MetaDestinations, - Values: []string{"DST_NL"}, + Element: "~*req.Destination", + Type: utils.MetaDestinations, + Values: []string{"DST_NL"}, }, }, ActivationInterval: &utils.TPActivationInterval{ @@ -1274,13 +1274,13 @@ func TestLoadAttributeProfiles(t *testing.T) { Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ FilterIDs: []string{"*string:~*req.Field1:Initial"}, - FieldName: "Field1", + Path: utils.MetaReq + utils.NestingSep + "Field1", Type: utils.MetaVariable, Value: "Sub1", }, &utils.TPAttribute{ FilterIDs: []string{}, - FieldName: "Field2", + Path: utils.MetaReq + utils.NestingSep + "Field2", Type: utils.MetaVariable, Value: "Sub2", }, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index c7e428e27..6bd3d3f50 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1692,11 +1692,11 @@ func (tps TpFilterS) AsTPFilter() (result []*utils.TPFilterProfile) { th.ActivationInterval.ActivationTime = aiSplt[0] } } - if tp.FilterType != "" { + if tp.Type != "" { th.Filters = append(th.Filters, &utils.TPFilter{ - Type: tp.FilterType, - FieldName: tp.FilterFieldName, - Values: strings.Split(tp.FilterFieldValues, utils.INFIELD_SEP)}) + Type: tp.Type, + Element: tp.Element, + Values: strings.Split(tp.Values, utils.INFIELD_SEP)}) } mst[(&utils.TenantID{Tenant: tp.Tenant, ID: tp.ID}).TenantID()] = th } @@ -1719,8 +1719,8 @@ func APItoModelTPFilter(th *utils.TPFilterProfile) (mdls TpFilterS) { Tenant: th.Tenant, ID: th.ID, } - mdl.FilterType = fltr.Type - mdl.FilterFieldName = fltr.FieldName + mdl.Type = fltr.Type + mdl.Element = fltr.Element if th.ActivationInterval != nil { if th.ActivationInterval.ActivationTime != "" { mdl.ActivationInterval = th.ActivationInterval.ActivationTime @@ -1731,9 +1731,9 @@ func APItoModelTPFilter(th *utils.TPFilterProfile) (mdls TpFilterS) { } for i, val := range fltr.Values { if i != 0 { - mdl.FilterFieldValues += utils.INFIELD_SEP + mdl.Values += utils.INFIELD_SEP } - mdl.FilterFieldValues += val + mdl.Values += val } mdls = append(mdls, mdl) } @@ -1747,7 +1747,7 @@ func APItoFilter(tpTH *utils.TPFilterProfile, timezone string) (th *Filter, err Rules: make([]*FilterRule, len(tpTH.Filters)), } for i, f := range tpTH.Filters { - rf := &FilterRule{Type: f.Type, FieldName: f.FieldName, Values: f.Values} + rf := &FilterRule{Type: f.Type, Element: f.Element, Values: f.Values} if err := rf.CompileValues(); err != nil { return nil, err } @@ -1769,9 +1769,9 @@ func FilterToTPFilter(f *Filter) (tpFltr *utils.TPFilterProfile) { } for i, reqFltr := range f.Rules { tpFltr.Filters[i] = &utils.TPFilter{ - Type: reqFltr.Type, - FieldName: reqFltr.FieldName, - Values: make([]string, len(reqFltr.Values)), + Type: reqFltr.Type, + Element: reqFltr.Element, + Values: make([]string, len(reqFltr.Values)), } for j, val := range reqFltr.Values { tpFltr.Filters[i].Values[j] = val @@ -2051,7 +2051,7 @@ func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttributeProfile) { contextMap[key.TenantID()][context] = true } } - if tp.FieldName != "" { + if tp.Path != "" { filterIDs := make([]string, 0) if tp.AttributeFilterIDs != "" { filterAttrSplit := strings.Split(tp.AttributeFilterIDs, utils.INFIELD_SEP) @@ -2062,7 +2062,7 @@ func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttributeProfile) { th.Attributes = append(th.Attributes, &utils.TPAttribute{ FilterIDs: filterIDs, Type: tp.Type, - FieldName: tp.FieldName, + Path: tp.Path, Value: tp.Value, }) } @@ -2125,7 +2125,7 @@ func APItoModelTPAttribute(th *utils.TPAttributeProfile) (mdls TPAttributes) { mdl.AttributeFilterIDs += val } } - mdl.FieldName = reqAttribute.FieldName + mdl.Path = reqAttribute.Path mdl.Value = reqAttribute.Value mdl.Type = reqAttribute.Type mdls = append(mdls, mdl) @@ -2156,7 +2156,7 @@ func APItoAttributeProfile(tpAttr *utils.TPAttributeProfile, timezone string) (a } attrPrf.Attributes[i] = &Attribute{ FilterIDs: reqAttr.FilterIDs, - FieldName: reqAttr.FieldName, + Path: reqAttr.Path, Type: reqAttr.Type, Value: sbstPrsr, } diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 9461bf020..9cc573868 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -1050,11 +1050,11 @@ func TestAPItoTPThreshold(t *testing.T) { func TestTPFilterAsTPFilter(t *testing.T) { tps := []*TpFilter{ &TpFilter{ - Tpid: "TEST_TPID", - ID: "Filter1", - FilterType: utils.MetaPrefix, - FilterFieldName: "Account", - FilterFieldValues: "1001;1002", + Tpid: "TEST_TPID", + ID: "Filter1", + Type: utils.MetaPrefix, + Element: "Account", + Values: "1001;1002", }, } eTPs := []*utils.TPFilterProfile{ @@ -1063,9 +1063,9 @@ func TestTPFilterAsTPFilter(t *testing.T) { ID: tps[0].ID, Filters: []*utils.TPFilter{ &utils.TPFilter{ - Type: utils.MetaPrefix, - FieldName: "Account", - Values: []string{"1001", "1002"}, + Type: utils.MetaPrefix, + Element: "Account", + Values: []string{"1001", "1002"}, }, }, }, @@ -1080,20 +1080,20 @@ func TestTPFilterAsTPFilter(t *testing.T) { func TestTPFilterAsTPFilter2(t *testing.T) { tps := []*TpFilter{ &TpFilter{ - Tpid: "TEST_TPID", - Tenant: "cgrates.org", - ID: "Filter1", - FilterType: utils.MetaPrefix, - FilterFieldName: "Account", - FilterFieldValues: "1001;1002", + Tpid: "TEST_TPID", + Tenant: "cgrates.org", + ID: "Filter1", + Type: utils.MetaPrefix, + Element: "Account", + Values: "1001;1002", }, &TpFilter{ - Tpid: "TEST_TPID", - Tenant: "anotherTenant", - ID: "Filter1", - FilterType: utils.MetaPrefix, - FilterFieldName: "Account", - FilterFieldValues: "1010", + Tpid: "TEST_TPID", + Tenant: "anotherTenant", + ID: "Filter1", + Type: utils.MetaPrefix, + Element: "Account", + Values: "1010", }, } eTPs := []*utils.TPFilterProfile{ @@ -1103,9 +1103,9 @@ func TestTPFilterAsTPFilter2(t *testing.T) { ID: tps[0].ID, Filters: []*utils.TPFilter{ &utils.TPFilter{ - Type: utils.MetaPrefix, - FieldName: "Account", - Values: []string{"1001", "1002"}, + Type: utils.MetaPrefix, + Element: "Account", + Values: []string{"1001", "1002"}, }, }, }, @@ -1115,9 +1115,9 @@ func TestTPFilterAsTPFilter2(t *testing.T) { ID: tps[1].ID, Filters: []*utils.TPFilter{ &utils.TPFilter{ - Type: utils.MetaPrefix, - FieldName: "Account", - Values: []string{"1010"}, + Type: utils.MetaPrefix, + Element: "Account", + Values: []string{"1010"}, }, }, }, @@ -1136,9 +1136,9 @@ func TestAPItoTPFilter(t *testing.T) { ID: "Filter1", Filters: []*utils.TPFilter{ &utils.TPFilter{ - FieldName: "Account", - Type: utils.MetaString, - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, } @@ -1148,9 +1148,9 @@ func TestAPItoTPFilter(t *testing.T) { ID: tps.ID, Rules: []*FilterRule{ &FilterRule{ - FieldName: "Account", - Type: utils.MetaString, - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, } @@ -1171,9 +1171,9 @@ func TestFilterToTPFilter(t *testing.T) { }, Rules: []*FilterRule{ &FilterRule{ - FieldName: "Account", - Type: utils.MetaString, - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, } @@ -1186,9 +1186,9 @@ func TestFilterToTPFilter(t *testing.T) { }, Filters: []*utils.TPFilter{ &utils.TPFilter{ - FieldName: "Account", - Type: utils.MetaString, - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, } @@ -1211,8 +1211,8 @@ func TestAPItoAttributeProfile(t *testing.T) { }, Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ - FieldName: "FL1", - Value: "Al1", + Path: utils.MetaReq + utils.NestingSep + "FL1", + Value: "Al1", }, }, Weight: 20, @@ -1227,8 +1227,8 @@ func TestAPItoAttributeProfile(t *testing.T) { }, Attributes: []*Attribute{ &Attribute{ - FieldName: "FL1", - Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FL1", + Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1253,8 +1253,8 @@ func TestAPItoModelTPAttribute(t *testing.T) { }, Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ - FieldName: "FL1", - Value: "Al1", + Path: utils.MetaReq + utils.NestingSep + "FL1", + Value: "Al1", }, }, Weight: 20, @@ -1266,7 +1266,7 @@ func TestAPItoModelTPAttribute(t *testing.T) { ID: "ALS1", Contexts: "con1", FilterIDs: "FLTR_ACNT_dan;FLTR_DST_DE", - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", ActivationInterval: "2014-07-14T14:35:00Z", Weight: 20, @@ -1286,7 +1286,7 @@ func TestModelAsTPAttribute(t *testing.T) { ID: "ALS1", Contexts: "con1", FilterIDs: "FLTR_ACNT_dan;FLTR_DST_DE", - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", ActivationInterval: "2014-07-14T14:35:00Z", Weight: 20, @@ -1305,7 +1305,7 @@ func TestModelAsTPAttribute(t *testing.T) { Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ FilterIDs: []string{}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", }, }, @@ -1324,7 +1324,7 @@ func TestModelAsTPAttribute(t *testing.T) { Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ FilterIDs: []string{}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Value: "Al1", }, }, diff --git a/engine/models.go b/engine/models.go index 3cf37f3a5..49befba33 100644 --- a/engine/models.go +++ b/engine/models.go @@ -270,9 +270,9 @@ type TpFilter struct { Tpid string Tenant string `index:"0" re:""` ID string `index:"1" re:""` - FilterType string `index:"2" re:"^\*[A-Za-z].*"` - FilterFieldName string `index:"3" re:""` - FilterFieldValues string `index:"4" re:""` + Type string `index:"2" re:"^\*[A-Za-z].*"` + Element string `index:"3" re:""` + Values string `index:"4" re:""` ActivationInterval string `index:"5" re:""` CreatedAt time.Time } @@ -396,7 +396,7 @@ type TPAttribute struct { FilterIDs string `index:"3" re:""` ActivationInterval string `index:"4" re:""` AttributeFilterIDs string `index:"5" re:""` - FieldName string `index:"6" re:""` + Path string `index:"6" re:""` Type string `index:"7" re:""` Value string `index:"8" re:""` Blocker bool `index:"9" re:""` diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 3326463bc..1b1424afe 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -1536,9 +1536,9 @@ func testOnStorITThresholdProfile(t *testing.T) { ID: "TestFilter2", Rules: []*FilterRule{ { - FieldName: "Account", - Type: "*string", - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1660,9 +1660,9 @@ func testOnStorITFilter(t *testing.T) { ID: "Filter1", Rules: []*FilterRule{ { - FieldName: "Account", - Type: "*string", - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1700,14 +1700,14 @@ func testOnStorITFilter(t *testing.T) { //update fp.Rules = []*FilterRule{ { - FieldName: "Account", - Type: "*string", - Values: []string{"1001", "1002"}, + Element: "Account", + Type: utils.MetaString, + Values: []string{"1001", "1002"}, }, { - FieldName: "Destination", - Type: "*string", - Values: []string{"10", "20"}, + Element: "Destination", + Type: utils.MetaString, + Values: []string{"10", "20"}, }, } if err := onStor.SetFilter(fp); err != nil { @@ -1862,8 +1862,8 @@ func testOnStorITAttributeProfile(t *testing.T) { Contexts: []string{"con1"}, Attributes: []*Attribute{ { - FieldName: "FN1", - Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FN1", + Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1942,8 +1942,8 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { Contexts: []string{"con1"}, Attributes: []*Attribute{ { - FieldName: "FN1", - Value: config.NewRSRParsersMustCompile("Val1", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FN1", + Value: config.NewRSRParsersMustCompile("Val1", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -1964,8 +1964,8 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { } attrProfile.Attributes = []*Attribute{ { - FieldName: "FN1", - Value: config.NewRSRParsersMustCompile("123.123", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FN1", + Value: config.NewRSRParsersMustCompile("123.123", true, utils.INFIELD_SEP), }, } if err := onStor.SetAttributeProfile(attrProfile, false); err != nil { @@ -1980,8 +1980,8 @@ func testOnStorITTestAttributeSubstituteIface(t *testing.T) { } attrProfile.Attributes = []*Attribute{ { - FieldName: "FN1", - Value: config.NewRSRParsersMustCompile("true", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "FN1", + Value: config.NewRSRParsersMustCompile("true", true, utils.INFIELD_SEP), }, } if err := onStor.SetAttributeProfile(attrProfile, false); err != nil { diff --git a/engine/resources_test.go b/engine/resources_test.go index f827f3485..a3fc0dd1d 100644 --- a/engine/resources_test.go +++ b/engine/resources_test.go @@ -408,24 +408,24 @@ func TestResourceAddFilters(t *testing.T) { ID: "FLTR_RES_1", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Resources", - Values: []string{"ResourceProfile1"}, + Type: utils.MetaString, + Element: "~*req.Resources", + Values: []string{"ResourceProfile1"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.UsageInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.UsageInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"9.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"9.0"}, }, }, } @@ -435,24 +435,24 @@ func TestResourceAddFilters(t *testing.T) { ID: "FLTR_RES_2", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Resources", - Values: []string{"ResourceProfile2"}, + Type: utils.MetaString, + Element: "~*req.Resources", + Values: []string{"ResourceProfile2"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.PddInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.PddInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"15.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"15.0"}, }, }, } @@ -462,9 +462,9 @@ func TestResourceAddFilters(t *testing.T) { ID: "FLTR_RES_3", Rules: []*FilterRule{ { - Type: utils.MetaPrefix, - FieldName: "~*req.Resources", - Values: []string{"ResourceProfilePrefix"}, + Type: utils.MetaPrefix, + Element: "~*req.Resources", + Values: []string{"ResourceProfilePrefix"}, }, }, } diff --git a/engine/stats_test.go b/engine/stats_test.go index d8973be42..7730f7143 100644 --- a/engine/stats_test.go +++ b/engine/stats_test.go @@ -162,24 +162,24 @@ func TestStatQueuesAddFilters(t *testing.T) { ID: "FLTR_STATS_1", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Stats", - Values: []string{"StatQueueProfile1"}, + Type: utils.MetaString, + Element: "~*req.Stats", + Values: []string{"StatQueueProfile1"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.UsageInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.UsageInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"9.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"9.0"}, }, }, } @@ -189,24 +189,24 @@ func TestStatQueuesAddFilters(t *testing.T) { ID: "FLTR_STATS_2", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Stats", - Values: []string{"StatQueueProfile2"}, + Type: utils.MetaString, + Element: "~*req.Stats", + Values: []string{"StatQueueProfile2"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.PddInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.PddInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"15.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"15.0"}, }, }, } @@ -216,9 +216,9 @@ func TestStatQueuesAddFilters(t *testing.T) { ID: "FLTR_STATS_3", Rules: []*FilterRule{ { - Type: utils.MetaPrefix, - FieldName: "~*req.Stats", - Values: []string{"StatQueueProfilePrefix"}, + Type: utils.MetaPrefix, + Element: "~*req.Stats", + Values: []string{"StatQueueProfilePrefix"}, }, }, } diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go index 4f2bcac96..b6c27a6ab 100644 --- a/engine/suppliers_test.go +++ b/engine/suppliers_test.go @@ -306,19 +306,19 @@ func TestSuppliersAddFilters(t *testing.T) { ID: "FLTR_SUPP_1", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Supplier", - Values: []string{"SupplierProfile1"}, + Type: utils.MetaString, + Element: "~*req.Supplier", + Values: []string{"SupplierProfile1"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.UsageInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.UsageInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"9.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"9.0"}, }, }, } @@ -328,19 +328,19 @@ func TestSuppliersAddFilters(t *testing.T) { ID: "FLTR_SUPP_2", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Supplier", - Values: []string{"SupplierProfile2"}, + Type: utils.MetaString, + Element: "~*req.Supplier", + Values: []string{"SupplierProfile2"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: "~*req.PddInterval", - Values: []string{(1 * time.Second).String()}, + Type: utils.MetaGreaterOrEqual, + Element: "~*req.PddInterval", + Values: []string{(1 * time.Second).String()}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"15.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"15.0"}, }, }, } @@ -350,9 +350,9 @@ func TestSuppliersAddFilters(t *testing.T) { ID: "FLTR_SUPP_3", Rules: []*FilterRule{ { - Type: utils.MetaPrefix, - FieldName: "~*req.Supplier", - Values: []string{"SupplierProfilePrefix"}, + Type: utils.MetaPrefix, + Element: "~*req.Supplier", + Values: []string{"SupplierProfilePrefix"}, }, }, } diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index 0bae470b0..b92cd8a80 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -160,14 +160,14 @@ func TestThresholdsAddFilters(t *testing.T) { ID: "FLTR_TH_1", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Threshold", - Values: []string{"TH_1"}, + Type: utils.MetaString, + Element: "~*req.Threshold", + Values: []string{"TH_1"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"9.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"9.0"}, }, }, } @@ -177,14 +177,14 @@ func TestThresholdsAddFilters(t *testing.T) { ID: "FLTR_TH_2", Rules: []*FilterRule{ { - Type: utils.MetaString, - FieldName: "~*req.Threshold", - Values: []string{"TH_2"}, + Type: utils.MetaString, + Element: "~*req.Threshold", + Values: []string{"TH_2"}, }, { - Type: utils.MetaGreaterOrEqual, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, - Values: []string{"15.0"}, + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"15.0"}, }, }, } @@ -194,9 +194,9 @@ func TestThresholdsAddFilters(t *testing.T) { ID: "FLTR_TH_3", Rules: []*FilterRule{ { - Type: utils.MetaPrefix, - FieldName: "~*req.Threshold", - Values: []string{"ThresholdPrefix"}, + Type: utils.MetaPrefix, + Element: "~*req.Threshold", + Values: []string{"ThresholdPrefix"}, }, }, } diff --git a/engine/version.go b/engine/version.go index 9b4378450..93afbbae3 100644 --- a/engine/version.go +++ b/engine/version.go @@ -151,9 +151,9 @@ func CurrentDataDBVersions() Versions { utils.SharedGroups: 2, utils.Thresholds: 3, utils.Suppliers: 1, - utils.Attributes: 4, + utils.Attributes: 5, utils.Timing: 1, - utils.RQF: 3, + utils.RQF: 4, utils.Resource: 1, utils.Subscribers: 1, utils.Destinations: 1, diff --git a/general_tests/cdrs_processevent_it_test.go b/general_tests/cdrs_processevent_it_test.go index 9452a8b72..b97d3c6f6 100644 --- a/general_tests/cdrs_processevent_it_test.go +++ b/general_tests/cdrs_processevent_it_test.go @@ -178,8 +178,8 @@ func testV1CDRsProcessEventAttrS(t *testing.T) { FilterIDs: []string{"*string:~*req.Account:1001"}, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1011", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1011", true, utils.INFIELD_SEP), }, }, Weight: 20, diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index 45b0bf3b2..fdb2875e8 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -261,9 +261,9 @@ func testV1FltrPupulateThreshold(t *testing.T) { ID: "FLTR_TH_Stats1", Rules: []*engine.FilterRule{ { - Type: "*gt", - FieldName: "~*stats.Stat_1.*acd", - Values: []string{"10.0"}, + Type: "*gt", + Element: "~*stats.Stat_1.*acd", + Values: []string{"10.0"}, }, }, }, @@ -346,9 +346,9 @@ func testV1FltrGetThresholdForEvent2(t *testing.T) { ID: "FLTR_TH_Stats1", Rules: []*engine.FilterRule{ { - Type: "*lt", - FieldName: "~*stats.Stat_1.*acd", - Values: []string{"10.0"}, + Type: "*lt", + Element: "~*stats.Stat_1.*acd", + Values: []string{"10.0"}, }, }, }, @@ -451,9 +451,9 @@ func testV1FltrPopulateResources(t *testing.T) { ID: "FLTR_TH_Resource", Rules: []*engine.FilterRule{ { - Type: "*gt", - FieldName: "~*resources.ResTest.TotalUsage", - Values: []string{"2.0"}, + Type: "*gt", + Element: "~*resources.ResTest.TotalUsage", + Values: []string{"2.0"}, }, }, }, @@ -515,9 +515,9 @@ func testV1FltrPopulateResources(t *testing.T) { ID: "FLTR_TH_Resource", Rules: []*engine.FilterRule{ { - Type: "*lt", - FieldName: "~*resources.ResTest.TotalUsage", - Values: []string{"2.0"}, + Type: "*lt", + Element: "~*resources.ResTest.TotalUsage", + Values: []string{"2.0"}, }, }, } @@ -559,9 +559,9 @@ func testV1FltrAccounts(t *testing.T) { ID: "FLTR_TH_Accounts", Rules: []*engine.FilterRule{ { - Type: "*gt", - FieldName: "~*accounts.1001.BalanceMap.*monetary[0].Value", - Values: []string{"9"}, + Type: "*gt", + Element: "~*accounts.1001.BalanceMap.*monetary[0].Value", + Values: []string{"9"}, }, }, }, @@ -633,9 +633,9 @@ func testV1FltrAccounts(t *testing.T) { ID: "FLTR_TH_Accounts", Rules: []*engine.FilterRule{ { - Type: "*gt", - FieldName: "~*accounts.1001.BalanceMap.*monetary[0].Value", - Values: []string{"11"}, + Type: "*gt", + Element: "~*accounts.1001.BalanceMap.*monetary[0].Value", + Values: []string{"11"}, }, }, } diff --git a/general_tests/sentinel_it_test.go b/general_tests/sentinel_it_test.go index cb8286b83..e414ce7b1 100755 --- a/general_tests/sentinel_it_test.go +++ b/general_tests/sentinel_it_test.go @@ -126,11 +126,11 @@ func testRedisSentinelSetGetAttribute(t *testing.T) { Tenant: "cgrates.org", ID: "ApierTest", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -160,11 +160,11 @@ func testRedisSentinelInsertion(t *testing.T) { Tenant: "cgrates.org", ID: "ApierTest", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*reqAccount:1001"}, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -244,11 +244,11 @@ func testRedisSentinelGetAttrAfterFailover(t *testing.T) { Tenant: "cgrates.org", ID: "ApierTest", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, - FilterIDs: []string{"*string:Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, Attributes: []*engine.Attribute{ { - FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }, }, Weight: 20, diff --git a/general_tests/session3_it_test.go b/general_tests/session3_it_test.go index 477458baf..f28a229e4 100644 --- a/general_tests/session3_it_test.go +++ b/general_tests/session3_it_test.go @@ -165,7 +165,7 @@ func testSes3ItProcessEvent(t *testing.T) { } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItProcessEvent", diff --git a/general_tests/sessions_concur_test.go b/general_tests/sessions_concur_test.go index 736fd3785..5462cf55b 100644 --- a/general_tests/sessions_concur_test.go +++ b/general_tests/sessions_concur_test.go @@ -132,8 +132,8 @@ func testSCncrLoadTP(t *testing.T) { Contexts: []string{utils.ANY}, Attributes: []*engine.ExternalAttribute{ { - FieldName: "TestType", - Value: "ConcurrentSessions", + Path: utils.MetaReq + utils.NestingSep + "TestType", + Value: "ConcurrentSessions", }, }, Weight: 20, diff --git a/loaders/libloader_test.go b/loaders/libloader_test.go index 168aabf0f..f0ec4c68e 100644 --- a/loaders/libloader_test.go +++ b/loaders/libloader_test.go @@ -50,8 +50,8 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { FieldId: "ActivationInterval", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~4", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FieldName", - FieldId: "FieldName", + &config.FCTemplate{Tag: "Path", + FieldId: "Path", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~5", true, utils.INFIELD_SEP)}, &config.FCTemplate{Tag: "Initial", @@ -86,7 +86,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { "Contexts": "*sessions;*cdrs", "FilterIDs": "*string:Account:1007", "ActivationInterval": "2014-01-14T00:00:00Z", - "FieldName": "Account", + "Path": "Account", "Initial": "*any", "Substitute": "1001", "Append": "false", @@ -105,7 +105,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { "Contexts": "", "FilterIDs": "", "ActivationInterval": "", - "FieldName": "Subject", + "Path": "Subject", "Initial": "*any", "Substitute": "1001", "Append": "true", @@ -140,8 +140,8 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) { FieldId: "ActivationInterval", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("~4", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FieldName", - FieldId: "FieldName", + &config.FCTemplate{Tag: "Path", + FieldId: "Path", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("~5", true, utils.INFIELD_SEP)}, &config.FCTemplate{Tag: "Initial", @@ -176,7 +176,7 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) { "Contexts": "*sessions;*cdrs", "FilterIDs": "*string:Account:1007", "ActivationInterval": "2014-01-14T00:00:00Z", - "FieldName": "Account", + "Path": "Account", "Initial": "*any", "Substitute": "1001", "Append": "false", @@ -195,7 +195,7 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) { "Contexts": "", "FilterIDs": "", "ActivationInterval": "", - "FieldName": "Subject", + "Path": "Subject", "Initial": "*any", "Substitute": "1001", "Append": "true", @@ -222,8 +222,8 @@ func TestDataUpdateFromCSVMultiFiles(t *testing.T) { FieldId: "Contexts", Type: utils.MetaString, Value: config.NewRSRParsersMustCompile("*any", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FieldName", - FieldId: "FieldName", + &config.FCTemplate{Tag: "Path", + FieldId: "Path", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~File1.csv:5", true, utils.INFIELD_SEP)}, &config.FCTemplate{Tag: "Initial", @@ -259,7 +259,7 @@ func TestDataUpdateFromCSVMultiFiles(t *testing.T) { eLData := LoaderData{"Tenant": "cgrates.org", "ID": "ATTR_1", "Contexts": "*any", - "FieldName": "Subject", + "Path": "Subject", "Initial": "*any", "Substitute": "1001", "Append": "true", diff --git a/loaders/loader_it_test.go b/loaders/loader_it_test.go index dab46c834..31f61087e 100644 --- a/loaders/loader_it_test.go +++ b/loaders/loader_it_test.go @@ -163,13 +163,13 @@ func testLoaderCheckAttributes(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{"*string:~*req.Field1:Initial"}, - FieldName: "Field1", + Path: utils.MetaReq + utils.NestingSep + "Field1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Sub1", true, utils.INFIELD_SEP), }, &engine.Attribute{ FilterIDs: []string{}, - FieldName: "Field2", + Path: utils.MetaReq + utils.NestingSep + "Field2", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Sub2", true, utils.INFIELD_SEP), }}, diff --git a/loaders/loader_test.go b/loaders/loader_test.go index 0dc8da752..8496c6e12 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -68,8 +68,8 @@ func TestLoaderProcessContentSingleFile(t *testing.T) { FieldId: "AttributeFilterIDs", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~5", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FieldName", - FieldId: "FieldName", + &config.FCTemplate{Tag: "Path", + FieldId: "Path", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~6", true, utils.INFIELD_SEP)}, &config.FCTemplate{Tag: "Type", @@ -111,13 +111,13 @@ func TestLoaderProcessContentSingleFile(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{"*string:~*req.Field1:Initial"}, - FieldName: "Field1", + Path: utils.MetaReq + utils.NestingSep + "Field1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Sub1", true, utils.INFIELD_SEP), }, &engine.Attribute{ FilterIDs: []string{}, - FieldName: "Field2", + Path: utils.MetaReq + utils.NestingSep + "Field2", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Sub2", true, utils.INFIELD_SEP), }}, @@ -137,7 +137,7 @@ func TestLoaderProcessContentSingleFile(t *testing.T) { } func TestLoaderProcessContentMultiFiles(t *testing.T) { - file1CSV := `ignored,ignored,ignored,ignored,ignored,,Subject,1001,ignored,ignored` + file1CSV := `ignored,ignored,ignored,ignored,ignored,,*req.Subject,1001,ignored,ignored` file2CSV := `ignored,TestLoader2` data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) ldr := &Loader{ @@ -162,8 +162,8 @@ func TestLoaderProcessContentMultiFiles(t *testing.T) { FieldId: "Contexts", Type: utils.MetaString, Value: config.NewRSRParsersMustCompile("*any", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FieldName", - FieldId: "FieldName", + &config.FCTemplate{Tag: "Path", + FieldId: "Path", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~File1.csv:6", true, utils.INFIELD_SEP)}, &config.FCTemplate{Tag: "Value", @@ -198,7 +198,7 @@ func TestLoaderProcessContentMultiFiles(t *testing.T) { Contexts: []string{utils.ANY}, Attributes: []*engine.Attribute{ &engine.Attribute{ - FieldName: "Subject", + Path: utils.MetaReq + utils.NestingSep + "Subject", FilterIDs: []string{}, Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP), }}, @@ -354,16 +354,16 @@ func TestLoaderProcessFilters(t *testing.T) { Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~1", true, utils.INFIELD_SEP), Mandatory: true}, - &config.FCTemplate{Tag: "FilterType", - FieldId: "FilterType", + &config.FCTemplate{Tag: "Type", + FieldId: "Type", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~2", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FilterFieldName", - FieldId: "FilterFieldName", + &config.FCTemplate{Tag: "Element", + FieldId: "Element", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~3", true, utils.INFIELD_SEP)}, - &config.FCTemplate{Tag: "FilterFieldValues", - FieldId: "FilterFieldValues", + &config.FCTemplate{Tag: "Values", + FieldId: "Values", Type: utils.META_COMPOSED, Value: config.NewRSRParsersMustCompile("~4", true, utils.INFIELD_SEP)}, &config.FCTemplate{Tag: "ActivationInterval", @@ -388,19 +388,19 @@ func TestLoaderProcessFilters(t *testing.T) { ID: "FLTR_1", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaString, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, - Values: []string{"1001", "1002"}, + Type: utils.MetaString, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Values: []string{"1001", "1002"}, }, &engine.FilterRule{ - Type: "*prefix", - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Values: []string{"10", "20"}, + Type: "*prefix", + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Values: []string{"10", "20"}, }, &engine.FilterRule{ - Type: "*rsr", - FieldName: "", - Values: []string{"~*req.Subject(~^1.*1$)", "~*req.Destination(1002)"}, + Type: "*rsr", + Element: "", + Values: []string{"~*req.Subject(~^1.*1$)", "~*req.Destination(1002)"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -416,9 +416,9 @@ func TestLoaderProcessFilters(t *testing.T) { ID: "FLTR_DST_DE", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: "*destinations", - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, - Values: []string{"DST_DE"}, + Type: "*destinations", + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Values: []string{"DST_DE"}, }, }, ActivationInterval: &utils.ActivationInterval{ @@ -1151,13 +1151,13 @@ func TestLoaderRemoveContentSingleFile(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{"*string:~*req.Field1:Initial"}, - FieldName: "Field1", + Path: utils.MetaReq + utils.NestingSep + "Field1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Sub1", true, utils.INFIELD_SEP), }, &engine.Attribute{ FilterIDs: []string{}, - FieldName: "Field2", + Path: utils.MetaReq + utils.NestingSep + "Field2", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Sub2", true, utils.INFIELD_SEP), }}, diff --git a/migrator/alias.go b/migrator/alias.go index 621a31ebe..3393e101e 100644 --- a/migrator/alias.go +++ b/migrator/alias.go @@ -105,13 +105,17 @@ func alias2AtttributeProfile(alias *v1Alias, defaultTenant string) *engine.Attri } for fieldName, vals := range av.Pairs { for initial, substitute := range vals { + var fld string if fieldName == utils.Tenant { fieldName = utils.MetaTenant + fld = utils.MetaTenant + } else { + fld = utils.MetaReq + utils.NestingSep + fieldName } attr := &engine.Attribute{ - FieldName: fieldName, - Type: utils.MetaVariable, //default type for Attribute - Value: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP), + Path: fld, + Type: utils.MetaVariable, //default type for Attribute + Value: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP), } out.Attributes = append(out.Attributes, attr) // Add attribute filters if needed diff --git a/migrator/alias_it_test.go b/migrator/alias_it_test.go index 4074ee493..e9fd07795 100644 --- a/migrator/alias_it_test.go +++ b/migrator/alias_it_test.go @@ -144,13 +144,13 @@ func testAlsITMigrateAndMove(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: "Account", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Account", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, { FilterIDs: []string{"*string:~*req.Category:call_1001"}, - FieldName: "Category", + Path: utils.MetaReq + utils.NestingSep + "Category", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("call_1002", true, utils.INFIELD_SEP), }, @@ -193,10 +193,10 @@ func testAlsITMigrateAndMove(t *testing.T) { } result.Compile() sort.Slice(result.Attributes, func(i, j int) bool { - if result.Attributes[i].FieldName == result.Attributes[j].FieldName { + if result.Attributes[i].Path == result.Attributes[j].Path { return result.Attributes[i].FilterIDs[0] < result.Attributes[j].FilterIDs[0] } - return result.Attributes[i].FieldName < result.Attributes[j].FieldName + return result.Attributes[i].Path < result.Attributes[j].Path }) // only for test; map returns random keys if !reflect.DeepEqual(*attrProf, *result) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrProf), utils.ToJSON(result)) diff --git a/migrator/alias_test.go b/migrator/alias_test.go index 2c9cbb80b..885399bd6 100644 --- a/migrator/alias_test.go +++ b/migrator/alias_test.go @@ -181,7 +181,7 @@ func TestAlias2AtttributeProfile(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, @@ -198,13 +198,13 @@ func TestAlias2AtttributeProfile(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, { FilterIDs: []string{"*string:~*req.Account:1003"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP), }, @@ -221,13 +221,13 @@ func TestAlias2AtttributeProfile(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, { FilterIDs: []string{"*string:~*req.Account:1003"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP), }, @@ -247,14 +247,14 @@ func TestAlias2AtttributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: "Account", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Account", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, { - FieldName: "Subject", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("call_1001", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Subject", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("call_1001", true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -272,12 +272,12 @@ func TestAlias2AtttributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: "Account", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Account", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, { - FieldName: "Category", + Path: utils.MetaReq + utils.NestingSep + "Category", Type: utils.MetaVariable, FilterIDs: []string{"*string:~*req.Category:call_1001"}, Value: config.NewRSRParsersMustCompile("call_1002", true, utils.INFIELD_SEP), @@ -295,9 +295,9 @@ func TestAlias2AtttributeProfile(t *testing.T) { }, Attributes: []*engine.Attribute{ { - FieldName: utils.Category, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("somecateg_roam_fromz4", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Category, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("somecateg_roam_fromz4", true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -306,10 +306,10 @@ func TestAlias2AtttributeProfile(t *testing.T) { for i := range expected { rply := alias2AtttributeProfile(aliases[i], defaultTenant) sort.Slice(rply.Attributes, func(i, j int) bool { - if rply.Attributes[i].FieldName == rply.Attributes[j].FieldName { + if rply.Attributes[i].Path == rply.Attributes[j].Path { return rply.Attributes[i].FilterIDs[0] < rply.Attributes[j].FilterIDs[0] } - return rply.Attributes[i].FieldName < rply.Attributes[j].FieldName + return rply.Attributes[i].Path < rply.Attributes[j].Path }) // only for test; map returns random keys if !reflect.DeepEqual(expected[i], rply) { t.Errorf("For %v expected: %s ,recived: %s ", i, utils.ToJSON(expected[i]), utils.ToJSON(rply)) diff --git a/migrator/attributes.go b/migrator/attributes.go index d0a32be4e..1b0170f19 100644 --- a/migrator/attributes.go +++ b/migrator/attributes.go @@ -67,7 +67,7 @@ func (m *Migrator) migrateCurrentAttributeProfile() (err error) { idg, utils.NonTransactional, false); err != nil { return err } - m.stats[utils.Attributes] += 1 + m.stats[utils.Attributes]++ } return } @@ -98,7 +98,7 @@ func (m *Migrator) migrateV1Attributes() (err error) { if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil { return err } - m.stats[utils.Attributes] += 1 + m.stats[utils.Attributes]++ } if m.dryRun { return @@ -137,7 +137,7 @@ func (m *Migrator) migrateV2Attributes() (err error) { if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil { return err } - m.stats[utils.Attributes] += 1 + m.stats[utils.Attributes]++ } if m.dryRun { return @@ -176,7 +176,46 @@ func (m *Migrator) migrateV3Attributes() (err error) { if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil { return err } - m.stats[utils.Attributes] += 1 + m.stats[utils.Attributes]++ + } + if m.dryRun { + return + } + // All done, update version wtih current one + vrs := engine.Versions{utils.Attributes: engine.CurrentDataDBVersions()[utils.Attributes]} + if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when updating Thresholds version into dataDB", err.Error())) + } + return +} + +func (m *Migrator) migrateV4Attributes() (err error) { + var v4Attr *v4AttributeProfile + for { + v4Attr, err = m.dmIN.getV4AttributeProfile() + if err != nil && err != utils.ErrNoMoreData { + return err + } + if err == utils.ErrNoMoreData { + break + } + if v4Attr == nil { + continue + } + attrPrf, err := v4Attr.AsAttributeProfile() + if err != nil { + return err + } + if m.dryRun { + continue + } + if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil { + return err + } + m.stats[utils.Attributes]++ } if m.dryRun { return @@ -227,6 +266,10 @@ func (m *Migrator) migrateAttributeProfile() (err error) { if err = m.migrateV3Attributes(); err != nil { return err } + case 4: + if err = m.migrateV4Attributes(); err != nil { + return err + } } return m.ensureIndexesDataDB(engine.ColAttr) } @@ -257,7 +300,7 @@ func (v1AttrPrf v1AttributeProfile) AsAttributeProfile() (attrPrf *engine.Attrib } attrPrf.Attributes = append(attrPrf.Attributes, &engine.Attribute{ FilterIDs: filterIDs, - FieldName: attr.FieldName, + Path: utils.MetaReq + utils.NestingSep + attr.FieldName, Value: sbstPrsr, Type: utils.MetaVariable, }) @@ -308,7 +351,7 @@ func (v2AttrPrf v2AttributeProfile) AsAttributeProfile() (attrPrf *engine.Attrib } attrPrf.Attributes = append(attrPrf.Attributes, &engine.Attribute{ FilterIDs: filterIDs, - FieldName: attr.FieldName, + Path: utils.MetaReq + utils.NestingSep + attr.FieldName, Value: attr.Substitute, Type: utils.MetaVariable, }) @@ -344,10 +387,48 @@ func (v3AttrPrf v3AttributeProfile) AsAttributeProfile() (attrPrf *engine.Attrib for _, attr := range v3AttrPrf.Attributes { attrPrf.Attributes = append(attrPrf.Attributes, &engine.Attribute{ FilterIDs: attr.FilterIDs, - FieldName: attr.FieldName, + Path: utils.MetaReq + utils.NestingSep + attr.FieldName, Value: attr.Substitute, Type: utils.MetaVariable, //default value for type }) } return } + +type v4Attribute struct { + FilterIDs []string + FieldName string + Type string + Value config.RSRParsers +} + +type v4AttributeProfile struct { + Tenant string + ID string + Contexts []string // bind this AttributeProfile to multiple contexts + FilterIDs []string + ActivationInterval *utils.ActivationInterval // Activation interval + Attributes []*v4Attribute + Blocker bool // blocker flag to stop processing on multiple runs + Weight float64 +} + +func (v4AttrPrf v4AttributeProfile) AsAttributeProfile() (attrPrf *engine.AttributeProfile, err error) { + attrPrf = &engine.AttributeProfile{ + Tenant: v4AttrPrf.Tenant, + ID: v4AttrPrf.ID, + Contexts: v4AttrPrf.Contexts, + FilterIDs: v4AttrPrf.FilterIDs, + Weight: v4AttrPrf.Weight, + ActivationInterval: v4AttrPrf.ActivationInterval, + } + for _, attr := range v4AttrPrf.Attributes { + attrPrf.Attributes = append(attrPrf.Attributes, &engine.Attribute{ + FilterIDs: attr.FilterIDs, + Path: utils.MetaReq + utils.NestingSep + attr.FieldName, + Value: attr.Value, + Type: attr.Type, + }) + } + return +} diff --git a/migrator/attributes_it_test.go b/migrator/attributes_it_test.go index 8f812ab9f..bd0c160b0 100755 --- a/migrator/attributes_it_test.go +++ b/migrator/attributes_it_test.go @@ -51,6 +51,8 @@ var sTestsAttrIT = []func(t *testing.T){ testAttrITMigrateV2, testAttrITFlush, testAttrITMigrateV3, + testAttrITFlush, + testAttrITMigrateV4, } func TestAttributeITRedis(t *testing.T) { @@ -254,7 +256,7 @@ func testAttrITMigrateOnlyVersion(t *testing.T) { if vrs, err := attrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { t.Error(err) - } else if vrs[utils.Attributes] != 4 { + } else if vrs[utils.Attributes] != 5 { t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) } } @@ -292,7 +294,7 @@ func testAttrITMigrateAndMove(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:FL1:In1"}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, @@ -324,7 +326,7 @@ func testAttrITMigrateAndMove(t *testing.T) { if vrs, err := attrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { t.Error(err) - } else if vrs[utils.Attributes] != 4 { + } else if vrs[utils.Attributes] != 5 { t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) } result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", @@ -412,7 +414,7 @@ func testAttrITMigrateV2(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:FL1:In1"}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, @@ -443,7 +445,7 @@ func testAttrITMigrateV2(t *testing.T) { if vrs, err := attrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { t.Error(err) - } else if vrs[utils.Attributes] != 4 { + } else if vrs[utils.Attributes] != 5 { t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) } result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", @@ -494,7 +496,7 @@ func testAttrITMigrateV3(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:FL1:In1"}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, @@ -525,7 +527,90 @@ func testAttrITMigrateV3(t *testing.T) { if vrs, err := attrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { t.Error(err) - } else if vrs[utils.Attributes] != 4 { + } else if vrs[utils.Attributes] != 5 { + t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) + } + result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", + "ATTR_1", false, false, utils.NonTransactional) + if err != nil { + t.Fatal("Error when getting Attribute ", err.Error()) + } + result.Compile() + attrPrf.Compile() + if !reflect.DeepEqual(result, attrPrf) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(result)) + } +} + +func testAttrITMigrateV4(t *testing.T) { + if attrAction != utils.Migrate { + return + } + + v4attr := &v4AttributeProfile{ + Tenant: "cgrates.org", + ID: "ATTR_1", + Contexts: []string{utils.MetaSessionS}, + FilterIDs: []string{"*string:Accont:1001"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + }, + Attributes: []*v4Attribute{ + &v4Attribute{ + FilterIDs: []string{"*string:FL1:In1"}, + FieldName: "FL1", + Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), + Type: utils.MetaVariable, + }, + }, + Weight: 20, + } + + attrPrf := &engine.AttributeProfile{ + Tenant: "cgrates.org", + ID: "ATTR_1", + Contexts: []string{utils.MetaSessionS}, + FilterIDs: []string{"*string:Accont:1001"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + }, + Attributes: []*engine.Attribute{ + { + FilterIDs: []string{"*string:FL1:In1"}, + Path: utils.MetaReq + utils.NestingSep + "FL1", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), + }, + }, + Weight: 20, + } + + err := attrMigrator.dmIN.setV4AttributeProfile(v4attr) + if err != nil { + t.Error("Error when setting v3 AttributeProfile ", err.Error()) + } + currentVersion := engine.Versions{utils.Attributes: 4} + err = attrMigrator.dmIN.DataManager().DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for Attributes ", err.Error()) + } + + if vrs, err := attrMigrator.dmIN.DataManager().DataDB().GetVersions(""); err != nil { + t.Error(err) + } else if vrs[utils.Attributes] != 4 { + t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) + } + + err, _ = attrMigrator.Migrate([]string{utils.MetaAttributes}) + if err != nil { + t.Error("Error when migrating Attributes ", err.Error()) + } + + if vrs, err := attrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { + t.Error(err) + } else if vrs[utils.Attributes] != 5 { t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) } result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org", diff --git a/migrator/attributes_test.go b/migrator/attributes_test.go index 0417ee26d..f67d59fa9 100644 --- a/migrator/attributes_test.go +++ b/migrator/attributes_test.go @@ -61,7 +61,7 @@ func TestV1AttributeProfileAsAttributeProfile(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{"*string:FL1:In1"}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, @@ -108,7 +108,7 @@ func TestV2AttributeProfileAsAttributeProfile(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{"*string:FL1:In1"}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, @@ -155,7 +155,7 @@ func TestV2AttributeProfileAsAttributeProfile2(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, @@ -201,7 +201,7 @@ func TestV3AttributeProfileAsAttributeProfile(t *testing.T) { Attributes: []*engine.Attribute{ &engine.Attribute{ FilterIDs: []string{"*string:FL1:In1"}, - FieldName: "FL1", + Path: utils.MetaReq + utils.NestingSep + "FL1", Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP), }, diff --git a/migrator/derived_chargers.go b/migrator/derived_chargers.go index 1ff0dfb66..29399148d 100644 --- a/migrator/derived_chargers.go +++ b/migrator/derived_chargers.go @@ -83,9 +83,9 @@ func fieldinfo2Attribute(attr []*engine.Attribute, fieldName, fieldInfo string) return attr } return append(attr, &engine.Attribute{ - FieldName: fieldName, - Value: rp, - Type: utils.MetaVariable, + Path: utils.MetaReq + utils.NestingSep + fieldName, + Value: rp, + Type: utils.MetaVariable, }) } diff --git a/migrator/derived_chargers_it_test.go b/migrator/derived_chargers_it_test.go index cd1f68120..631ceaae2 100644 --- a/migrator/derived_chargers_it_test.go +++ b/migrator/derived_chargers_it_test.go @@ -149,14 +149,14 @@ func testDCITMigrateAndMove(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: utils.Account, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("call_1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("call_1003", true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -210,7 +210,7 @@ func testDCITMigrateAndMove(t *testing.T) { } result.Compile() sort.Slice(result.Attributes, func(i, j int) bool { - return result.Attributes[i].FieldName < result.Attributes[j].FieldName + return result.Attributes[i].Path < result.Attributes[j].Path }) // only for test; map returns random keys if !reflect.DeepEqual(*attrProf, *result) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrProf), utils.ToJSON(result)) diff --git a/migrator/derived_chargers_test.go b/migrator/derived_chargers_test.go index 2c3b6d798..ff3854039 100644 --- a/migrator/derived_chargers_test.go +++ b/migrator/derived_chargers_test.go @@ -29,74 +29,74 @@ import ( func TestFieldinfo2Attribute(t *testing.T) { type testA struct { - FieldName string + Path string FieldInfo string Initial []*engine.Attribute Expected []*engine.Attribute } tests := []testA{ testA{ - FieldName: utils.Account, + Path: utils.Account, FieldInfo: utils.MetaDefault, Initial: make([]*engine.Attribute, 0), Expected: make([]*engine.Attribute, 0), }, testA{ - FieldName: utils.Account, + Path: utils.Account, FieldInfo: "", Initial: make([]*engine.Attribute, 0), Expected: make([]*engine.Attribute, 0), }, testA{ - FieldName: utils.Account, + Path: utils.Account, FieldInfo: "^1003", Initial: make([]*engine.Attribute, 0), Expected: []*engine.Attribute{ &engine.Attribute{ - FieldName: utils.Account, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), }, }, }, testA{ - FieldName: utils.Subject, + Path: utils.Subject, FieldInfo: `~effective_caller_id_number:s/(\d+)/+$1/`, Initial: make([]*engine.Attribute, 0), Expected: []*engine.Attribute{ &engine.Attribute{ - FieldName: utils.Subject, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile(`~effective_caller_id_number:s/(\d+)/+$1/`, true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile(`~effective_caller_id_number:s/(\d+)/+$1/`, true, utils.INFIELD_SEP), }, }, }, testA{ - FieldName: utils.Subject, + Path: utils.Subject, FieldInfo: "^call_1003", Initial: []*engine.Attribute{ &engine.Attribute{ - FieldName: utils.Account, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), }, }, Expected: []*engine.Attribute{ &engine.Attribute{ - FieldName: utils.Account, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), }, &engine.Attribute{ - FieldName: utils.Subject, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("call_1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("call_1003", true, utils.INFIELD_SEP), }, }, }, } for i, v := range tests { - if rply := fieldinfo2Attribute(v.Initial, v.FieldName, v.FieldInfo); !reflect.DeepEqual(v.Expected, rply) { + if rply := fieldinfo2Attribute(v.Initial, v.Path, v.FieldInfo); !reflect.DeepEqual(v.Expected, rply) { t.Errorf("For %v expected: %s ,recieved: %s", i, utils.ToJSON(v.Expected), utils.ToJSON(rply)) } } @@ -128,14 +128,14 @@ func TestDerivedChargers2AttributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ &engine.Attribute{ - FieldName: utils.Category, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("*voice", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Category, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("*voice", true, utils.INFIELD_SEP), }, &engine.Attribute{ - FieldName: utils.Account, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -161,24 +161,24 @@ func TestDerivedChargers2AttributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ &engine.Attribute{ - FieldName: utils.Category, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("*voice", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Category, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("*voice", true, utils.INFIELD_SEP), }, &engine.Attribute{ - FieldName: utils.Account, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Account, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1003", true, utils.INFIELD_SEP), }, &engine.Attribute{ - FieldName: utils.Subject, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("call_1003_to_1004", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("call_1003_to_1004", true, utils.INFIELD_SEP), }, &engine.Attribute{ - FieldName: utils.Destination, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Destination, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP), }, }, Blocker: false, diff --git a/migrator/filters.go b/migrator/filters.go index 5ea4505bc..816db9381 100644 --- a/migrator/filters.go +++ b/migrator/filters.go @@ -49,7 +49,7 @@ func (m *Migrator) migrateCurrentRequestFilter() (err error) { if err := m.dmOut.DataManager().SetFilter(fl); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -57,20 +57,42 @@ func (m *Migrator) migrateCurrentRequestFilter() (err error) { var filterTypes = utils.NewStringSet([]string{utils.MetaRSR, utils.MetaStatS, utils.MetaResources, utils.MetaNotRSR, utils.MetaNotStatS, utils.MetaNotResources}) -func migrateFilterV1(fl *engine.Filter) *engine.Filter { +func migrateFilterV1(fl *v1Filter) (fltr *engine.Filter) { + fltr = &engine.Filter{ + Tenant: fl.Tenant, + ID: fl.ID, + Rules: make([]*engine.FilterRule, len(fl.Rules)), + ActivationInterval: fl.ActivationInterval, + } for i, rule := range fl.Rules { + fltr.Rules[i] = &engine.FilterRule{ + Type: rule.Type, + Element: rule.FieldName, + Values: rule.Values, + } if rule.FieldName == "" || strings.HasPrefix(rule.FieldName, utils.DynamicDataPrefix) || filterTypes.Has(rule.Type) { continue } - fl.Rules[i].FieldName = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + rule.FieldName + fltr.Rules[i].Element = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + rule.FieldName } - return fl + return } -func migrateFilterV2(fl *engine.Filter) *engine.Filter { +func migrateFilterV2(fl *v1Filter) (fltr *engine.Filter) { + fltr = &engine.Filter{ + Tenant: fl.Tenant, + ID: fl.ID, + Rules: make([]*engine.FilterRule, len(fl.Rules)), + ActivationInterval: fl.ActivationInterval, + } for i, rule := range fl.Rules { + fltr.Rules[i] = &engine.FilterRule{ + Type: rule.Type, + Element: rule.FieldName, + Values: rule.Values, + } if (rule.FieldName == "" && rule.Type != utils.MetaRSR) || strings.HasPrefix(rule.FieldName, utils.DynamicDataPrefix+utils.MetaReq) || strings.HasPrefix(rule.FieldName, utils.DynamicDataPrefix+utils.MetaVars) || @@ -86,18 +108,35 @@ func migrateFilterV2(fl *engine.Filter) *engine.Filter { if strings.HasPrefix(rule.FieldName, utils.DynamicDataPrefix) { fl.Rules[i].FieldName = fl.Rules[i].FieldName[1:] } - fl.Rules[i].FieldName = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + rule.FieldName + fltr.Rules[i].Element = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + rule.FieldName } else { for idx, val := range rule.Values { if strings.HasPrefix(val, utils.DynamicDataPrefix) { // remove dynamic data prefix from fieldName val = val[1:] } - fl.Rules[i].Values[idx] = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + val + fltr.Rules[i].Values[idx] = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + val } } } - return fl + return +} + +func migrateFilterV3(fl *v1Filter) (fltr *engine.Filter) { + fltr = &engine.Filter{ + Tenant: fl.Tenant, + ID: fl.ID, + Rules: make([]*engine.FilterRule, len(fl.Rules)), + ActivationInterval: fl.ActivationInterval, + } + for i, rule := range fl.Rules { + fltr.Rules[i] = &engine.FilterRule{ + Type: rule.Type, + Element: rule.FieldName, + Values: rule.Values, + } + } + return } func migrateInlineFilter(fl string) string { @@ -141,36 +180,30 @@ func migrateInlineFilterV2(fl string) string { ruleSplt[1] = ruleSplt[1][1:] } return fmt.Sprintf("%s:~%s:%s", ruleSplt[0], utils.MetaReq+utils.NestingSep+ruleSplt[1], strings.Join(ruleSplt[2:], utils.InInFieldSep)) - } else { // in case of *rsr filter we need to add the prefix at fieldValue - if strings.HasPrefix(ruleSplt[2], utils.DynamicDataPrefix) { - // remove dynamic data prefix from fieldName - ruleSplt[2] = ruleSplt[2][1:] - } - return fmt.Sprintf("%s::~%s", ruleSplt[0], utils.MetaReq+utils.NestingSep+strings.Join(ruleSplt[2:], utils.InInFieldSep)) + } // in case of *rsr filter we need to add the prefix at fieldValue + if strings.HasPrefix(ruleSplt[2], utils.DynamicDataPrefix) { + // remove dynamic data prefix from fieldName + ruleSplt[2] = ruleSplt[2][1:] } - + return fmt.Sprintf("%s::~%s", ruleSplt[0], utils.MetaReq+utils.NestingSep+strings.Join(ruleSplt[2:], utils.InInFieldSep)) } func (m *Migrator) migrateRequestFilterV1() (err error) { - var ids []string - tenant := config.CgrConfig().GeneralCfg().DefaultTenant - ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.FilterPrefix) - if err != nil { - return err - } - for _, id := range ids { - idg := strings.TrimPrefix(id, utils.FilterPrefix+tenant+":") - fl, err := engine.GetFilter(m.dmIN.DataManager(), tenant, idg, false, false, utils.NonTransactional) - if err != nil { + for { + fl, err := m.dmIN.getV1Filter() + if err != nil && err != utils.ErrNoMoreData { return err } + if err == utils.ErrNoMoreData { + break + } if m.dryRun || fl == nil { continue } if err := m.dmOut.DataManager().SetFilter(migrateFilterV1(fl)); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } if err = m.migrateResourceProfileFiltersV1(); err != nil { return err @@ -193,7 +226,7 @@ func (m *Migrator) migrateRequestFilterV1() (err error) { if err = m.migrateDispatcherProfileFiltersV1(); err != nil { return err } - vrs := engine.Versions{utils.RQF: 2} + vrs := engine.Versions{utils.RQF: engine.CurrentDataDBVersions()[utils.RQF]} if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, @@ -204,27 +237,22 @@ func (m *Migrator) migrateRequestFilterV1() (err error) { } func (m *Migrator) migrateRequestFilterV2() (err error) { - var ids []string - tenant := config.CgrConfig().GeneralCfg().DefaultTenant - ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.FilterPrefix) - if err != nil { - return fmt.Errorf("Error: <%s> when getting filter IDs for migration", err.Error()) - } - for _, id := range ids { - idg := strings.TrimPrefix(id, utils.FilterPrefix+tenant+":") - fl, err := engine.GetFilter(m.dmIN.DataManager(), tenant, idg, false, false, utils.NonTransactional) - if err != nil { - return fmt.Errorf("Error: <%s> when getting filter with tenant: <%s> and id: <%s> for migration", - err.Error(), tenant, idg) + for { + fl, err := m.dmIN.getV1Filter() + if err != nil && err != utils.ErrNoMoreData { + return err + } + if err == utils.ErrNoMoreData { + break } if m.dryRun || fl == nil { continue } if err := m.dmOut.DataManager().SetFilter(migrateFilterV2(fl)); err != nil { return fmt.Errorf("Error: <%s> when setting filter with tenant: <%s> and id: <%s> after migration", - err.Error(), tenant, idg) + err.Error(), fl.Tenant, fl.ID) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } if err = m.migrateResourceProfileFiltersV2(); err != nil { return fmt.Errorf("Error: <%s> when trying to migrate filter for ResourceProfiles", @@ -264,6 +292,34 @@ func (m *Migrator) migrateRequestFilterV2() (err error) { return } +func (m *Migrator) migrateRequestFilterV3() (err error) { + for { + fl, err := m.dmIN.getV1Filter() + if err != nil && err != utils.ErrNoMoreData { + return err + } + if err == utils.ErrNoMoreData { + break + } + if m.dryRun || fl == nil { + continue + } + if err := m.dmOut.DataManager().SetFilter(migrateFilterV3(fl)); err != nil { + return fmt.Errorf("Error: <%s> when setting filter with tenant: <%s> and id: <%s> after migration", + err.Error(), fl.Tenant, fl.ID) + } + m.stats[utils.RQF]++ + } + vrs := engine.Versions{utils.RQF: engine.CurrentDataDBVersions()[utils.RQF]} + if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when updating Filters version into dataDB", err.Error())) + } + return +} + func (m *Migrator) migrateFilters() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() @@ -280,6 +336,10 @@ func (m *Migrator) migrateFilters() (err error) { "version number is not defined for ActionTriggers model") } switch vrs[utils.RQF] { + case 3: + if err = m.migrateRequestFilterV3(); err != nil { + return err + } case 2: if err = m.migrateRequestFilterV2(); err != nil { return err @@ -321,7 +381,7 @@ func (m *Migrator) migrateResourceProfileFiltersV1() (err error) { if err := m.dmOut.DataManager().SetResourceProfile(res, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -348,7 +408,7 @@ func (m *Migrator) migrateStatQueueProfileFiltersV1() (err error) { if err = m.dmOut.DataManager().SetStatQueueProfile(sgs, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -375,7 +435,7 @@ func (m *Migrator) migrateThresholdsProfileFiltersV1() (err error) { if err := m.dmOut.DataManager().SetThresholdProfile(ths, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -402,7 +462,7 @@ func (m *Migrator) migrateSupplierProfileFiltersV1() (err error) { if err := m.dmOut.DataManager().SetSupplierProfile(splp, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -434,7 +494,7 @@ func (m *Migrator) migrateAttributeProfileFiltersV1() (err error) { if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -461,7 +521,7 @@ func (m *Migrator) migrateChargerProfileFiltersV1() (err error) { if err := m.dmOut.DataManager().SetChargerProfile(cpp, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -488,7 +548,7 @@ func (m *Migrator) migrateDispatcherProfileFiltersV1() (err error) { if err := m.dmOut.DataManager().SetDispatcherProfile(dpp, true); err != nil { return err } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -518,7 +578,7 @@ func (m *Migrator) migrateResourceProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting resource profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -547,7 +607,7 @@ func (m *Migrator) migrateStatQueueProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting statQueue profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -576,7 +636,7 @@ func (m *Migrator) migrateThresholdsProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting threshold profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -605,7 +665,7 @@ func (m *Migrator) migrateSupplierProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting supplier profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -639,7 +699,7 @@ func (m *Migrator) migrateAttributeProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting attribute profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -668,7 +728,7 @@ func (m *Migrator) migrateChargerProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting charger profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } @@ -697,7 +757,22 @@ func (m *Migrator) migrateDispatcherProfileFiltersV2() (err error) { return fmt.Errorf("error: <%s> when setting dispatcher profile with tenant: <%s> and id: <%s>", err.Error(), tenant, idg) } - m.stats[utils.RQF] += 1 + m.stats[utils.RQF]++ } return } + +type v1Filter struct { + Tenant string + ID string + Rules []*v1FilterRule + ActivationInterval *utils.ActivationInterval +} + +type v1FilterRule struct { + Type string // Filter type (*string, *timing, *rsr_filters, *stats, *lt, *lte, *gt, *gte) + FieldName string // Name of the field providing us the Values to check (used in case of some ) + Values []string // Filter definition + rsrFields config.RSRParsers // Cache here the RSRFilter Values + negative *bool +} diff --git a/migrator/filters_it_test.go b/migrator/filters_it_test.go index 33e46b2a1..7cb1140f2 100644 --- a/migrator/filters_it_test.go +++ b/migrator/filters_it_test.go @@ -42,7 +42,10 @@ var sTestsFltrIT = []func(t *testing.T){ testFltrITConnect, testFltrITFlush, testFltrITMigrateAndMove, + testFltrITFlush, testFltrITMigratev2, + testFltrITFlush, + testFltrITMigratev3, } func TestFiltersMigrateITRedis(t *testing.T) { @@ -130,11 +133,11 @@ func testFltrITFlush(t *testing.T) { } func testFltrITMigrateAndMove(t *testing.T) { - Filters := &engine.Filter{ + Filters := &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_2", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaPrefix, FieldName: "Account", Values: []string{"1001"}, @@ -146,9 +149,9 @@ func testFltrITMigrateAndMove(t *testing.T) { ID: "FLTR_2", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaPrefix, - FieldName: "~*req.Account", - Values: []string{"1001"}, + Type: utils.MetaPrefix, + Element: "~*req.Account", + Values: []string{"1001"}, }, }, } @@ -162,7 +165,7 @@ func testFltrITMigrateAndMove(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, }, @@ -177,7 +180,7 @@ func testFltrITMigrateAndMove(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, }, @@ -187,7 +190,7 @@ func testFltrITMigrateAndMove(t *testing.T) { attrProf.Compile() switch fltrAction { case utils.Migrate: - if err := fltrMigrator.dmIN.DataManager().SetFilter(Filters); err != nil { + if err := fltrMigrator.dmIN.setV1Filter(Filters); err != nil { t.Error("Error when setting v1 Filters ", err.Error()) } if err := fltrMigrator.dmIN.DataManager().SetAttributeProfile(attrProf, false); err != nil { @@ -212,7 +215,7 @@ func testFltrITMigrateAndMove(t *testing.T) { //check if version was updated if vrs, err := fltrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { t.Error(err) - } else if vrs[utils.RQF] != 2 { + } else if vrs[utils.RQF] != 4 { t.Errorf("Unexpected version returned: %d", vrs[utils.RQF]) } //check if Filters was migrate correctly @@ -243,7 +246,7 @@ func testFltrITMigrateAndMove(t *testing.T) { t.Errorf("Expected %v, recived: %v", utils.ToJSON(expFltrIdx), utils.ToJSON(fltridx)) } case utils.Move: - if err := fltrMigrator.dmIN.DataManager().SetFilter(Filters); err != nil { + if err := fltrMigrator.dmIN.DataManager().SetFilter(expFilters); err != nil { t.Error(err) } currentVersion := engine.CurrentDataDBVersions() @@ -257,16 +260,16 @@ func testFltrITMigrateAndMove(t *testing.T) { t.Error("Error when fltrMigratorrating Filters ", err.Error()) } //check if account was migrate correctly - result, err := engine.GetFilter(fltrMigrator.dmOut.DataManager(), Filters.Tenant, Filters.ID, false, false, utils.NonTransactional) + result, err := engine.GetFilter(fltrMigrator.dmOut.DataManager(), expFilters.Tenant, expFilters.ID, false, false, utils.NonTransactional) if err != nil { t.Error(err) } result.Compile() - if !reflect.DeepEqual(Filters, result) { - t.Errorf("Expecting: %+v, received: %+v", Filters, result) + if !reflect.DeepEqual(expFilters, result) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expFilters), utils.ToJSON(result)) } // check if old account was deleted - result, err = engine.GetFilter(fltrMigrator.dmIN.DataManager(), Filters.Tenant, Filters.ID, false, false, utils.NonTransactional) + result, err = engine.GetFilter(fltrMigrator.dmIN.DataManager(), expFilters.Tenant, expFilters.ID, false, false, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) } @@ -277,21 +280,21 @@ func testFltrITMigratev2(t *testing.T) { if fltrAction != utils.Migrate { t.SkipNow() } - filters := &engine.Filter{ + filters := &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_2", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaString, FieldName: "~Account", Values: []string{"1001"}, }, - &engine.FilterRule{ + &v1FilterRule{ Type: utils.MetaString, FieldName: "~*req.Subject", Values: []string{"1001"}, }, - &engine.FilterRule{ + &v1FilterRule{ Type: utils.MetaRSR, FieldName: utils.EmptyString, Values: []string{"~Tenant(~^cgr.*\\.org$)"}, @@ -303,19 +306,19 @@ func testFltrITMigratev2(t *testing.T) { ID: "FLTR_2", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaString, - FieldName: "~*req.Account", - Values: []string{"1001"}, + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{"1001"}, }, &engine.FilterRule{ - Type: utils.MetaString, - FieldName: "~*req.Subject", - Values: []string{"1001"}, + Type: utils.MetaString, + Element: "~*req.Subject", + Values: []string{"1001"}, }, &engine.FilterRule{ - Type: utils.MetaRSR, - FieldName: utils.EmptyString, - Values: []string{"~*req.Tenant(~^cgr.*\\.org$)"}, + Type: utils.MetaRSR, + Element: utils.EmptyString, + Values: []string{"~*req.Tenant(~^cgr.*\\.org$)"}, }, }, } @@ -329,7 +332,7 @@ func testFltrITMigratev2(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, }, @@ -344,7 +347,7 @@ func testFltrITMigratev2(t *testing.T) { Attributes: []*engine.Attribute{ { FilterIDs: []string{"*string:~*req.Account:1001"}, - FieldName: "Account", + Path: utils.MetaReq + utils.NestingSep + "Account", Value: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP), }, }, @@ -353,7 +356,7 @@ func testFltrITMigratev2(t *testing.T) { expAttrProf.Compile() attrProf.Compile() - if err := fltrMigrator.dmIN.DataManager().SetFilter(filters); err != nil { + if err := fltrMigrator.dmIN.setV1Filter(filters); err != nil { t.Error("Error when setting v1 Filters ", err.Error()) } if err := fltrMigrator.dmIN.DataManager().SetAttributeProfile(attrProf, false); err != nil { @@ -378,7 +381,7 @@ func testFltrITMigratev2(t *testing.T) { //check if version was updated if vrs, err := fltrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { t.Error(err) - } else if vrs[utils.RQF] != 3 { + } else if vrs[utils.RQF] != 4 { t.Errorf("Unexpected version returned: %d", vrs[utils.RQF]) } //check if Filters was migrate correctly @@ -400,7 +403,6 @@ func testFltrITMigratev2(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expAttrProf), utils.ToJSON(resultAttr)) } expFltrIdx := map[string]utils.StringMap{ - "*prefix:~*req.Account:1001": utils.StringMap{"ATTR_1": true}, "*string:~*req.Account:1001": utils.StringMap{"ATTR_1": true}, "*string:~*req.Subject:1001": utils.StringMap{"ATTR_1": true}, } @@ -411,3 +413,87 @@ func testFltrITMigratev2(t *testing.T) { t.Errorf("Expected %v, recived: %v", utils.ToJSON(expFltrIdx), utils.ToJSON(fltridx)) } } + +func testFltrITMigratev3(t *testing.T) { + if fltrAction != utils.Migrate { + t.SkipNow() + } + filters := &v1Filter{ + Tenant: "cgrates.org", + ID: "FLTR_2", + Rules: []*v1FilterRule{ + &v1FilterRule{ + Type: utils.MetaString, + FieldName: "~*req.Account", + Values: []string{"1001"}, + }, + &v1FilterRule{ + Type: utils.MetaString, + FieldName: "~*req.Subject", + Values: []string{"1001"}, + }, + &v1FilterRule{ + Type: utils.MetaRSR, + FieldName: utils.EmptyString, + Values: []string{"~*req.Tenant(~^cgr.*\\.org$)"}, + }, + }, + } + expFilters := &engine.Filter{ + Tenant: "cgrates.org", + ID: "FLTR_2", + Rules: []*engine.FilterRule{ + &engine.FilterRule{ + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{"1001"}, + }, + &engine.FilterRule{ + Type: utils.MetaString, + Element: "~*req.Subject", + Values: []string{"1001"}, + }, + &engine.FilterRule{ + Type: utils.MetaRSR, + Element: utils.EmptyString, + Values: []string{"~*req.Tenant(~^cgr.*\\.org$)"}, + }, + }, + } + expFilters.Compile() + + if err := fltrMigrator.dmIN.setV1Filter(filters); err != nil { + t.Error("Error when setting v1 Filters ", err.Error()) + } + currentVersion := engine.Versions{utils.RQF: 3} + err := fltrMigrator.dmIN.DataManager().DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for Filters ", err.Error()) + } + //check if version was set correctly + if vrs, err := fltrMigrator.dmIN.DataManager().DataDB().GetVersions(""); err != nil { + t.Error(err) + } else if vrs[utils.RQF] != 3 { + t.Errorf("Unexpected version returned: %d", vrs[utils.RQF]) + } + //migrate Filters + err, _ = fltrMigrator.Migrate([]string{utils.MetaFilters}) + if err != nil { + t.Error("Error when migrating Filters ", err.Error()) + } + //check if version was updated + if vrs, err := fltrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil { + t.Error(err) + } else if vrs[utils.RQF] != 4 { + t.Errorf("Unexpected version returned: %d", vrs[utils.RQF]) + } + //check if Filters was migrate correctly + result, err := engine.GetFilter(fltrMigrator.dmOut.DataManager(), filters.Tenant, filters.ID, false, false, utils.NonTransactional) + if err != nil { + t.Fatalf("Error when getting filters %v", err.Error()) + } + result.Compile() + if !reflect.DeepEqual(*expFilters, *result) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expFilters), utils.ToJSON(result)) + } +} diff --git a/migrator/filters_test.go b/migrator/filters_test.go index 4807987cc..b72a2869b 100644 --- a/migrator/filters_test.go +++ b/migrator/filters_test.go @@ -58,13 +58,16 @@ func TestFiltersInlineMigrate(t *testing.T) { } func TestFiltersMigrate(t *testing.T) { - data := []struct{ in, exp *engine.Filter }{ + data := []struct { + in *v1Filter + exp *engine.Filter + }{ { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_1", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaString, FieldName: "Account", Values: []string{}, @@ -76,19 +79,19 @@ func TestFiltersMigrate(t *testing.T) { ID: "FLTR_1", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaString, - FieldName: "~*req.Account", - Values: []string{}, + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{}, }, }, }, }, { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_2", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaPrefix, FieldName: "~Account", Values: []string{}, @@ -100,9 +103,9 @@ func TestFiltersMigrate(t *testing.T) { ID: "FLTR_2", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaPrefix, - FieldName: "~Account", - Values: []string{}, + Type: utils.MetaPrefix, + Element: "~Account", + Values: []string{}, }, }, }, @@ -116,13 +119,16 @@ func TestFiltersMigrate(t *testing.T) { } func TestFiltersMigrateV2(t *testing.T) { - data := []struct{ in, exp *engine.Filter }{ + data := []struct { + in *v1Filter + exp *engine.Filter + }{ { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_1", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaString, FieldName: "~Account", Values: []string{}, @@ -134,19 +140,19 @@ func TestFiltersMigrateV2(t *testing.T) { ID: "FLTR_1", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaString, - FieldName: "~*req.Account", - Values: []string{}, + Type: utils.MetaString, + Element: "~*req.Account", + Values: []string{}, }, }, }, }, { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_2", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaPrefix, FieldName: "~*req.Account", Values: []string{}, @@ -158,19 +164,19 @@ func TestFiltersMigrateV2(t *testing.T) { ID: "FLTR_2", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaPrefix, - FieldName: "~*req.Account", - Values: []string{}, + Type: utils.MetaPrefix, + Element: "~*req.Account", + Values: []string{}, }, }, }, }, { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_3", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaPrefix, FieldName: "~*act.Account", Values: []string{}, @@ -182,19 +188,19 @@ func TestFiltersMigrateV2(t *testing.T) { ID: "FLTR_3", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaPrefix, - FieldName: "~*act.Account", - Values: []string{}, + Type: utils.MetaPrefix, + Element: "~*act.Account", + Values: []string{}, }, }, }, }, { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_4", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaPrefix, FieldName: "~*act.Account", Values: []string{}, @@ -206,19 +212,19 @@ func TestFiltersMigrateV2(t *testing.T) { ID: "FLTR_4", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaPrefix, - FieldName: "~*act.Account", - Values: []string{}, + Type: utils.MetaPrefix, + Element: "~*act.Account", + Values: []string{}, }, }, }, }, { - in: &engine.Filter{ + in: &v1Filter{ Tenant: "cgrates.org", ID: "FLTR_5", - Rules: []*engine.FilterRule{ - &engine.FilterRule{ + Rules: []*v1FilterRule{ + &v1FilterRule{ Type: utils.MetaPrefix, FieldName: "~*vars.Account", Values: []string{}, @@ -230,9 +236,9 @@ func TestFiltersMigrateV2(t *testing.T) { ID: "FLTR_5", Rules: []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaPrefix, - FieldName: "~*vars.Account", - Values: []string{}, + Type: utils.MetaPrefix, + Element: "~*vars.Account", + Values: []string{}, }, }, }, diff --git a/migrator/migrator_datadb.go b/migrator/migrator_datadb.go index 4b03daf65..82fad78ff 100644 --- a/migrator/migrator_datadb.go +++ b/migrator/migrator_datadb.go @@ -62,6 +62,14 @@ type MigratorDataDB interface { setV3AttributeProfile(x *v3AttributeProfile) (err error) remV3AttributeProfile(tenant, id string) (err error) + getV4AttributeProfile() (v4attrPrf *v4AttributeProfile, err error) + setV4AttributeProfile(x *v4AttributeProfile) (err error) + remV4AttributeProfile(tenant, id string) (err error) + + getV1Filter() (v1Fltr *v1Filter, err error) + setV1Filter(x *v1Filter) (err error) + remV1Filter(tenant, id string) (err error) + DataManager() *engine.DataManager close() } diff --git a/migrator/storage_map_datadb.go b/migrator/storage_map_datadb.go index cd6a5103e..079aac1cd 100755 --- a/migrator/storage_map_datadb.go +++ b/migrator/storage_map_datadb.go @@ -247,4 +247,36 @@ func (iDBMig *internalMigrator) remV3AttributeProfile(tenant, id string) (err er return utils.ErrNotImplemented } +//AttributeProfile methods +//get +func (iDBMig *internalMigrator) getV4AttributeProfile() (v4attrPrf *v4AttributeProfile, err error) { + return nil, utils.ErrNotImplemented +} + +//set +func (iDBMig *internalMigrator) setV4AttributeProfile(x *v4AttributeProfile) (err error) { + return utils.ErrNotImplemented +} + +//rem +func (iDBMig *internalMigrator) remV4AttributeProfile(tenant, id string) (err error) { + return utils.ErrNotImplemented +} + +// Filter Methods +//get +func (iDBMig *internalMigrator) getV1Filter() (v1Fltr *v1Filter, err error) { + return nil, utils.ErrNotImplemented +} + +//set +func (iDBMig *internalMigrator) setV1Filter(x *v1Filter) (err error) { + return utils.ErrNotImplemented +} + +//rem +func (iDBMig *internalMigrator) remV1Filter(tenant, id string) (err error) { + return utils.ErrNotImplemented +} + func (iDBMig *internalMigrator) close() {} diff --git a/migrator/storage_mongo_datadb.go b/migrator/storage_mongo_datadb.go index 0e92dc220..f4bbe86bc 100644 --- a/migrator/storage_mongo_datadb.go +++ b/migrator/storage_mongo_datadb.go @@ -59,12 +59,12 @@ func newMongoMigrator(dm *engine.DataManager) (mgoMig *mongoMigrator) { } } -func (mgoMig *mongoMigrator) close() { - mgoMig.mgoDB.Close() +func (v1ms *mongoMigrator) close() { + v1ms.mgoDB.Close() } -func (mgoMig *mongoMigrator) DataManager() *engine.DataManager { - return mgoMig.dm +func (v1ms *mongoMigrator) DataManager() *engine.DataManager { + return v1ms.dm } //Account methods @@ -588,3 +588,69 @@ func (v1ms *mongoMigrator) remV3AttributeProfile(tenant, id string) (err error) _, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).DeleteOne(v1ms.mgoDB.GetContext(), bson.M{"tenant": tenant, "id": id}) return } + +//AttributeProfile methods +//get +func (v1ms *mongoMigrator) getV4AttributeProfile() (v4attrPrf *v4AttributeProfile, err error) { + if v1ms.cursor == nil { + v1ms.cursor, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).Find(v1ms.mgoDB.GetContext(), bson.D{}) + if err != nil { + return nil, err + } + } + if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { + (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) + v1ms.cursor = nil + return nil, utils.ErrNoMoreData + } + v4attrPrf = new(v4AttributeProfile) + if err := (*v1ms.cursor).Decode(v4attrPrf); err != nil { + return nil, err + } + return v4attrPrf, nil +} + +//set +func (v1ms *mongoMigrator) setV4AttributeProfile(x *v4AttributeProfile) (err error) { + _, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).InsertOne(v1ms.mgoDB.GetContext(), x) + return +} + +//rem +func (v1ms *mongoMigrator) remV4AttributeProfile(tenant, id string) (err error) { + _, err = v1ms.mgoDB.DB().Collection(v1AttributeProfilesCol).DeleteOne(v1ms.mgoDB.GetContext(), bson.M{"tenant": tenant, "id": id}) + return +} + +// Filter Methods +//get +func (v1ms *mongoMigrator) getV1Filter() (v1Fltr *v1Filter, err error) { + if v1ms.cursor == nil { + v1ms.cursor, err = v1ms.mgoDB.DB().Collection(engine.ColFlt).Find(v1ms.mgoDB.GetContext(), bson.D{}) + if err != nil { + return nil, err + } + } + if !(*v1ms.cursor).Next(v1ms.mgoDB.GetContext()) { + (*v1ms.cursor).Close(v1ms.mgoDB.GetContext()) + v1ms.cursor = nil + return nil, utils.ErrNoMoreData + } + v1Fltr = new(v1Filter) + if err := (*v1ms.cursor).Decode(v1Fltr); err != nil { + return nil, err + } + return +} + +//set +func (v1ms *mongoMigrator) setV1Filter(x *v1Filter) (err error) { + _, err = v1ms.mgoDB.DB().Collection(engine.ColFlt).InsertOne(v1ms.mgoDB.GetContext(), x) + return +} + +//rem +func (v1ms *mongoMigrator) remV1Filter(tenant, id string) (err error) { + _, err = v1ms.mgoDB.DB().Collection(engine.ColFlt).DeleteOne(v1ms.mgoDB.GetContext(), bson.M{"tenant": tenant, "id": id}) + return +} diff --git a/migrator/storage_redis.go b/migrator/storage_redis.go index c1dfdca56..345af4cd1 100644 --- a/migrator/storage_redis.go +++ b/migrator/storage_redis.go @@ -34,7 +34,7 @@ type redisMigrator struct { } var ( - REVERSE_ALIASES_PREFIX = "rls_" + reverseAliasesPrefix = "rls_" ) func newRedisMigrator(dm *engine.DataManager) (rM *redisMigrator) { @@ -44,12 +44,12 @@ func newRedisMigrator(dm *engine.DataManager) (rM *redisMigrator) { } } -func (rdsMig *redisMigrator) close() { - rdsMig.rds.Close() +func (v1rs *redisMigrator) close() { + v1rs.rds.Close() } -func (rdsMig *redisMigrator) DataManager() *engine.DataManager { - return rdsMig.dm +func (v1rs *redisMigrator) DataManager() *engine.DataManager { + return v1rs.dm } //Account methods @@ -558,7 +558,7 @@ func (v1rs *redisMigrator) remV1Alias(key string) (err error) { for target, pairs := range value.Pairs { for _, alias := range pairs { revID := alias + target + al.Context - err = v1rs.rds.Cmd("SREM", REVERSE_ALIASES_PREFIX+revID, tmpKey).Err + err = v1rs.rds.Cmd("SREM", reverseAliasesPrefix+revID, tmpKey).Err if err != nil { return err } @@ -754,3 +754,95 @@ func (v1rs *redisMigrator) remV3AttributeProfile(tenant, id string) (err error) key := utils.AttributeProfilePrefix + utils.ConcatenatedKey(tenant, id) return v1rs.rds.Cmd("DEL", key).Err } + +//AttributeProfile methods +//get +func (v1rs *redisMigrator) getV4AttributeProfile() (v3attrPrf *v4AttributeProfile, err error) { + var v4attr *v4AttributeProfile + if v1rs.qryIdx == nil { + v1rs.dataKeys, err = v1rs.rds.GetKeysForPrefix(utils.AttributeProfilePrefix) + if err != nil { + return + } else if len(v1rs.dataKeys) == 0 { + return nil, utils.ErrNoMoreData + } + v1rs.qryIdx = utils.IntPointer(0) + } + if *v1rs.qryIdx <= len(v1rs.dataKeys)-1 { + strVal, err := v1rs.rds.Cmd("GET", v1rs.dataKeys[*v1rs.qryIdx]).Bytes() + if err != nil { + return nil, err + } + if err := v1rs.rds.Marshaler().Unmarshal(strVal, &v4attr); err != nil { + return nil, err + } + *v1rs.qryIdx = *v1rs.qryIdx + 1 + } else { + v1rs.qryIdx = nil + return nil, utils.ErrNoMoreData + } + return v4attr, nil +} + +//set +func (v1rs *redisMigrator) setV4AttributeProfile(x *v4AttributeProfile) (err error) { + key := utils.AttributeProfilePrefix + utils.ConcatenatedKey(x.Tenant, x.ID) + bit, err := v1rs.rds.Marshaler().Marshal(x) + if err != nil { + return err + } + if err = v1rs.rds.Cmd("SET", key, bit).Err; err != nil { + return err + } + return +} + +//rem +func (v1rs *redisMigrator) remV4AttributeProfile(tenant, id string) (err error) { + key := utils.AttributeProfilePrefix + utils.ConcatenatedKey(tenant, id) + return v1rs.rds.Cmd("DEL", key).Err +} + +// Filter Methods +//get +func (v1rs *redisMigrator) getV1Filter() (v1Fltr *v1Filter, err error) { + if v1rs.qryIdx == nil { + v1rs.dataKeys, err = v1rs.rds.GetKeysForPrefix(utils.FilterPrefix) + if err != nil { + return + } else if len(v1rs.dataKeys) == 0 { + return nil, utils.ErrNoMoreData + } + v1rs.qryIdx = utils.IntPointer(0) + } + if *v1rs.qryIdx <= len(v1rs.dataKeys)-1 { + strVal, err := v1rs.rds.Cmd("GET", v1rs.dataKeys[*v1rs.qryIdx]).Bytes() + if err != nil { + return nil, err + } + if err := v1rs.rds.Marshaler().Unmarshal(strVal, &v1Fltr); err != nil { + return nil, err + } + *v1rs.qryIdx = *v1rs.qryIdx + 1 + } else { + v1rs.qryIdx = nil + return nil, utils.ErrNoMoreData + } + return +} + +//set +func (v1rs *redisMigrator) setV1Filter(x *v1Filter) (err error) { + key := utils.FilterPrefix + utils.ConcatenatedKey(x.Tenant, x.ID) + bit, err := v1rs.rds.Marshaler().Marshal(x) + if err != nil { + return err + } + return v1rs.rds.Cmd("SET", key, bit).Err +} + +//rem +func (v1rs *redisMigrator) remV1Filter(tenant, id string) (err error) { + key := utils.FilterPrefix + utils.ConcatenatedKey(tenant, id) + return v1rs.rds.Cmd("DEL", key).Err +} diff --git a/migrator/tp_filters_it_test.go b/migrator/tp_filters_it_test.go index cea1259a2..d7b2d0b0a 100755 --- a/migrator/tp_filters_it_test.go +++ b/migrator/tp_filters_it_test.go @@ -113,9 +113,9 @@ func testTpFltrITPopulate(t *testing.T) { ID: "Filter", Filters: []*utils.TPFilter{ { - Type: "*string", - FieldName: "Account", - Values: []string{"1001", "1002"}, + Type: utils.MetaString, + Element: "Account", + Values: []string{"1001", "1002"}, }, }, ActivationInterval: &utils.TPActivationInterval{ diff --git a/migrator/user.go b/migrator/user.go index 62d81ce51..96b584582 100644 --- a/migrator/user.go +++ b/migrator/user.go @@ -63,9 +63,9 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr } if user.Tenant != attr.Tenant { attr.Attributes = append(attr.Attributes, &engine.Attribute{ - FieldName: utils.MetaTenant, - Value: config.NewRSRParsersMustCompile(user.Tenant, true, utils.INFIELD_SEP), - Type: utils.META_CONSTANT, + Path: utils.MetaTenant, + Value: config.NewRSRParsersMustCompile(user.Tenant, true, utils.INFIELD_SEP), + Type: utils.META_CONSTANT, }) } for fieldName, substitute := range user.Profile { @@ -77,9 +77,9 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr continue } attr.Attributes = append(attr.Attributes, &engine.Attribute{ - FieldName: fieldName, - Value: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP), - Type: utils.MetaVariable, + Path: utils.MetaReq + utils.NestingSep + fieldName, + Value: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP), + Type: utils.MetaVariable, }) } return @@ -107,7 +107,7 @@ func (m *Migrator) migrateV1User2AttributeProfile() (err error) { if err := m.dmOut.DataManager().SetAttributeProfile(attr, true); err != nil { return err } - m.stats[utils.User] += 1 + m.stats[utils.User]++ } if m.dryRun { return diff --git a/migrator/user_it_test.go b/migrator/user_it_test.go index f5164e3be..beacb6703 100644 --- a/migrator/user_it_test.go +++ b/migrator/user_it_test.go @@ -130,19 +130,19 @@ func testUsrITMigrateAndMove(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: utils.MetaTenant, - Type: utils.META_CONSTANT, - Value: config.NewRSRParsersMustCompile("cgrates.com", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.RequestType, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), }, { - FieldName: utils.RequestType, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "msisdn", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("123423534646752", true, utils.INFIELD_SEP), }, { - FieldName: "msisdn", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("123423534646752", true, utils.INFIELD_SEP), + Path: utils.MetaTenant, + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile("cgrates.com", true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -183,7 +183,7 @@ func testUsrITMigrateAndMove(t *testing.T) { } result.Compile() sort.Slice(result.Attributes, func(i, j int) bool { - return result.Attributes[i].FieldName < result.Attributes[j].FieldName + return result.Attributes[i].Path < result.Attributes[j].Path }) // only for test; map returns random keys if !reflect.DeepEqual(*attrProf, *result) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrProf), utils.ToJSON(result)) diff --git a/migrator/user_test.go b/migrator/user_test.go index 0f009b559..6d2f58e27 100644 --- a/migrator/user_test.go +++ b/migrator/user_test.go @@ -104,14 +104,14 @@ func TestUserProfile2attributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: utils.MetaTenant, - Type: utils.META_CONSTANT, - Value: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "Subject", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("call_1001", true, utils.INFIELD_SEP), }, { - FieldName: "Subject", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("call_1001", true, utils.INFIELD_SEP), + Path: utils.MetaTenant, + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -127,14 +127,14 @@ func TestUserProfile2attributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: utils.RequestType, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.RequestType, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), }, { - FieldName: "msisdn", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("123423534646752", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "msisdn", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("123423534646752", true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -148,14 +148,14 @@ func TestUserProfile2attributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: utils.MetaTenant, - Type: utils.META_CONSTANT, - Value: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.RequestType, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), }, { - FieldName: utils.RequestType, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), + Path: utils.MetaTenant, + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -171,29 +171,29 @@ func TestUserProfile2attributeProfile(t *testing.T) { ActivationInterval: nil, Attributes: []*engine.Attribute{ { - FieldName: utils.MetaTenant, - Type: utils.META_CONSTANT, - Value: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.RequestType, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), }, { - FieldName: utils.RequestType, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + utils.Subject, + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("acnt63", true, utils.INFIELD_SEP), }, { - FieldName: utils.Subject, - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("acnt63", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "imsi", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("12345", true, utils.INFIELD_SEP), }, { - FieldName: "imsi", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("12345", true, utils.INFIELD_SEP), + Path: utils.MetaReq + utils.NestingSep + "msisdn", + Type: utils.MetaVariable, + Value: config.NewRSRParsersMustCompile("12345", true, utils.INFIELD_SEP), }, { - FieldName: "msisdn", - Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("12345", true, utils.INFIELD_SEP), + Path: utils.MetaTenant, + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP), }, }, Blocker: false, @@ -203,13 +203,13 @@ func TestUserProfile2attributeProfile(t *testing.T) { for i := range expected { rply := userProfile2attributeProfile(users[i]) sort.Slice(rply.Attributes, func(i, j int) bool { - if rply.Attributes[i].FieldName == rply.Attributes[j].FieldName { + if rply.Attributes[i].Path == rply.Attributes[j].Path { return rply.Attributes[i].FilterIDs[0] < rply.Attributes[j].FilterIDs[0] } - return rply.Attributes[i].FieldName < rply.Attributes[j].FieldName + return rply.Attributes[i].Path < rply.Attributes[j].Path }) // only for test; map returns random keys if !reflect.DeepEqual(expected[i], rply) { - t.Errorf("For %v expected: %s ,\nreceived: %s ", i, utils.ToIJSON(expected[i]), utils.ToIJSON(rply)) + t.Errorf("For %v expected: %s ,\nreceived: %s ", i, utils.ToJSON(expected[i]), utils.ToJSON(rply)) } } } diff --git a/sessions/sessions.go b/sessions/sessions.go index 30b4dff4e..90a588289 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -811,7 +811,7 @@ func (sS *SessionS) getIndexedFilters(tenant string, fltrs []string) ( continue } for _, fltr := range f.Rules { - fldName := strings.TrimPrefix(fltr.FieldName, utils.DynamicDataPrefix+utils.MetaReq+utils.NestingSep) // remove ~req. prefix + fldName := strings.TrimPrefix(fltr.Element, utils.DynamicDataPrefix+utils.MetaReq+utils.NestingSep) // remove ~req. prefix if fltr.Type != utils.MetaString || !sS.cgrCfg.SessionSCfg().SessionIndexes.HasKey(fldName) { unindexedFltr = append(unindexedFltr, fltr) @@ -1756,6 +1756,7 @@ func (v1AuthReply *V1AuthorizeReply) AsNavigableMap( if v1AuthReply.Attributes != nil { attrs := make(map[string]interface{}) for _, fldName := range v1AuthReply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1AuthReply.Attributes.CGREvent.HasField(fldName) { attrs[fldName] = v1AuthReply.Attributes.CGREvent.Event[fldName] } @@ -1820,11 +1821,6 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.ClientConnector, args.AttributeIDs) if err == nil { args.CGREvent = rplyAttr.CGREvent - if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has { - // special case when we want to overwrite the tenant - args.CGREvent.Tenant = tntIface.(string) - delete(args.CGREvent.Event, utils.MetaTenant) - } authReply.Attributes = &rplyAttr } else if err.Error() != utils.ErrNotFound.Error() { return utils.NewErrAttributeS(err) @@ -2029,6 +2025,7 @@ func (v1Rply *V1InitSessionReply) AsNavigableMap( if v1Rply.Attributes != nil { attrs := make(map[string]interface{}) for _, fldName := range v1Rply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { attrs[fldName] = v1Rply.Attributes.CGREvent.Event[fldName] } @@ -2091,11 +2088,6 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.ClientConnector, args.AttributeIDs) if err == nil { args.CGREvent = rplyAttr.CGREvent.Clone() // avoid concurrency with rply.Attributes - if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has { - // special case when we want to overwrite the tenant - args.CGREvent.Tenant = tntIface.(string) - delete(args.CGREvent.Event, utils.MetaTenant) - } rply.Attributes = &rplyAttr } else if err.Error() != utils.ErrNotFound.Error() { return utils.NewErrAttributeS(err) @@ -2263,6 +2255,7 @@ func (v1Rply *V1UpdateSessionReply) AsNavigableMap( if v1Rply.Attributes != nil { attrs := make(map[string]interface{}) for _, fldName := range v1Rply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { attrs[fldName] = v1Rply.Attributes.CGREvent.Event[fldName] } @@ -2314,11 +2307,6 @@ func (sS *SessionS) BiRPCv1UpdateSession(clnt rpcclient.ClientConnector, args.AttributeIDs) if err == nil { args.CGREvent = rplyAttr.CGREvent.Clone() - if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has { - // special case when we want to overwrite the tenant - args.CGREvent.Tenant = tntIface.(string) - delete(args.CGREvent.Event, utils.MetaTenant) - } rply.Attributes = &rplyAttr } else if err.Error() != utils.ErrNotFound.Error() { return utils.NewErrAttributeS(err) @@ -2734,6 +2722,7 @@ func (v1Rply *V1ProcessMessageReply) AsNavigableMap( if v1Rply.Attributes != nil { attrs := make(map[string]interface{}) for _, fldName := range v1Rply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { attrs[fldName] = v1Rply.Attributes.CGREvent.Event[fldName] } @@ -2792,11 +2781,6 @@ func (sS *SessionS) BiRPCv1ProcessMessage(clnt rpcclient.ClientConnector, args.AttributeIDs) if err == nil { args.CGREvent = rplyAttr.CGREvent - if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has { - // special case when we want to overwrite the tenant - args.CGREvent.Tenant = tntIface.(string) - delete(args.CGREvent.Event, utils.MetaTenant) - } rply.Attributes = &rplyAttr } else if err.Error() != utils.ErrNotFound.Error() { return utils.NewErrAttributeS(err) @@ -2911,6 +2895,7 @@ func (v1Rply *V1ProcessEventReply) AsNavigableMap( if v1Rply.Attributes != nil { attrs := make(map[string]interface{}) for _, fldName := range v1Rply.Attributes.AlteredFields { + fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { attrs[fldName] = v1Rply.Attributes.CGREvent.Event[fldName] } @@ -2976,11 +2961,6 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, argsFlagsWithParams.ParamsSlice(utils.MetaAttributes)) if err == nil { args.CGREvent = rplyAttr.CGREvent.Clone() - if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has { - // special case when we want to overwrite the tenant - args.CGREvent.Tenant = tntIface.(string) - delete(args.CGREvent.Event, utils.MetaTenant) - } rply.Attributes = &rplyAttr } else if err.Error() != utils.ErrNotFound.Error() { return utils.NewErrAttributeS(err) diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index 2f3547815..0f9201710 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -34,7 +34,7 @@ import ( var attrs = &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, - AlteredFields: []string{"OfficeGroup"}, + AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSSv1ItAuth", @@ -1574,9 +1574,9 @@ func TestSessionSGetIndexedFilters(t *testing.T) { expIndx := map[string][]string{} expUindx := []*engine.FilterRule{ &engine.FilterRule{ - Type: utils.MetaString, - FieldName: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.ToR, - Values: []string{utils.VOICE}, + Type: utils.MetaString, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.ToR, + Values: []string{utils.VOICE}, }, } fltrs := []string{"*string:~*req.ToR:*voice"} diff --git a/utils/apitpdata.go b/utils/apitpdata.go index b9e681fae..4d0b1e1ee 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1077,11 +1077,11 @@ type TPFilterProfile struct { ActivationInterval *TPActivationInterval // Time when this limit becomes active and expires } -// TPFilterProfile is used in TPFilterProfile +// TPFilter is used in TPFilterProfile type TPFilter struct { - Type string // Filter type (*string, *timing, *rsr_filters, *cdr_stats) - FieldName string // Name of the field providing us the Values to check (used in case of some ) - Values []string // Filter definition + Type string // Filter type (*string, *timing, *rsr_filters, *cdr_stats) + Element string // Name of the field providing us the Values to check (used in case of some ) + Values []string // Filter definition } // TPSupplier is used in TPSupplierProfile @@ -1113,7 +1113,7 @@ type TPSupplierProfile struct { // TPAttribute is used in TPAttributeProfile type TPAttribute struct { FilterIDs []string - FieldName string + Path string Type string Value string } diff --git a/utils/apitpdata_test.go b/utils/apitpdata_test.go index 28621d0a0..a80b6fd6b 100644 --- a/utils/apitpdata_test.go +++ b/utils/apitpdata_test.go @@ -797,7 +797,7 @@ func TestAppendToSMCostFilter(t *testing.T) { expected := &SMCostFilter{ CGRIDs: []string{"CGRID1", "CGRID2"}, } - if smfltr, err = AppendToSMCostFilter(smfltr, "*string", DynamicDataPrefix+CGRID, []string{"CGRID1", "CGRID2"}, ""); err != nil { + if smfltr, err = AppendToSMCostFilter(smfltr, MetaString, DynamicDataPrefix+CGRID, []string{"CGRID1", "CGRID2"}, ""); err != nil { t.Error(err) } else if !reflect.DeepEqual(smfltr, expected) { t.Errorf("Expected: %s ,received: %s ", ToJSON(expected), ToJSON(smfltr)) @@ -810,7 +810,7 @@ func TestAppendToSMCostFilter(t *testing.T) { } expected.RunIDs = []string{"RunID1", "RunID2"} - if smfltr, err = AppendToSMCostFilter(smfltr, "*string", DynamicDataPrefix+RunID, []string{"RunID1", "RunID2"}, ""); err != nil { + if smfltr, err = AppendToSMCostFilter(smfltr, MetaString, DynamicDataPrefix+RunID, []string{"RunID1", "RunID2"}, ""); err != nil { t.Error(err) } else if !reflect.DeepEqual(smfltr, expected) { t.Errorf("Expected: %s ,received: %s ", ToJSON(expected), ToJSON(smfltr)) @@ -823,7 +823,7 @@ func TestAppendToSMCostFilter(t *testing.T) { } expected.OriginHosts = []string{"OriginHost1", "OriginHost2"} - if smfltr, err = AppendToSMCostFilter(smfltr, "*string", DynamicDataPrefix+OriginHost, []string{"OriginHost1", "OriginHost2"}, ""); err != nil { + if smfltr, err = AppendToSMCostFilter(smfltr, MetaString, DynamicDataPrefix+OriginHost, []string{"OriginHost1", "OriginHost2"}, ""); err != nil { t.Error(err) } else if !reflect.DeepEqual(smfltr, expected) { t.Errorf("Expected: %s ,received: %s ", ToJSON(expected), ToJSON(smfltr)) @@ -836,7 +836,7 @@ func TestAppendToSMCostFilter(t *testing.T) { } expected.OriginIDs = []string{"OriginID1", "OriginID2"} - if smfltr, err = AppendToSMCostFilter(smfltr, "*string", DynamicDataPrefix+OriginID, []string{"OriginID1", "OriginID2"}, ""); err != nil { + if smfltr, err = AppendToSMCostFilter(smfltr, MetaString, DynamicDataPrefix+OriginID, []string{"OriginID1", "OriginID2"}, ""); err != nil { t.Error(err) } else if !reflect.DeepEqual(smfltr, expected) { t.Errorf("Expected: %s ,received: %s ", ToJSON(expected), ToJSON(smfltr)) @@ -849,7 +849,7 @@ func TestAppendToSMCostFilter(t *testing.T) { } expected.CostSources = []string{"CostSource1", "CostSource2"} - if smfltr, err = AppendToSMCostFilter(smfltr, "*string", DynamicDataPrefix+CostSource, []string{"CostSource1", "CostSource2"}, ""); err != nil { + if smfltr, err = AppendToSMCostFilter(smfltr, MetaString, DynamicDataPrefix+CostSource, []string{"CostSource1", "CostSource2"}, ""); err != nil { t.Error(err) } else if !reflect.DeepEqual(smfltr, expected) { t.Errorf("Expected: %s ,received: %s ", ToJSON(expected), ToJSON(smfltr)) @@ -891,7 +891,7 @@ func TestAppendToSMCostFilter(t *testing.T) { if !reflect.DeepEqual(smfltr, expected) { t.Errorf("Expected: %s ,received: %s ", ToJSON(expected), ToJSON(smfltr)) } - if smfltr, err = AppendToSMCostFilter(smfltr, "*string", CGRID, []string{"CGRID1", "CGRID2"}, ""); err == nil || err.Error() != "FieldName: \"CGRID\" not supported" { + if smfltr, err = AppendToSMCostFilter(smfltr, MetaString, CGRID, []string{"CGRID1", "CGRID2"}, ""); err == nil || err.Error() != "FieldName: \"CGRID\" not supported" { t.Errorf("Expected error: FieldName: \"CGRID\" not supported ,received %v", err) } if !reflect.DeepEqual(smfltr, expected) { diff --git a/utils/consts.go b/utils/consts.go index e7d327d7a..298071ae3 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -502,6 +502,7 @@ const ( CGR_ACD = "cgr_acd" FilterIDs = "FilterIDs" FieldName = "FieldName" + Path = "Path" MetaRound = "*round" Pong = "Pong" MetaEventCost = "*event_cost"