diff --git a/config/config.go b/config/config.go index f15bd0a8c..bed37751c 100644 --- a/config/config.go +++ b/config/config.go @@ -318,7 +318,8 @@ type CGRConfig struct { var posibleLoaderTypes = utils.NewStringSet([]string{utils.MetaAttributes, utils.MetaResources, utils.MetaFilters, utils.MetaStats, utils.MetaRoutes, utils.MetaThresholds, utils.MetaChargers, - utils.MetaDispatchers, utils.MetaDispatcherHosts, utils.MetaRateProfiles}) + utils.MetaDispatchers, utils.MetaDispatcherHosts, utils.MetaRateProfiles, + utils.MetaAccounts, utils.MetaActionProfiles}) var possibleReaderTypes = utils.NewStringSet([]string{utils.MetaFileCSV, utils.MetaKafkajsonMap, utils.MetaFileXML, utils.MetaSQL, utils.MetaFileFWV, diff --git a/console/accounts_profile.go b/console/accounts_profile.go index 7a949405a..92e93264d 100644 --- a/console/accounts_profile.go +++ b/console/accounts_profile.go @@ -25,7 +25,7 @@ import ( func init() { c := &CmdGetAccounts{ name: "accounts", - rpcMethod: utils.APIerSv1GetAccount, + rpcMethod: utils.AdminSv1GetAccount, rpcParams: &utils.TenantIDWithAPIOpts{}, } commands[c.Name()] = c diff --git a/console/accounts_profile_ids.go b/console/accounts_profile_ids.go index f137e36eb..6df856247 100644 --- a/console/accounts_profile_ids.go +++ b/console/accounts_profile_ids.go @@ -25,7 +25,7 @@ import ( func init() { c := &CmdGetAccountsIDs{ name: "accounts_ids", - rpcMethod: utils.APIerSv1GetAccountIDs, + rpcMethod: utils.AdminSv1GetAccountIDs, rpcParams: &utils.PaginatorWithTenant{}, } commands[c.Name()] = c diff --git a/console/accounts_profile_rem.go b/console/accounts_profile_rem.go index 741e7a7d0..cd1e98704 100644 --- a/console/accounts_profile_rem.go +++ b/console/accounts_profile_rem.go @@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils" func init() { c := &CmdRemoveAccounts{ name: "accounts_remove", - rpcMethod: utils.APIerSv1RemoveAccount, + rpcMethod: utils.AdminSv1RemoveAccount, rpcParams: &utils.TenantIDWithAPIOpts{}, } commands[c.Name()] = c diff --git a/console/accounts_profile_set.go b/console/accounts_profile_set.go index 3c92b1055..950468f12 100644 --- a/console/accounts_profile_set.go +++ b/console/accounts_profile_set.go @@ -25,7 +25,7 @@ import ( func init() { c := &CmdSetAccount{ name: "accounts_set", - rpcMethod: utils.APIerSv1SetAccount, + rpcMethod: utils.AdminSv1SetAccount, rpcParams: &utils.APIAccountWithOpts{}, } commands[c.Name()] = c diff --git a/data/conf/samples/preload_internal/cgrates.json b/data/conf/samples/preload_internal/cgrates.json index cbacfdf36..b17e0a5e9 100644 --- a/data/conf/samples/preload_internal/cgrates.json +++ b/data/conf/samples/preload_internal/cgrates.json @@ -52,6 +52,77 @@ }, ], }, + { + "id": "Accounts_Loader", + "enabled": true, + "dry_run": false, + "tenant": "cgrates.org", + "run_delay": "0", + "lock_filename": ".cgr2.lock", + "caches_conns": ["*internal"], + "field_separator": ",", + "tp_in_dir": "/tmp/AccountsIn", + "tp_out_dir": "/tmp/AccountsOut", + "data":[ + { + "type": "*accounts", + "file_name": "Accounts.csv", + "fields": [ + {"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true}, + {"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true}, + {"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.2"}, + {"tag": "Weights", "path": "Weights", "type": "*variable", "value": "~*req.3"}, + {"tag": "Opts", "path": "Opts", "type": "*variable", "value": "~*req.4"}, + {"tag": "BalanceID", "path": "BalanceID", "type": "*variable", "value": "~*req.5"}, + {"tag": "BalanceFilterIDs", "path": "BalanceFilterIDs", "type": "*variable", "value": "~*req.6"}, + {"tag": "BalanceWeights", "path": "BalanceWeights", "type": "*variable", "value": "~*req.7"}, + {"tag": "BalanceType", "path": "BalanceType", "type": "*variable", "value": "~*req.8"}, + {"tag": "BalanceUnits", "path": "BalanceUnits", "type": "*variable", "value": "~*req.9"}, + {"tag": "BalanceUnitFactors", "path": "BalanceUnitFactors", "type": "*variable", "value": "~*req.10"}, + {"tag": "BalanceOpts", "path": "BalanceOpts", "type": "*variable", "value": "~*req.11"}, + {"tag": "BalanceCostIncrements", "path": "BalanceCostIncrements", "type": "*variable", "value": "~*req.12"}, + {"tag": "BalanceAttributeIDs", "path": "BalanceAttributeIDs", "type": "*variable", "value": "~*req.13"}, + {"tag": "BalanceRateProfileIDs", "path": "BalanceRateProfileIDs", "type": "*variable", "value": "~*req.14"}, + {"tag": "ThresholdIDs", "path": "ThresholdIDs", "type": "*variable", "value": "~*req.15"}, + ], + }, + ], + }, + { + "id": "Actions_Loader", + "enabled": true, + "dry_run": false, + "tenant": "cgrates.org", + "run_delay": "0", + "lock_filename": ".cgr3.lock", + "caches_conns": ["*internal"], + "field_separator": ",", + "tp_in_dir": "/tmp/ActionsIn", + "tp_out_dir": "/tmp/ActionsOut", + "data":[ + { + "type": "*action_profiles", + "file_name": "ActionProfiles.csv", + "fields": [ + {"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true}, + {"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true}, + {"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.2"}, + {"tag": "Weights", "path": "Weights", "type": "*variable", "value": "~*req.3"}, + {"tag": "Schedule", "path": "Schedule", "type": "*variable", "value": "~*req.4"}, + {"tag": "TargetType", "path": "TargetType", "type": "*variable", "value": "~*req.5"}, + {"tag": "TargetIDs", "path": "TargetIDs", "type": "*variable", "value": "~*req.6"}, + {"tag": "ActionID", "path": "ActionID", "type": "*variable", "value": "~*req.7"}, + {"tag": "ActionFilterIDs", "path": "ActionFilterIDs", "type": "*variable", "value": "~*req.8"}, + {"tag": "ActionBlocker", "path": "ActionBlocker", "type": "*variable", "value": "~*req.9"}, + {"tag": "ActionTTL", "path": "ActionTTL", "type": "*variable", "value": "~*req.10"}, + {"tag": "ActionType", "path": "ActionType", "type": "*variable", "value": "~*req.11"}, + {"tag": "ActionOpts", "path": "ActionOpts", "type": "*variable", "value": "~*req.12"}, + {"tag": "ActionPath", "path": "ActionPath", "type": "*variable", "value": "~*req.13"}, + {"tag": "ActionValue", "path": "ActionValue", "type": "*variable", "value": "~*req.14"}, + ], + }, + ], + } ], "admins": { diff --git a/engine/dynamicdp.go b/engine/dynamicdp.go index 47542f0b8..9b87755f4 100644 --- a/engine/dynamicdp.go +++ b/engine/dynamicdp.go @@ -96,7 +96,7 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val interface{}, err e // fieldNameType (~*accounts), accountID(1001) and queried part (BalanceMap.*monetary[0].Value) var account utils.Account - if err = connMgr.Call(dDP.ctx, dDP.apiConns, utils.APIerSv1GetAccount, + if err = connMgr.Call(dDP.ctx, dDP.apiConns, utils.AdminSv1GetAccount, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: dDP.tenant, ID: fldPath[1]}}, &account); err != nil { return } diff --git a/loaders/libloader.go b/loaders/libloader.go index 0e40714a2..a1dcaf638 100644 --- a/loaders/libloader.go +++ b/loaders/libloader.go @@ -49,7 +49,7 @@ func (ld LoaderData) GetRateIDs() ([]string, error) { // UpdateFromCSV will update LoaderData with data received from fileName, // contained in record and processed with cfgTpl -func (ld LoaderData) UpdateFromCSV(fileName string, record []string, +func (ld LoaderData) UpdateFromCSV(ctx *context.Context, fileName string, record []string, cfgTpl []*config.FCTemplate, tnt config.RSRParsers, filterS *engine.FilterS) (err error) { csvProvider := newCsvProvider(record, fileName) tenant, err := tnt.ParseValue("") @@ -59,7 +59,7 @@ func (ld LoaderData) UpdateFromCSV(fileName string, record []string, for _, cfgFld := range cfgTpl { // Make sure filters are matching if len(cfgFld.Filters) != 0 { - if pass, err := filterS.Pass(context.TODO(), tenant, + if pass, err := filterS.Pass(ctx, tenant, cfgFld.Filters, csvProvider); err != nil { return err } else if !pass { diff --git a/loaders/libloader_test.go b/loaders/libloader_test.go index f77990153..06d8644dd 100644 --- a/loaders/libloader_test.go +++ b/loaders/libloader_test.go @@ -22,6 +22,8 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/config" @@ -75,7 +77,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { {"cgrates.org", "ATTR_1", "", "", "", "Subject", "*any", "1001", "true"}, } lData := make(LoaderData) - if err := lData.UpdateFromCSV("Attributes.csv", rows[0], attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[0], attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil { t.Error(err) } @@ -93,7 +95,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { t.Errorf("expecting: %+v, received: %+v", eLData, lData) } lData = make(LoaderData) - if err := lData.UpdateFromCSV("Attributes.csv", rows[1], attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[1], attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil { t.Error(err) } @@ -159,7 +161,7 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) { {"cgrates.org", "ATTR_1", "", "", "", "Subject", "*any", "1001", "true"}, } lData := make(LoaderData) - if err := lData.UpdateFromCSV("Attributes.csv", rows[0], attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[0], attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil { t.Error(err) } @@ -177,7 +179,7 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) { t.Errorf("expecting: %+v, received: %+v", eLData, lData) } lData = make(LoaderData) - if err := lData.UpdateFromCSV("Attributes.csv", rows[1], attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[1], attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil { t.Error(err) } @@ -240,7 +242,7 @@ func TestDataUpdateFromCSVMultiFiles(t *testing.T) { } lData := make(LoaderData) for fName, record := range loadRun1 { - if err := lData.UpdateFromCSV(fName, record, attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), fName, record, attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil { t.Error(err) } @@ -288,7 +290,7 @@ func TestUpdateFromCsvParseValueError(t *testing.T) { } tnt := config.NewRSRParsersMustCompile("asd{*duration_seconds}", utils.InfieldSep) expected := "time: invalid duration \"asd\"" - if err := ldrData.UpdateFromCSV("File1.csv", nil, nil, tnt, nil); err == nil || err.Error() != expected { + if err := ldrData.UpdateFromCSV(context.Background(), "File1.csv", nil, nil, tnt, nil); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -320,7 +322,7 @@ func TestUpdateFromCsvWithFiltersError(t *testing.T) { for fName, record := range loadRunStr { expected := "Ignoring record: [\"cgrates.org\" \"TEST_1\"] with error : strconv.Atoi: parsing \"Account\": invalid syntax" - if err := lData.UpdateFromCSV(fName, record, attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), fName, record, attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), filterS); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -353,7 +355,7 @@ func TestUpdateFromCsvWithFiltersContinue(t *testing.T) { filterS := engine.NewFilterS(dftCfg, nil, dm) for fName, record := range loadRunStr { - if err := lData.UpdateFromCSV(fName, record, attrSFlds, + if err := lData.UpdateFromCSV(context.Background(), fName, record, attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), filterS); err != nil { t.Error(err) } diff --git a/loaders/loader.go b/loaders/loader.go index 6c4e2cc76..d25028532 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -229,7 +229,7 @@ func (ldr *Loader) processContent(ctx *context.Context, loaderType, caching stri continue } - if err := lData.UpdateFromCSV(fName, record, + if err := lData.UpdateFromCSV(ctx, fName, record, ldr.dataTpls[loaderType], ldr.tenant, ldr.filterS); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> <%s> line: %d, error: %s", @@ -701,7 +701,7 @@ func (ldr *Loader) removeContent(ctx *context.Context, loaderType, caching strin continue } - if err := lData.UpdateFromCSV(fName, record, + if err := lData.UpdateFromCSV(ctx, fName, record, ldr.dataTpls[loaderType], ldr.tenant, ldr.filterS); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> <%s> line: %d, error: %s",