mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add "configs" section in config
This commit is contained in:
committed by
Dan Christian Bogos
parent
080938c880
commit
fc8b98f815
@@ -189,6 +189,7 @@ func NewDefaultCGRConfig() (cfg *CGRConfig, err error) {
|
||||
cfg.eesCfg.Cache = make(map[string]*CacheParamCfg)
|
||||
cfg.rateSCfg = new(RateSCfg)
|
||||
cfg.sipAgentCfg = new(SIPAgentCfg)
|
||||
cfg.configSCfg = new(ConfigSCfg)
|
||||
|
||||
cfg.ConfigReloads = make(map[string]chan struct{})
|
||||
|
||||
@@ -311,6 +312,7 @@ type CGRConfig struct {
|
||||
eesCfg *EEsCfg // EventExporter config
|
||||
rateSCfg *RateSCfg // RateS config
|
||||
sipAgentCfg *SIPAgentCfg // SIPAgent config
|
||||
configSCfg *ConfigSCfg //ConfigS config
|
||||
}
|
||||
|
||||
var posibleLoaderTypes = utils.NewStringSet([]string{utils.MetaAttributes,
|
||||
@@ -376,7 +378,7 @@ func (cfg *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
cfg.loadMailerCfg, cfg.loadSureTaxCfg, cfg.loadDispatcherSCfg,
|
||||
cfg.loadLoaderCgrCfg, cfg.loadMigratorCgrCfg, cfg.loadTlsCgrCfg,
|
||||
cfg.loadAnalyzerCgrCfg, cfg.loadApierCfg, cfg.loadErsCfg, cfg.loadEesCfg,
|
||||
cfg.loadRateSCfg, cfg.loadSIPAgentCfg, cfg.loadDispatcherHCfg} {
|
||||
cfg.loadRateSCfg, cfg.loadSIPAgentCfg, cfg.loadDispatcherHCfg, cfg.loadConfigSCfg} {
|
||||
if err = loadFunc(jsnCfg); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -777,6 +779,14 @@ func (cfg *CGRConfig) loadTemplateSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (cfg *CGRConfig) loadConfigSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
var jsnConfigSCfg *ConfigSCfgJson
|
||||
if jsnConfigSCfg, err = jsnCfg.ConfigSJsonCfg(); err != nil {
|
||||
return
|
||||
}
|
||||
return cfg.configSCfg.loadFromJsonCfg(jsnConfigSCfg)
|
||||
}
|
||||
|
||||
// SureTaxCfg use locking to retrieve the configuration, possibility later for runtime reload
|
||||
func (cfg *CGRConfig) SureTaxCfg() *SureTaxCfg {
|
||||
cfg.lks[SURETAX_JSON].Lock()
|
||||
@@ -1282,6 +1292,7 @@ func (cfg *CGRConfig) getLoadFunctions() map[string]func(*CgrJsonCfg) error {
|
||||
RateSJson: cfg.loadRateSCfg,
|
||||
SIPAgentJson: cfg.loadSIPAgentCfg,
|
||||
TemplatesJson: cfg.loadTemplateSCfg,
|
||||
ConfigSJson: cfg.loadConfigSCfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -990,4 +990,11 @@ const CGRATES_CFG_JSON = `
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"configs": {
|
||||
"enabled": false, // enables the ConfigS: <true|false>
|
||||
"listen": "", // address where to listen for config <x.y.z.y:1234>
|
||||
},
|
||||
|
||||
|
||||
}`
|
||||
|
||||
@@ -63,6 +63,7 @@ const (
|
||||
RPCConnsJsonName = "rpc_conns"
|
||||
SIPAgentJson = "sip_agent"
|
||||
TemplatesJson = "templates"
|
||||
ConfigSJson = "configs"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -70,7 +71,7 @@ var (
|
||||
CACHE_JSN, FilterSjsn, RALS_JSN, CDRS_JSN, ERsJson, SessionSJson, AsteriskAgentJSN, FreeSWITCHAgentJSN,
|
||||
KamailioAgentJSN, DA_JSN, RA_JSN, HttpAgentJson, DNSAgentJson, ATTRIBUTE_JSN, ChargerSCfgJson, RESOURCES_JSON, STATS_JSON,
|
||||
THRESHOLDS_JSON, RouteSJson, LoaderJson, MAILER_JSN, SURETAX_JSON, CgrLoaderCfgJson, CgrMigratorCfgJson, DispatcherSJson,
|
||||
AnalyzerCfgJson, ApierS, EEsJson, RateSJson, SIPAgentJson, DispatcherHJson, TemplatesJson}
|
||||
AnalyzerCfgJson, ApierS, EEsJson, RateSJson, SIPAgentJson, DispatcherHJson, TemplatesJson, ConfigSJson}
|
||||
)
|
||||
|
||||
// Loads the json config out of io.Reader, eg other sources than file, maybe over http
|
||||
@@ -544,3 +545,15 @@ func (self CgrJsonCfg) TemplateSJsonCfg() (map[string][]*FcTemplateJsonCfg, erro
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (self CgrJsonCfg) ConfigSJsonCfg() (*ConfigSCfgJson, error) {
|
||||
rawCfg, hasKey := self[ConfigSJson]
|
||||
if !hasKey {
|
||||
return nil, nil
|
||||
}
|
||||
cfg := new(ConfigSCfgJson)
|
||||
if err := json.Unmarshal(*rawCfg, cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -2492,6 +2492,13 @@ func TestRpcConnsDefaults(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTemplateConnsDefaults(t *testing.T) {
|
||||
func TestCgrCfgJSONDefaultsConfigS(t *testing.T) {
|
||||
eCfg := &ConfigSCfg{
|
||||
Enabled: false,
|
||||
Listen: utils.EmptyString,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cgrCfg.configSCfg, eCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.configSCfg), utils.ToJSON(eCfg))
|
||||
}
|
||||
}
|
||||
|
||||
39
config/configs.go
Normal file
39
config/configs.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
// ConfigSCfg config for listening over http
|
||||
type ConfigSCfg struct {
|
||||
Enabled bool
|
||||
Listen string
|
||||
}
|
||||
|
||||
//loadFromJsonCfg loads Database config from JsonCfg
|
||||
func (cScfg *ConfigSCfg) loadFromJsonCfg(jsnCfg *ConfigSCfgJson) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return nil
|
||||
}
|
||||
if jsnCfg.Enabled != nil {
|
||||
cScfg.Enabled = *jsnCfg.Enabled
|
||||
}
|
||||
if jsnCfg.Listen != nil {
|
||||
cScfg.Listen = *jsnCfg.Listen
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -642,3 +642,8 @@ type SIPAgentJsonCfg struct {
|
||||
Templates map[string][]*FcTemplateJsonCfg
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
}
|
||||
|
||||
type ConfigSCfgJson struct {
|
||||
Enabled *bool
|
||||
Listen *string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user