Added non-empty check at migration

This commit is contained in:
adragusin
2020-05-28 17:59:07 +03:00
committed by Dan Christian Bogos
parent 025f6bd0a4
commit 2ce94a020d
6 changed files with 22 additions and 11 deletions

View File

@@ -237,8 +237,8 @@ func (v1Acc v1Account) V1toV3Account() (ac *engine.Account) {
ac.ID = utils.ConcatenatedKey(idElements[1], idElements[2])
// balances
for oldBalKey, oldBalChain := range v1Acc.BalanceMap {
keyElements := strings.Split(oldBalKey, "*")
newBalKey := "*" + keyElements[1]
keyElements := strings.Split(oldBalKey, utils.Meta)
newBalKey := utils.Meta + keyElements[1]
ac.BalanceMap[newBalKey] = make(engine.Balances, len(oldBalChain))
for index, oldBal := range oldBalChain {
balVal := oldBal.Value

View File

@@ -109,7 +109,7 @@ func alias2AtttributeProfile(alias *v1Alias, defaultTenant string) *engine.Attri
if fieldName == utils.Tenant {
fieldName = utils.MetaTenant
fld = utils.MetaTenant
} else {
} else if fieldName != utils.EmptyString {
fld = utils.MetaReq + utils.NestingSep + fieldName
}
attr := &engine.Attribute{

View File

@@ -300,12 +300,12 @@ func (v2AttrPrf v2AttributeProfile) AsAttributeProfile() (attrPrf *v3AttributePr
filterIDs := make([]string, 0)
//append false translate to if FieldName exist do stuff
if attr.Append == false {
filterIDs = append(filterIDs, utils.MetaExists+":"+attr.FieldName+":")
filterIDs = append(filterIDs, utils.MetaExists+utils.InInFieldSep+attr.FieldName+utils.InInFieldSep)
}
//Initial not *any translate to if value of fieldName = initial do stuff
initial := utils.IfaceAsString(attr.Initial)
if initial != utils.META_ANY {
filterIDs = append(filterIDs, utils.MetaString+":"+attr.FieldName+":"+initial)
filterIDs = append(filterIDs, utils.MetaString+utils.InInFieldSep+attr.FieldName+utils.InInFieldSep+initial)
}
attrPrf.Attributes = append(attrPrf.Attributes, &v3Attribute{
@@ -397,10 +397,13 @@ func (v4AttrPrf v4AttributeProfile) AsAttributeProfile() (attrPrf *engine.Attrib
return nil, err
}
}
var path string
if attr.FieldName != utils.EmptyString {
path = utils.MetaReq + utils.NestingSep + attr.FieldName
}
attrPrf.Attributes = append(attrPrf.Attributes, &engine.Attribute{
FilterIDs: attr.FilterIDs,
Path: utils.MetaReq + utils.NestingSep + attr.FieldName,
Path: path,
Value: rsrVal,
Type: attr.Type,
})

View File

@@ -82,8 +82,12 @@ func fieldinfo2Attribute(attr []*engine.Attribute, fieldName, fieldInfo string)
utils.Logger.Err(fmt.Sprintf("On Migrating rule: <%s>, error: %s", fieldInfo, err.Error()))
return attr
}
var path string
if fieldName != utils.EmptyString {
path = utils.MetaReq + utils.NestingSep + fieldName
}
return append(attr, &engine.Attribute{
Path: utils.MetaReq + utils.NestingSep + fieldName,
Path: path,
Value: rp,
Type: utils.MetaVariable,
})

View File

@@ -434,8 +434,8 @@ func (v1Sts v1Stat) AsStatQP() (filter *engine.Filter, sq *engine.StatQueue, stq
}
if len(v1Sts.Metrics) != 0 {
for i := range v1Sts.Metrics {
if !strings.HasPrefix(v1Sts.Metrics[i], "*") {
v1Sts.Metrics[i] = "*" + v1Sts.Metrics[i]
if !strings.HasPrefix(v1Sts.Metrics[i], utils.Meta) {
v1Sts.Metrics[i] = utils.Meta + v1Sts.Metrics[i]
}
v1Sts.Metrics[i] = strings.ToLower(v1Sts.Metrics[i])
stq.Metrics = append(stq.Metrics, &engine.MetricWithFilters{MetricID: v1Sts.Metrics[i]})

View File

@@ -76,8 +76,12 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr
attr.FilterIDs = append(attr.FilterIDs, fmt.Sprintf("*string:~%s:%s", fieldName, substitute))
continue
}
var path string
if fieldName != utils.EmptyString {
path = utils.MetaReq + utils.NestingSep + fieldName
}
attr.Attributes = append(attr.Attributes, &engine.Attribute{
Path: utils.MetaReq + utils.NestingSep + fieldName,
Path: path,
Value: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP),
Type: utils.MetaVariable,
})