mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add new section "configs"
This commit is contained in:
committed by
Dan Christian Bogos
parent
beea38e295
commit
21e08d5a92
@@ -60,7 +60,7 @@ func NewDiameterAgent(cgrCfg *config.CGRConfig, filterS *engine.FilterS,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
msgTemplates := da.cgrCfg.TemplateCfg()
|
||||
msgTemplates := da.cgrCfg.TemplatesCfg()
|
||||
// Inflate *template field types
|
||||
for _, procsr := range da.cgrCfg.DiameterAgentCfg().RequestProcessors {
|
||||
if tpls, err := config.InflateTemplates(procsr.RequestFields, msgTemplates); err != nil {
|
||||
@@ -185,7 +185,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) {
|
||||
// build the negative error answer
|
||||
diamErr, err := diamErr(
|
||||
m, diam.UnableToComply, reqVars,
|
||||
da.cgrCfg.TemplateCfg()[utils.MetaErr],
|
||||
da.cgrCfg.TemplatesCfg()[utils.MetaErr],
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone,
|
||||
da.filterS)
|
||||
@@ -518,7 +518,7 @@ func (da *DiameterAgent) sendASR(originID string, reply *string) (err error) {
|
||||
dmd.vars, nil, nil, nil, nil,
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone, da.filterS, nil, nil)
|
||||
if err = aReq.SetFields(da.cgrCfg.TemplateCfg()[da.cgrCfg.DiameterAgentCfg().ASRTemplate]); err != nil {
|
||||
if err = aReq.SetFields(da.cgrCfg.TemplatesCfg()[da.cgrCfg.DiameterAgentCfg().ASRTemplate]); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> cannot disconnect session with OriginID: <%s>, err: %s",
|
||||
utils.DiameterAgent, originID, err.Error()))
|
||||
@@ -561,7 +561,7 @@ func (da *DiameterAgent) V1ReAuthorize(originID string, reply *string) (err erro
|
||||
dmd.vars, nil, nil, nil, nil,
|
||||
da.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
da.cgrCfg.GeneralCfg().DefaultTimezone, da.filterS, nil, nil)
|
||||
if err = aReq.SetFields(da.cgrCfg.TemplateCfg()[da.cgrCfg.DiameterAgentCfg().RARTemplate]); err != nil {
|
||||
if err = aReq.SetFields(da.cgrCfg.TemplatesCfg()[da.cgrCfg.DiameterAgentCfg().RARTemplate]); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> cannot send RAR with OriginID: <%s>, err: %s",
|
||||
utils.DiameterAgent, originID, err.Error()))
|
||||
|
||||
@@ -508,8 +508,8 @@ func main() {
|
||||
if len(cfg.HTTPCfg().DispatchersRegistrarURL) != 0 {
|
||||
server.RegisterHttpFunc(cfg.HTTPCfg().DispatchersRegistrarURL, dispatcherh.Registar)
|
||||
}
|
||||
if len(cfg.HTTPCfg().ConfigsURL) != 0 {
|
||||
server.RegisterHttpFunc(cfg.HTTPCfg().ConfigsURL, config.HandlerConfigS)
|
||||
if cfg.ConfigSCfg().Enabled {
|
||||
server.RegisterHttpFunc(cfg.ConfigSCfg().Url, config.HandlerConfigS)
|
||||
}
|
||||
if *httpPprofPath != "" {
|
||||
go server.RegisterProfiler(*httpPprofPath)
|
||||
|
||||
@@ -190,6 +190,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{})
|
||||
|
||||
@@ -312,6 +313,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,
|
||||
@@ -377,7 +379,8 @@ 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
|
||||
}
|
||||
@@ -778,6 +781,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()
|
||||
@@ -1055,13 +1066,20 @@ func (cfg *CGRConfig) RPCConns() map[string]*RPCConn {
|
||||
return cfg.rpcConns
|
||||
}
|
||||
|
||||
// DiameterAgentCfg returns the config for Diameter Agent
|
||||
func (cfg *CGRConfig) TemplateCfg() map[string][]*FCTemplate {
|
||||
// TemplatesCfg returns the config for templates
|
||||
func (cfg *CGRConfig) TemplatesCfg() map[string][]*FCTemplate {
|
||||
cfg.lks[TemplatesJson].Lock()
|
||||
defer cfg.lks[TemplatesJson].Unlock()
|
||||
return cfg.templates
|
||||
}
|
||||
|
||||
// ConfigSCfg returns the configs configuration
|
||||
func (cfg *CGRConfig) ConfigSCfg() *ConfigSCfg {
|
||||
cfg.lks[ConfigSJson].RLock()
|
||||
defer cfg.lks[ConfigSJson].RUnlock()
|
||||
return cfg.configSCfg
|
||||
}
|
||||
|
||||
// GetReloadChan returns the reload chanel for the given section
|
||||
func (cfg *CGRConfig) GetReloadChan(sectID string) chan struct{} {
|
||||
return cfg.rldChans[sectID]
|
||||
@@ -1155,7 +1173,9 @@ func (cfg *CGRConfig) V1GetConfigSection(args *SectionWithOpts, reply *map[strin
|
||||
case SIPAgentJson:
|
||||
jsonString = utils.ToJSON(cfg.SIPAgentCfg())
|
||||
case TemplatesJson:
|
||||
jsonString = utils.ToJSON(cfg.TemplateCfg())
|
||||
jsonString = utils.ToJSON(cfg.TemplatesCfg())
|
||||
case ConfigSJson:
|
||||
jsonString = utils.ToJSON(cfg.ConfigSCfg())
|
||||
default:
|
||||
return errors.New("Invalid section")
|
||||
}
|
||||
@@ -1283,6 +1303,7 @@ func (cfg *CGRConfig) getLoadFunctions() map[string]func(*CgrJsonCfg) error {
|
||||
RateSJson: cfg.loadRateSCfg,
|
||||
SIPAgentJson: cfg.loadSIPAgentCfg,
|
||||
TemplatesJson: cfg.loadTemplateSCfg,
|
||||
ConfigSJson: cfg.loadConfigSCfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,6 @@ const CGRATES_CFG_JSON = `
|
||||
"http_cdrs": "/cdr_http", // CDRS relative URL ("" to disable)
|
||||
"use_basic_auth": false, // use basic authentication
|
||||
"auth_users": {}, // basic authentication usernames and base64-encoded passwords (eg: { "username1": "cGFzc3dvcmQ=", "username2": "cGFzc3dvcmQy "})
|
||||
"configs_url": "/configs/" // configs
|
||||
},
|
||||
|
||||
|
||||
@@ -918,10 +917,11 @@ const CGRATES_CFG_JSON = `
|
||||
"rate_indexed_selects": true, // enable profile matching exclusively on indexes
|
||||
//"rate_string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"rate_prefix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"rate_suffix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"rate_suffix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"rate_nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level)
|
||||
},
|
||||
|
||||
|
||||
"sip_agent": { // SIP Agents, only used for redirections
|
||||
"enabled": false, // enables the SIP agent: <true|false>
|
||||
"listen": "127.0.0.1:5060", // address where to listen for SIP requests <x.y.z.y:1234>
|
||||
@@ -933,6 +933,7 @@ const CGRATES_CFG_JSON = `
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"templates": {
|
||||
"*err": [
|
||||
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
|
||||
@@ -993,4 +994,13 @@ const CGRATES_CFG_JSON = `
|
||||
"value": "SIP/2.0 500 Internal Server Error", "mandatory": true},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"configs": {
|
||||
"enabled": false,
|
||||
"url": "/configs/", // configs url
|
||||
"root_dir": "/var/spool/cgrates/configs", // root directory in case of calling /configs request
|
||||
},
|
||||
|
||||
|
||||
}`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1557,7 +1557,6 @@ func TestDfHttpJsonCfg(t *testing.T) {
|
||||
Http_Cdrs: utils.StringPointer("/cdr_http"),
|
||||
Use_basic_auth: utils.BoolPointer(false),
|
||||
Auth_users: utils.MapStringStringPointer(map[string]string{}),
|
||||
Configs_url: utils.StringPointer("/configs/"),
|
||||
}
|
||||
if cfg, err := dfCgrJSONCfg.HttpJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -2496,3 +2496,14 @@ func TestRpcConnsDefaults(t *testing.T) {
|
||||
t.Errorf("received: %+v,\n expecting: %+v", utils.ToJSON(cgrCfg.rpcConns), utils.ToJSON(eCfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCgrCfgJSONDefaultsConfigS(t *testing.T) {
|
||||
eCfg := &ConfigSCfg{
|
||||
Enabled: false,
|
||||
Url: "/configs/",
|
||||
RootDir: "/var/spool/cgrates/configs",
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.configSCfg, eCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.configSCfg), utils.ToJSON(eCfg))
|
||||
}
|
||||
}
|
||||
|
||||
40
config/configs.go
Normal file
40
config/configs.go
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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
|
||||
Url string
|
||||
RootDir 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.Url != nil {
|
||||
cScfg.Url = *jsnCfg.Url
|
||||
}
|
||||
if jsnCfg.Root_dir != nil {
|
||||
cScfg.RootDir = *jsnCfg.Root_dir
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -29,7 +29,6 @@ type HTTPCfg struct {
|
||||
HTTPCDRsURL string // CDRS relative URL ("" to disable)
|
||||
HTTPUseBasicAuth bool // Use basic auth for HTTP API
|
||||
HTTPAuthUsers map[string]string // Basic auth user:password map (base64 passwords)
|
||||
ConfigsURL string
|
||||
}
|
||||
|
||||
//loadFromJsonCfg loads Database config from JsonCfg
|
||||
@@ -58,10 +57,6 @@ func (httpcfg *HTTPCfg) loadFromJsonCfg(jsnHttpCfg *HTTPJsonCfg) (err error) {
|
||||
if jsnHttpCfg.Auth_users != nil {
|
||||
httpcfg.HTTPAuthUsers = *jsnHttpCfg.Auth_users
|
||||
}
|
||||
if jsnHttpCfg.Configs_url != nil {
|
||||
httpcfg.ConfigsURL = *jsnHttpCfg.Configs_url
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -79,6 +74,5 @@ func (httpcfg *HTTPCfg) AsMapInterface() map[string]interface{} {
|
||||
utils.HTTPCDRsURLCfg: httpcfg.HTTPCDRsURL,
|
||||
utils.HTTPUseBasicAuthCfg: httpcfg.HTTPUseBasicAuth,
|
||||
utils.HTTPAuthUsersCfg: httpUsers,
|
||||
utils.ConfigsURL: httpcfg.ConfigsURL,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ func TestHTTPCfgAsMapInterface(t *testing.T) {
|
||||
"http_cdrs": "/cdr_http",
|
||||
"use_basic_auth": false,
|
||||
"auth_users": {},
|
||||
"configs_url": "/configs/"
|
||||
},
|
||||
}`
|
||||
|
||||
@@ -88,7 +87,6 @@ func TestHTTPCfgAsMapInterface(t *testing.T) {
|
||||
"http_cdrs": "/cdr_http",
|
||||
"use_basic_auth": false,
|
||||
"auth_users": map[string]interface{}{},
|
||||
"configs_url": "/configs/",
|
||||
}
|
||||
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
|
||||
@@ -71,7 +71,6 @@ type HTTPJsonCfg struct {
|
||||
Http_Cdrs *string
|
||||
Use_basic_auth *bool
|
||||
Auth_users *map[string]string
|
||||
Configs_url *string
|
||||
}
|
||||
|
||||
type TlsJsonCfg struct {
|
||||
@@ -648,6 +647,7 @@ type SIPAgentJsonCfg struct {
|
||||
}
|
||||
|
||||
type ConfigSCfgJson struct {
|
||||
Enabled *bool
|
||||
Listen *string
|
||||
Enabled *bool
|
||||
Url *string
|
||||
Root_dir *string
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestEventExporterSReload(t *testing.T) {
|
||||
Layout: time.RFC3339,
|
||||
}
|
||||
fcTmp.ComputePath()
|
||||
cfg.TemplateCfg()["requiredFields"] = []*config.FCTemplate{fcTmp}
|
||||
cfg.TemplatesCfg()["requiredFields"] = []*config.FCTemplate{fcTmp}
|
||||
var reply string
|
||||
if err := cfg.V1ReloadConfigFromPath(&config.ConfigReloadWithOpts{
|
||||
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ees"),
|
||||
|
||||
Reference in New Issue
Block a user