mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added user_filters in migrator
This commit is contained in:
committed by
Dan Christian Bogos
parent
42845d0158
commit
c31210feab
@@ -327,6 +327,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
config.SetCgrConfig(mgrCfg)
|
||||
if migrate != nil && *migrate != "" { // Run migrator
|
||||
migrstats := make(map[string]int)
|
||||
mig := strings.Split(*migrate, ",")
|
||||
|
||||
@@ -721,6 +721,7 @@ const CGRATES_CFG_JSON = `
|
||||
"out_stordb_name": "cgrates",
|
||||
"out_stordb_user": "cgrates",
|
||||
"out_stordb_password": "",
|
||||
"users_filters":[],
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -1465,6 +1465,7 @@ func TestDfMigratorCfg(t *testing.T) {
|
||||
Out_storDB_name: utils.StringPointer("cgrates"),
|
||||
Out_storDB_user: utils.StringPointer("cgrates"),
|
||||
Out_storDB_password: utils.StringPointer(""),
|
||||
Users_filters: &[]string{},
|
||||
}
|
||||
if cfg, err := dfCgrJsonCfg.MigratorCfgJson(); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -546,6 +546,7 @@ type MigratorCfgJson struct {
|
||||
Out_storDB_name *string
|
||||
Out_storDB_user *string
|
||||
Out_storDB_password *string
|
||||
Users_filters *[]string
|
||||
}
|
||||
|
||||
type FcTemplateJsonCfg struct {
|
||||
|
||||
@@ -37,6 +37,7 @@ type MigratorCgrCfg struct {
|
||||
OutStorDBName string
|
||||
OutStorDBUser string
|
||||
OutStorDBPassword string
|
||||
UsersFilters []string
|
||||
}
|
||||
|
||||
func (mg *MigratorCgrCfg) loadFromJsonCfg(jsnCfg *MigratorCfgJson) (err error) {
|
||||
@@ -85,5 +86,11 @@ func (mg *MigratorCgrCfg) loadFromJsonCfg(jsnCfg *MigratorCfgJson) (err error) {
|
||||
if jsnCfg.Out_storDB_password != nil {
|
||||
mg.OutStorDBPassword = *jsnCfg.Out_storDB_password
|
||||
}
|
||||
if jsnCfg.Users_filters != nil && len(*jsnCfg.Users_filters) != 0 {
|
||||
mg.UsersFilters = make([]string, len(*jsnCfg.Users_filters))
|
||||
for i, v := range *jsnCfg.Users_filters {
|
||||
mg.UsersFilters[i] = v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@
|
||||
"out_stordb_type": "mongo",
|
||||
"out_stordb_port": "27017",
|
||||
"out_stordb_name": "cgrates",
|
||||
"users_filters":["Account"],
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -282,6 +282,7 @@
|
||||
|
||||
"migrator":{
|
||||
"out_stordb_password": "CGRateS.org",
|
||||
"users_filters":["Account"],
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ func (ud *v1UserProfile) SetId(id string) error {
|
||||
}
|
||||
|
||||
func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributeProfile) {
|
||||
usrFltr := config.CgrConfig().MigratorCgrCfg().UsersFilters
|
||||
attr = &engine.AttributeProfile{
|
||||
Tenant: user.Tenant,
|
||||
ID: user.UserName,
|
||||
@@ -61,6 +62,10 @@ func userProfile2attributeProfile(user *v1UserProfile) (attr *engine.AttributePr
|
||||
Weight: user.Weight,
|
||||
}
|
||||
for fieldname, substitute := range user.Profile {
|
||||
if utils.IsSliceMember(usrFltr, fieldname) {
|
||||
attr.FilterIDs = append(attr.FilterIDs, fmt.Sprintf("*string:%s:%s", fieldname, substitute))
|
||||
continue
|
||||
}
|
||||
attr.Attributes = append(attr.Attributes, &engine.Attribute{
|
||||
FieldName: fieldname,
|
||||
Initial: utils.META_ANY,
|
||||
|
||||
@@ -85,6 +85,7 @@ func testUsrStart(testName, inPath, outPath, action string, t *testing.T) {
|
||||
if usrCfgIn, err = config.NewCGRConfigFromFolder(inPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
config.SetCgrConfig(usrCfgIn)
|
||||
if usrCfgOut, err = config.NewCGRConfigFromFolder(outPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -144,15 +145,9 @@ func testUsrITMigrateAndMove(t *testing.T) {
|
||||
Tenant: defaultTenant,
|
||||
ID: "1001",
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: make([]string, 0),
|
||||
FilterIDs: []string{"*string:Account:1002"},
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: "Account",
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
{
|
||||
FieldName: "ReqType",
|
||||
Initial: utils.META_ANY,
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package migrator
|
||||
|
||||
import (
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
@@ -29,6 +30,13 @@ import (
|
||||
)
|
||||
|
||||
func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
inPath := path.Join("/usr/share/cgrates", "samples", "tutmongo")
|
||||
usrCfgIn, err := config.NewCGRConfigFromFolder(inPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
usrCfgIn.MigratorCgrCfg().UsersFilters = []string{"Account"}
|
||||
config.SetCgrConfig(usrCfgIn)
|
||||
users := map[int]*v1UserProfile{
|
||||
0: &v1UserProfile{
|
||||
Tenant: defaultTenant,
|
||||
@@ -74,15 +82,9 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
Tenant: defaultTenant,
|
||||
ID: "1001",
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: make([]string, 0),
|
||||
FilterIDs: []string{"*string:Account:1002"},
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: "Account",
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
{
|
||||
FieldName: "Subject",
|
||||
Initial: utils.META_ANY,
|
||||
@@ -97,15 +99,9 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
Tenant: defaultTenant,
|
||||
ID: "1001",
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: make([]string, 0),
|
||||
FilterIDs: []string{"*string:Account:1002"},
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: "Account",
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
{
|
||||
FieldName: "ReqType",
|
||||
Initial: utils.META_ANY,
|
||||
|
||||
Reference in New Issue
Block a user