Updated loader config

This commit is contained in:
Trial97
2020-03-20 18:11:30 +02:00
committed by Dan Christian Bogos
parent 57cfcbf5fc
commit 0ecf6c1b9d
6 changed files with 75 additions and 36 deletions

View File

@@ -788,13 +788,14 @@ const CGRATES_CFG_JSON = `
},
"loader": { // loader for tariff plans out of .csv files
"tpid": "", // tariff plan identificator
"data_path": "./", // path towards tariff plan files
"disable_reverse": false, // disable reverse computing
"field_separator": ",", // separator used in case of csv files
"loader": { // loader for tariff plans out of .csv files
"tpid": "", // tariff plan identificator
"data_path": "./", // path towards tariff plan files
"disable_reverse": false, // disable reverse computing
"field_separator": ",", // separator used in case of csv files
"caches_conns":["*localhost"],
"scheduler_conns": ["*localhost"],
"gapi_credentials": ".gapi/credentials.json" // the path to the credentials for google API or the credentials.json file content
},

View File

@@ -1713,18 +1713,20 @@ func TestDfDispatcherSJsonCfg(t *testing.T) {
}
func TestDfLoaderCfg(t *testing.T) {
cred := json.RawMessage(`".gapi/credentials.json"`)
eCfg := &LoaderCfgJson{
Tpid: utils.StringPointer(""),
Data_path: utils.StringPointer("./"),
Disable_reverse: utils.BoolPointer(false),
Field_separator: utils.StringPointer(","),
Caches_conns: &[]string{utils.MetaLocalHost},
Scheduler_conns: &[]string{utils.MetaLocalHost},
Tpid: utils.StringPointer(""),
Data_path: utils.StringPointer("./"),
Disable_reverse: utils.BoolPointer(false),
Field_separator: utils.StringPointer(","),
Caches_conns: &[]string{utils.MetaLocalHost},
Scheduler_conns: &[]string{utils.MetaLocalHost},
Gapi_credentials: &cred,
}
if cfg, err := dfCgrJsonCfg.LoaderCfgJson(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfg, cfg) {
t.Errorf("Expected: %+v, received: %+v", utils.ToJSON(eCfg), utils.ToJSON(cfg))
t.Errorf("Expected1: %s, received: %+v", utils.ToJSON(*eCfg), utils.ToJSON(cfg))
}
}

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package config
import (
"encoding/json"
"path"
"reflect"
"testing"
@@ -1501,12 +1502,13 @@ func TestCgrCfgJSONDefaultDispatcherSCfg(t *testing.T) {
func TestCgrLoaderCfgDefault(t *testing.T) {
eLdrCfg := &LoaderCgrCfg{
TpID: "",
DataPath: "./",
DisableReverse: false,
FieldSeparator: rune(utils.CSV_SEP),
CachesConns: []string{utils.MetaLocalHost},
SchedulerConns: []string{utils.MetaLocalHost},
TpID: "",
DataPath: "./",
DisableReverse: false,
FieldSeparator: rune(utils.CSV_SEP),
CachesConns: []string{utils.MetaLocalHost},
SchedulerConns: []string{utils.MetaLocalHost},
GapiCredentials: json.RawMessage(`".gapi/credentials.json"`),
}
if !reflect.DeepEqual(cgrCfg.LoaderCgrCfg(), eLdrCfg) {
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.LoaderCgrCfg()), utils.ToJSON(eLdrCfg))

View File

@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package config
import "encoding/json"
// General config section
type GeneralJsonCfg struct {
Node_id *string
@@ -497,12 +499,13 @@ type DispatcherSJsonCfg struct {
}
type LoaderCfgJson struct {
Tpid *string
Data_path *string
Disable_reverse *bool
Field_separator *string
Caches_conns *[]string
Scheduler_conns *[]string
Tpid *string
Data_path *string
Disable_reverse *bool
Field_separator *string
Caches_conns *[]string
Scheduler_conns *[]string
Gapi_credentials *json.RawMessage
}
type MigratorCfgJson struct {

View File

@@ -18,15 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package config
import "github.com/cgrates/cgrates/utils"
import (
"encoding/json"
"github.com/cgrates/cgrates/utils"
)
type LoaderCgrCfg struct {
TpID string
DataPath string
DisableReverse bool
FieldSeparator rune // The separator to use when reading csvs
CachesConns []string
SchedulerConns []string
TpID string
DataPath string
DisableReverse bool
FieldSeparator rune // The separator to use when reading csvs
CachesConns []string
SchedulerConns []string
GapiCredentials json.RawMessage
}
func (ld *LoaderCgrCfg) loadFromJsonCfg(jsnCfg *LoaderCfgJson) (err error) {
@@ -68,5 +73,8 @@ func (ld *LoaderCgrCfg) loadFromJsonCfg(jsnCfg *LoaderCfgJson) (err error) {
}
}
}
if jsnCfg.Gapi_credentials != nil {
ld.GapiCredentials = *jsnCfg.Gapi_credentials
}
return nil
}

View File

@@ -394,6 +394,8 @@
// "concurrent_requests": -1, // limit the number of active requests processed by the server <-1|0-n>
// "synced_conn_requests": false, // process one request at the time per connection
// "asr_template": "", // enable AbortSession message being sent to client on DisconnectSession
// "rar_template": "", // template used to build the Re-Auth-Request
// "disconnect_method": "*asr", // the request to send to diameter on DisconnectSession <*asr|*rar>
// "templates":{ // default message templates
// "*err": [
// {"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
@@ -436,6 +438,26 @@
// "value": "~*req.User-Name", "mandatory": true},
// {"tag": "OriginStateID", "path": "*diamreq.Origin-State-Id", "type": "*constant",
// "value": "1"},
// ],
// "*rar": [
// {"tag": "SessionId", "path": "*diamreq.Session-Id", "type": "*variable",
// "value": "~*req.Session-Id", "mandatory": true},
// {"tag": "OriginHost", "path": "*diamreq.Origin-Host", "type": "*variable",
// "value": "~*req.Destination-Host", "mandatory": true},
// {"tag": "OriginRealm", "path": "*diamreq.Origin-Realm", "type": "*variable",
// "value": "~*req.Destination-Realm", "mandatory": true},
// {"tag": "DestinationRealm", "path": "*diamreq.Destination-Realm", "type": "*variable",
// "value": "~*req.Origin-Realm", "mandatory": true},
// {"tag": "DestinationHost", "path": "*diamreq.Destination-Host", "type": "*variable",
// "value": "~*req.Origin-Host", "mandatory": true},
// {"tag": "AuthApplicationId", "path": "*diamreq.Auth-Application-Id", "type": "*variable",
// "value": "~*vars.*appid", "mandatory": true},
// {"tag": "UserName", "path": "*diamreq.User-Name", "type": "*variable",
// "value": "~*req.User-Name", "mandatory": true},
// {"tag": "OriginStateID", "path": "*diamreq.Origin-State-Id", "type": "*constant",
// "value": "1"},
// {"tag": "ReAuthRequestType", "path": "*diamreq.Re-Auth-Request-Type", "type": "*constant",
// "value": "0"},
// ]
// },
// "request_processors": [ // list of processors to be applied to diameter messages
@@ -745,13 +767,14 @@
// },
// "loader": { // loader for tariff plans out of .csv files
// "tpid": "", // tariff plan identificator
// "data_path": "./", // path towards tariff plan files
// "disable_reverse": false, // disable reverse computing
// "field_separator": ",", // separator used in case of csv files
// "loader": { // loader for tariff plans out of .csv files
// "tpid": "", // tariff plan identificator
// "data_path": "./", // path towards tariff plan files
// "disable_reverse": false, // disable reverse computing
// "field_separator": ",", // separator used in case of csv files
// "caches_conns":["*localhost"],
// "scheduler_conns": ["*localhost"],
// "gapi_credentials": ".gapi/credentials.json" // the path to the credentials for google API or the credentials.json file content
// },