mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added in-line Attributes
This commit is contained in:
@@ -2,4 +2,3 @@
|
||||
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
|
||||
cgrates.org,ATTR_RAW_REQ,*any,*string:~*req.RunID:*raw,,,RequestType,*constant,*none,false,10
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight
|
||||
cgrates.org,Raw,,,*raw,ATTR_RAW_REQ,20
|
||||
cgrates.org,Raw,,,*raw,*constant:RequestType:*none,20
|
||||
cgrates.org,CustomerCharges,,,CustomerCharges,*none,20
|
||||
cgrates.org,SupplierCharges,,,SupplierCharges,ATTR_SUPPLIER1,10
|
||||
|
@@ -22,4 +22,3 @@ cgrates.com,ATTR_TNT_ALIAS,*any,,,,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,,
|
||||
cgrates.org,ATTR_RAW_REQ,*any,*string:~*req.RunID:*raw,,,RequestType,*constant,*none,false,10
|
||||
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight
|
||||
cgrates.org,DEFAULT,,,*default,*none,0
|
||||
cgrates.org,Raw,,,*raw,ATTR_RAW_REQ,0
|
||||
cgrates.org,Raw,,,*raw,*constant:RequestType:*none,0
|
||||
|
@@ -122,7 +122,7 @@ func testDspChcLoadAfterFolder(t *testing.T) {
|
||||
t.Error(reply)
|
||||
}
|
||||
expStats[utils.CacheActions].Items = 2
|
||||
expStats[utils.CacheAttributeProfiles].Items = 11
|
||||
expStats[utils.CacheAttributeProfiles].Items = 10
|
||||
expStats[utils.CacheChargerProfiles].Items = 2
|
||||
expStats[utils.CacheFilters].Items = 7
|
||||
expStats[utils.CacheRatingPlans].Items = 5
|
||||
|
||||
@@ -133,7 +133,7 @@ func testDspCppGetChtgFailover(t *testing.T) {
|
||||
ID: "Raw",
|
||||
FilterIDs: []string{},
|
||||
RunID: utils.MetaRaw,
|
||||
AttributeIDs: []string{"ATTR_RAW_REQ"},
|
||||
AttributeIDs: []string{"*constant:RequestType:*none"},
|
||||
Weight: 0,
|
||||
},
|
||||
)
|
||||
@@ -222,7 +222,7 @@ func testDspCppTestAuthKey2(t *testing.T) {
|
||||
ID: "Raw",
|
||||
FilterIDs: []string{},
|
||||
RunID: utils.MetaRaw,
|
||||
AttributeIDs: []string{"ATTR_RAW_REQ"},
|
||||
AttributeIDs: []string{"*constant:RequestType:*none"},
|
||||
Weight: 0,
|
||||
},
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func testDspCppGetChtgRoundRobin(t *testing.T) {
|
||||
ID: "Raw",
|
||||
FilterIDs: []string{},
|
||||
RunID: utils.MetaRaw,
|
||||
AttributeIDs: []string{"ATTR_RAW_REQ"},
|
||||
AttributeIDs: []string{"*constant:RequestType:*none"},
|
||||
Weight: 0,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1781,7 +1781,14 @@ func (dm *DataManager) GetAttributeProfile(tenant, id string, cacheRead, cacheWr
|
||||
return x.(*AttributeProfile), nil
|
||||
}
|
||||
}
|
||||
attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id)
|
||||
if strings.HasPrefix(id, utils.Meta) {
|
||||
attrPrfl, err = NewAttributeFromInline(tenant, id)
|
||||
} else if dm == nil { // in case we want the filter from dataDB but the connection to dataDB a optional (e.g. SessionS)
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
} else {
|
||||
attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id)
|
||||
}
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound &&
|
||||
config.CgrConfig().DataDbCfg().Items[utils.MetaAttributeProfiles].Remote {
|
||||
|
||||
@@ -19,7 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -114,3 +116,29 @@ func (ext *ExternalAttributeProfile) AsAttributeProfile() (attr *AttributeProfil
|
||||
attr.Weight = ext.Weight
|
||||
return
|
||||
}
|
||||
|
||||
// NewAttributeFromInline parses an inline rule into a compiled AttributeProfile
|
||||
func NewAttributeFromInline(tenant, inlnRule string) (attr *AttributeProfile, err error) {
|
||||
ruleSplt := strings.Split(inlnRule, utils.InInFieldSep)
|
||||
if len(ruleSplt) < 3 {
|
||||
return nil, fmt.Errorf("inline parse error for string: <%s>", inlnRule)
|
||||
}
|
||||
var vals config.RSRParsers
|
||||
if vals, err = config.NewRSRParsers(strings.Join(ruleSplt[2:], utils.InInFieldSep), true, utils.INFIELD_SEP); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
attr = &AttributeProfile{
|
||||
Tenant: tenant,
|
||||
ID: inlnRule,
|
||||
Contexts: []string{utils.META_ANY},
|
||||
Attributes: []*Attribute{&Attribute{
|
||||
FieldName: ruleSplt[1],
|
||||
Type: ruleSplt[0],
|
||||
Value: vals,
|
||||
}},
|
||||
}
|
||||
if err = attr.Compile(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user