mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Adding reqType sensitization for eventReader
This commit is contained in:
committed by
Dan Christian Bogos
parent
c15d33e216
commit
dfbca6d4b2
@@ -306,6 +306,8 @@ var posibleLoaderTypes = utils.NewStringSet([]string{utils.MetaAttributes,
|
||||
utils.MetaSuppliers, utils.MetaThresholds, utils.MetaChargers,
|
||||
utils.MetaDispatchers, utils.MetaDispatcherHosts})
|
||||
|
||||
var poisbleReaderType = utils.NewStringSet([]string{utils.MetaFileCSV})
|
||||
|
||||
func (self *CGRConfig) checkConfigSanity() error {
|
||||
// Rater checks
|
||||
if self.ralsCfg.RALsEnabled && !self.dispatcherSCfg.Enabled {
|
||||
@@ -664,6 +666,28 @@ func (self *CGRConfig) checkConfigSanity() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
// EventReader sanity checks
|
||||
if self.ersCfg.Enabled {
|
||||
if !self.sessionSCfg.Enabled {
|
||||
for _, connCfg := range self.ersCfg.SessionSConns {
|
||||
if connCfg.Address == utils.MetaInternal {
|
||||
return errors.New("SessionS not enabled but requested by EventReader component.")
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, rdr := range self.ersCfg.Readers {
|
||||
for _, dir := range []string{rdr.ProcessedPath, rdr.SourcePath} {
|
||||
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
||||
return fmt.Errorf("<%s> Nonexistent folder: %s for reader with ID: %s", utils.ERs, dir, rdr.ID)
|
||||
}
|
||||
}
|
||||
|
||||
if !poisbleReaderType.Has(rdr.Type) {
|
||||
return fmt.Errorf("<%s> unsupported data type: %s for reader with ID: %s", utils.ERs, rdr.Type, rdr.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (objDP *ObjectDP) String() string {
|
||||
func (objDP *ObjectDP) FieldAsInterface(fldPath []string) (data interface{}, err error) {
|
||||
// []string{ BalanceMap *monetary[0] Value }
|
||||
var has bool
|
||||
if data, has = objDP.getCache(strings.Join(fldPath, ".")); has {
|
||||
if data, has = objDP.getCache(strings.Join(fldPath, utils.NestingSep)); has {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -215,3 +215,24 @@ func TestEventReaderLoadFromJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEventReaderSanitisation(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"ers": {
|
||||
"enabled": true,
|
||||
"readers": [
|
||||
{
|
||||
"id": "file_reader1",
|
||||
"run_delay": -1,
|
||||
"type": "*file_csv",
|
||||
"source_path": "/tmp/ers/in",
|
||||
"processed_path": "/tmp/ers/out",
|
||||
},
|
||||
],
|
||||
}
|
||||
}`
|
||||
|
||||
if _, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user