mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Add config section for AccountS
This commit is contained in:
committed by
Dan Christian Bogos
parent
8e3bf6e945
commit
9c5b50a1de
130
config/accountscfg.go
Normal file
130
config/accountscfg.go
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
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
|
||||
|
||||
import "github.com/cgrates/cgrates/utils"
|
||||
|
||||
// AccountSCfg is the configuration of ActionS
|
||||
type AccountSCfg struct {
|
||||
Enabled bool
|
||||
IndexedSelects bool
|
||||
StringIndexedFields *[]string
|
||||
PrefixIndexedFields *[]string
|
||||
SuffixIndexedFields *[]string
|
||||
NestedFields bool
|
||||
}
|
||||
|
||||
func (acS *AccountSCfg) loadFromJSONCfg(jsnCfg *AccountSJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
if jsnCfg.Enabled != nil {
|
||||
acS.Enabled = *jsnCfg.Enabled
|
||||
}
|
||||
if jsnCfg.Indexed_selects != nil {
|
||||
acS.IndexedSelects = *jsnCfg.Indexed_selects
|
||||
}
|
||||
if jsnCfg.String_indexed_fields != nil {
|
||||
sif := make([]string, len(*jsnCfg.String_indexed_fields))
|
||||
for i, fID := range *jsnCfg.String_indexed_fields {
|
||||
sif[i] = fID
|
||||
}
|
||||
acS.StringIndexedFields = &sif
|
||||
}
|
||||
if jsnCfg.Prefix_indexed_fields != nil {
|
||||
pif := make([]string, len(*jsnCfg.Prefix_indexed_fields))
|
||||
for i, fID := range *jsnCfg.Prefix_indexed_fields {
|
||||
pif[i] = fID
|
||||
}
|
||||
acS.PrefixIndexedFields = &pif
|
||||
}
|
||||
if jsnCfg.Suffix_indexed_fields != nil {
|
||||
sif := make([]string, len(*jsnCfg.Suffix_indexed_fields))
|
||||
for i, fID := range *jsnCfg.Suffix_indexed_fields {
|
||||
sif[i] = fID
|
||||
}
|
||||
acS.SuffixIndexedFields = &sif
|
||||
}
|
||||
if jsnCfg.Nested_fields != nil {
|
||||
acS.NestedFields = *jsnCfg.Nested_fields
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]interface{}
|
||||
func (acS *AccountSCfg) AsMapInterface() (initialMP map[string]interface{}) {
|
||||
initialMP = map[string]interface{}{
|
||||
utils.EnabledCfg: acS.Enabled,
|
||||
utils.IndexedSelectsCfg: acS.IndexedSelects,
|
||||
utils.NestedFieldsCfg: acS.NestedFields,
|
||||
}
|
||||
if acS.StringIndexedFields != nil {
|
||||
stringIndexedFields := make([]string, len(*acS.StringIndexedFields))
|
||||
for i, item := range *acS.StringIndexedFields {
|
||||
stringIndexedFields[i] = item
|
||||
}
|
||||
initialMP[utils.StringIndexedFieldsCfg] = stringIndexedFields
|
||||
}
|
||||
if acS.PrefixIndexedFields != nil {
|
||||
prefixIndexedFields := make([]string, len(*acS.PrefixIndexedFields))
|
||||
for i, item := range *acS.PrefixIndexedFields {
|
||||
prefixIndexedFields[i] = item
|
||||
}
|
||||
initialMP[utils.PrefixIndexedFieldsCfg] = prefixIndexedFields
|
||||
}
|
||||
if acS.SuffixIndexedFields != nil {
|
||||
suffixIndexedFields := make([]string, len(*acS.SuffixIndexedFields))
|
||||
for i, item := range *acS.SuffixIndexedFields {
|
||||
suffixIndexedFields[i] = item
|
||||
}
|
||||
initialMP[utils.SuffixIndexedFieldsCfg] = suffixIndexedFields
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Clone returns a deep copy of AccountSCfg
|
||||
func (acS AccountSCfg) Clone() (cln *AccountSCfg) {
|
||||
cln = &AccountSCfg{
|
||||
Enabled: acS.Enabled,
|
||||
IndexedSelects: acS.IndexedSelects,
|
||||
NestedFields: acS.NestedFields,
|
||||
}
|
||||
if acS.StringIndexedFields != nil {
|
||||
idx := make([]string, len(*acS.StringIndexedFields))
|
||||
for i, dx := range *acS.StringIndexedFields {
|
||||
idx[i] = dx
|
||||
}
|
||||
cln.StringIndexedFields = &idx
|
||||
}
|
||||
if acS.PrefixIndexedFields != nil {
|
||||
idx := make([]string, len(*acS.PrefixIndexedFields))
|
||||
for i, dx := range *acS.PrefixIndexedFields {
|
||||
idx[i] = dx
|
||||
}
|
||||
cln.PrefixIndexedFields = &idx
|
||||
}
|
||||
if acS.SuffixIndexedFields != nil {
|
||||
idx := make([]string, len(*acS.SuffixIndexedFields))
|
||||
for i, dx := range *acS.SuffixIndexedFields {
|
||||
idx[i] = dx
|
||||
}
|
||||
cln.SuffixIndexedFields = &idx
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -199,6 +199,7 @@ func newCGRConfig(config []byte) (cfg *CGRConfig, err error) {
|
||||
cfg.configSCfg = new(ConfigSCfg)
|
||||
cfg.apiBanCfg = new(APIBanCfg)
|
||||
cfg.coreSCfg = new(CoreSCfg)
|
||||
cfg.accountSCfg = new(AccountSCfg)
|
||||
|
||||
var cgrJSONCfg *CgrJsonCfg
|
||||
if cgrJSONCfg, err = NewCgrJsonCfgFromBytes(config); err != nil {
|
||||
@@ -332,6 +333,7 @@ type CGRConfig struct {
|
||||
configSCfg *ConfigSCfg // ConfigS config
|
||||
apiBanCfg *APIBanCfg // APIBan config
|
||||
coreSCfg *CoreSCfg // CoreS config
|
||||
accountSCfg *AccountSCfg // AccountS config
|
||||
}
|
||||
|
||||
var posibleLoaderTypes = utils.NewStringSet([]string{utils.MetaAttributes,
|
||||
@@ -399,7 +401,8 @@ func (cfg *CGRConfig) loadFromJSONCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
cfg.loadLoaderCgrCfg, cfg.loadMigratorCgrCfg, cfg.loadTLSCgrCfg,
|
||||
cfg.loadAnalyzerCgrCfg, cfg.loadApierCfg, cfg.loadErsCfg, cfg.loadEesCfg,
|
||||
cfg.loadRateSCfg, cfg.loadSIPAgentCfg, cfg.loadDispatcherHCfg,
|
||||
cfg.loadConfigSCfg, cfg.loadAPIBanCgrCfg, cfg.loadCoreSCfg, cfg.loadActionSCfg} {
|
||||
cfg.loadConfigSCfg, cfg.loadAPIBanCgrCfg, cfg.loadCoreSCfg, cfg.loadActionSCfg,
|
||||
cfg.loadAccountSCfg} {
|
||||
if err = loadFunc(jsnCfg); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -826,7 +829,7 @@ func (cfg *CGRConfig) loadConfigSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
return cfg.configSCfg.loadFromJSONCfg(jsnConfigSCfg)
|
||||
}
|
||||
|
||||
// loadActionSCfg loads the CoreS section of the configuration
|
||||
// loadActionSCfg loads the ActionS section of the configuration
|
||||
func (cfg *CGRConfig) loadActionSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
var jsnActionCfg *ActionSJsonCfg
|
||||
if jsnActionCfg, err = jsnCfg.ActionSCfgJson(); err != nil {
|
||||
@@ -835,6 +838,15 @@ func (cfg *CGRConfig) loadActionSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
return cfg.actionSCfg.loadFromJSONCfg(jsnActionCfg)
|
||||
}
|
||||
|
||||
// loadAccountSCfg loads the AccountS section of the configuration
|
||||
func (cfg *CGRConfig) loadAccountSCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
var jsnActionCfg *AccountSJsonCfg
|
||||
if jsnActionCfg, err = jsnCfg.AccountSCfgJson(); err != nil {
|
||||
return
|
||||
}
|
||||
return cfg.accountSCfg.loadFromJSONCfg(jsnActionCfg)
|
||||
}
|
||||
|
||||
// SureTaxCfg use locking to retrieve the configuration, possibility later for runtime reload
|
||||
func (cfg *CGRConfig) SureTaxCfg() *SureTaxCfg {
|
||||
cfg.lks[SURETAX_JSON].Lock()
|
||||
@@ -1106,6 +1118,13 @@ func (cfg *CGRConfig) ActionSCfg() *ActionSCfg {
|
||||
return cfg.actionSCfg
|
||||
}
|
||||
|
||||
// AccountSCfg reads the AccountS configuration
|
||||
func (cfg *CGRConfig) AccountSCfg() *AccountSCfg {
|
||||
cfg.lks[AccountSCfgJson].RLock()
|
||||
defer cfg.lks[AccountSCfgJson].RUnlock()
|
||||
return cfg.accountSCfg
|
||||
}
|
||||
|
||||
// SIPAgentCfg reads the Apier configuration
|
||||
func (cfg *CGRConfig) SIPAgentCfg() *SIPAgentCfg {
|
||||
cfg.lks[SIPAgentJson].Lock()
|
||||
@@ -1245,6 +1264,7 @@ func (cfg *CGRConfig) getLoadFunctions() map[string]func(*CgrJsonCfg) error {
|
||||
APIBanCfgJson: cfg.loadAPIBanCgrCfg,
|
||||
CoreSCfgJson: cfg.loadCoreSCfg,
|
||||
ActionSJson: cfg.loadActionSCfg,
|
||||
AccountSCfgJson: cfg.loadAccountSCfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1549,6 +1569,7 @@ func (cfg *CGRConfig) AsMapInterface(separator string) (mp map[string]interface{
|
||||
ConfigSJson: cfg.configSCfg.AsMapInterface(),
|
||||
CoreSCfgJson: cfg.coreSCfg.AsMapInterface(),
|
||||
ActionSJson: cfg.actionSCfg.AsMapInterface(),
|
||||
AccountSCfgJson: cfg.accountSCfg.AsMapInterface(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1700,6 +1721,8 @@ func (cfg *CGRConfig) V1GetConfig(args *SectionWithOpts, reply *map[string]inter
|
||||
mp = cfg.CoreSCfg().AsMapInterface()
|
||||
case ActionSJson:
|
||||
mp = cfg.ActionSCfg().AsMapInterface()
|
||||
case AccountSCfgJson:
|
||||
mp = cfg.AccountSCfg().AsMapInterface()
|
||||
default:
|
||||
return errors.New("Invalid section")
|
||||
}
|
||||
@@ -1941,6 +1964,7 @@ func (cfg CGRConfig) Clone() (cln *CGRConfig) {
|
||||
apiBanCfg: cfg.apiBanCfg.Clone(),
|
||||
coreSCfg: cfg.coreSCfg.Clone(),
|
||||
actionSCfg: cfg.actionSCfg.Clone(),
|
||||
accountSCfg: cfg.accountSCfg.Clone(),
|
||||
}
|
||||
cln.initChanels()
|
||||
return
|
||||
|
||||
@@ -1078,4 +1078,14 @@ const CGRATES_CFG_JSON = `
|
||||
},
|
||||
|
||||
|
||||
"accounts": { // AccountS config
|
||||
"enabled": false, // starts service: <true|false>
|
||||
"indexed_selects": true, // enable profile matching exclusively on indexes
|
||||
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"prefix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"suffix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level)
|
||||
},
|
||||
|
||||
|
||||
}`
|
||||
|
||||
@@ -67,6 +67,7 @@ const (
|
||||
ConfigSJson = "configs"
|
||||
APIBanCfgJson = "apiban"
|
||||
CoreSCfgJson = "cores"
|
||||
AccountSCfgJson = "accounts"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -75,7 +76,7 @@ var (
|
||||
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, ConfigSJson, APIBanCfgJson, CoreSCfgJson,
|
||||
ActionSJson}
|
||||
ActionSJson, AccountSCfgJson}
|
||||
)
|
||||
|
||||
// Loads the json config out of io.Reader, eg other sources than file, maybe over http
|
||||
@@ -597,3 +598,15 @@ func (self CgrJsonCfg) ActionSCfgJson() (*ActionSJsonCfg, error) {
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (self CgrJsonCfg) AccountSCfgJson() (*AccountSJsonCfg, error) {
|
||||
rawCfg, hasKey := self[AccountSCfgJson]
|
||||
if !hasKey {
|
||||
return nil, nil
|
||||
}
|
||||
cfg := new(AccountSJsonCfg)
|
||||
if err := json.Unmarshal(*rawCfg, cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -679,3 +679,13 @@ type ActionSJsonCfg struct {
|
||||
Suffix_indexed_fields *[]string
|
||||
Nested_fields *bool // applies when indexed fields is not defined
|
||||
}
|
||||
|
||||
// Account service config section
|
||||
type AccountSJsonCfg struct {
|
||||
Enabled *bool
|
||||
Indexed_selects *bool
|
||||
String_indexed_fields *[]string
|
||||
Prefix_indexed_fields *[]string
|
||||
Suffix_indexed_fields *[]string
|
||||
Nested_fields *bool // applies when indexed fields is not defined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user