diff --git a/config/config.go b/config/config.go index 944062405..a6da8fa9b 100644 --- a/config/config.go +++ b/config/config.go @@ -198,6 +198,7 @@ type CGRConfig struct { RaterHistoryServer string RaterPubSubServer string RaterUserServer string + RaterAliasesServer string BalancerEnabled bool SchedulerEnabled bool CDRSEnabled bool // Enable CDR Server service @@ -219,8 +220,8 @@ type CGRConfig struct { HistoryServerEnabled bool // Starts History as server: . HistoryDir string // Location on disk where to store history files. HistorySaveInterval time.Duration // The timout duration between pubsub writes - PubSubServer string // Address where to reach the master pubsub server: PubSubServerEnabled bool // Starts PubSub as server: . + AliasesServerEnabled bool // Starts PubSub as server: . UserServerEnabled bool // Starts User as server: UserServerIndexes []string // List of user profile field indexes MailerServer string // The server to use when sending emails out @@ -250,6 +251,9 @@ func (self *CGRConfig) checkConfigSanity() error { if self.RaterPubSubServer == utils.INTERNAL && !self.PubSubServerEnabled { return errors.New("PubSub server not enabled but requested by Rater component.") } + if self.RaterAliasesServer == utils.INTERNAL && !self.AliasesServerEnabled { + return errors.New("Aliases server not enabled but requested by Rater component.") + } if self.RaterUserServer == utils.INTERNAL && !self.UserServerEnabled { return errors.New("Users service not enabled but requested by Rater component.") } @@ -425,6 +429,11 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { return err } + jsnAliasesServCfg, err := jsnCfg.AliasesServJsonCfg() + if err != nil { + return err + } + jsnUserServCfg, err := jsnCfg.UserServJsonCfg() if err != nil { return err @@ -566,6 +575,9 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { if jsnRaterCfg.Pubsubs != nil { self.RaterPubSubServer = *jsnRaterCfg.Pubsubs } + if jsnRaterCfg.Aliases != nil { + self.RaterAliasesServer = *jsnRaterCfg.Aliases + } if jsnRaterCfg.Users != nil { self.RaterUserServer = *jsnRaterCfg.Users } @@ -709,6 +721,12 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { } } + if jsnAliasesServCfg != nil { + if jsnAliasesServCfg.Enabled != nil { + self.AliasesServerEnabled = *jsnAliasesServCfg.Enabled + } + } + if jsnUserServCfg != nil { if jsnUserServCfg.Enabled != nil { self.UserServerEnabled = *jsnUserServCfg.Enabled diff --git a/config/config_defaults.go b/config/config_defaults.go index 8a1a51427..d1aa047c0 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -93,6 +93,7 @@ const CGRATES_CFG_JSON = ` "historys": "", // address where to reach the history service, empty to disable history functionality: <""|internal|x.y.z.y:1234> "pubsubs": "", // address where to reach the pubusb service, empty to disable pubsub functionality: <""|internal|x.y.z.y:1234> "users": "", // address where to reach the user service, empty to disable user profile functionality: <""|internal|x.y.z.y:1234> + "aliases": "", // address where to reach the aliases service, empty to disable aliases functionality: <""|internal|x.y.z.y:1234> }, @@ -254,6 +255,9 @@ const CGRATES_CFG_JSON = ` "enabled": false, // starts PubSub service: . }, +"aliases": { + "enabled": false, // starts Aliases service: . +}, "users": { "enabled": false, // starts User service: . diff --git a/config/config_json.go b/config/config_json.go index 58fcb8a66..353ec4a8a 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -27,30 +27,31 @@ import ( ) const ( - GENERAL_JSN = "general" - LISTEN_JSN = "listen" - TPDB_JSN = "tariffplan_db" - DATADB_JSN = "data_db" - STORDB_JSN = "stor_db" - BALANCER_JSN = "balancer" - RATER_JSN = "rater" - SCHEDULER_JSN = "scheduler" - CDRS_JSN = "cdrs" - MEDIATOR_JSN = "mediator" - CDRSTATS_JSN = "cdrstats" - CDRE_JSN = "cdre" - CDRC_JSN = "cdrc" - SMFS_JSN = "sm_freeswitch" - SMKAM_JSN = "sm_kamailio" - SMOSIPS_JSN = "sm_opensips" - SM_JSN = "session_manager" - FS_JSN = "freeswitch" - KAMAILIO_JSN = "kamailio" - OSIPS_JSN = "opensips" - HISTSERV_JSN = "historys" - PUBSUBSERV_JSN = "pubsubs" - USERSERV_JSN = "users" - MAILER_JSN = "mailer" + GENERAL_JSN = "general" + LISTEN_JSN = "listen" + TPDB_JSN = "tariffplan_db" + DATADB_JSN = "data_db" + STORDB_JSN = "stor_db" + BALANCER_JSN = "balancer" + RATER_JSN = "rater" + SCHEDULER_JSN = "scheduler" + CDRS_JSN = "cdrs" + MEDIATOR_JSN = "mediator" + CDRSTATS_JSN = "cdrstats" + CDRE_JSN = "cdre" + CDRC_JSN = "cdrc" + SMFS_JSN = "sm_freeswitch" + SMKAM_JSN = "sm_kamailio" + SMOSIPS_JSN = "sm_opensips" + SM_JSN = "session_manager" + FS_JSN = "freeswitch" + KAMAILIO_JSN = "kamailio" + OSIPS_JSN = "opensips" + HISTSERV_JSN = "historys" + PUBSUBSERV_JSN = "pubsubs" + ALIASESSERV_JSN = "aliases" + USERSERV_JSN = "users" + MAILER_JSN = "mailer" ) // Loads the json config out of io.Reader, eg other sources than file, maybe over http @@ -256,6 +257,18 @@ func (self CgrJsonCfg) PubSubServJsonCfg() (*PubSubServJsonCfg, error) { return cfg, nil } +func (self CgrJsonCfg) AliasesServJsonCfg() (*AliasesServJsonCfg, error) { + rawCfg, hasKey := self[ALIASESSERV_JSN] + if !hasKey { + return nil, nil + } + cfg := new(AliasesServJsonCfg) + if err := json.Unmarshal(*rawCfg, cfg); err != nil { + return nil, err + } + return cfg, nil +} + func (self CgrJsonCfg) UserServJsonCfg() (*UserServJsonCfg, error) { rawCfg, hasKey := self[USERSERV_JSN] if !hasKey { diff --git a/config/config_json_test.go b/config/config_json_test.go index eac1e82b3..83ab592de 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -123,11 +123,11 @@ func TestDfBalancerJsonCfg(t *testing.T) { func TestDfRaterJsonCfg(t *testing.T) { eCfg := &RaterJsonCfg{Enabled: utils.BoolPointer(false), Balancer: utils.StringPointer(""), Cdrstats: utils.StringPointer(""), - Historys: utils.StringPointer(""), Pubsubs: utils.StringPointer(""), Users: utils.StringPointer("")} + Historys: utils.StringPointer(""), Pubsubs: utils.StringPointer(""), Users: utils.StringPointer(""), Aliases: utils.StringPointer("")} if cfg, err := dfCgrJsonCfg.RaterJsonCfg(); err != nil { t.Error(err) } else if !reflect.DeepEqual(eCfg, cfg) { - t.Error("Received: ", cfg) + t.Errorf("Received: %+v", cfg) } } @@ -417,6 +417,17 @@ func TestDfPubSubServJsonCfg(t *testing.T) { } } +func TestDfAliasesServJsonCfg(t *testing.T) { + eCfg := &AliasesServJsonCfg{ + Enabled: utils.BoolPointer(false), + } + if cfg, err := dfCgrJsonCfg.AliasesServJsonCfg(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eCfg, cfg) { + t.Error("Received: ", cfg) + } +} + func TestDfUserServJsonCfg(t *testing.T) { eCfg := &UserServJsonCfg{ Enabled: utils.BoolPointer(false), diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 7c285bb3a..9fd57e8ec 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -64,6 +64,7 @@ type RaterJsonCfg struct { Cdrstats *string Historys *string Pubsubs *string + Aliases *string Users *string } @@ -230,7 +231,12 @@ type PubSubServJsonCfg struct { Enabled *bool } -// PubSub server config section +// Aliases server config section +type AliasesServJsonCfg struct { + Enabled *bool +} + +// Users server config section type UserServJsonCfg struct { Enabled *bool Indexes *[]string diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index 4971943a5..991cd78c6 100644 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -72,6 +72,7 @@ // "historys": "", // address where to reach the history service, empty to disable history functionality: <""|internal|x.y.z.y:1234> // "pubsubs": "", // address where to reach the pubusb service, empty to disable pubsub functionality: <""|internal|x.y.z.y:1234> // "users": "", // address where to reach the user service, empty to disable user profile functionality: <""|internal|x.y.z.y:1234> +// "aliases": "", // address where to reach the aliases service, empty to disable aliases functionality: <""|internal|x.y.z.y:1234> //}, @@ -238,6 +239,9 @@ // "indexes": [], // user profile field indexes //}, +//"aliases": { +// "enabled": false, // starts Aliases service: . +//}, //"mailer": { // "server": "localhost", // the server to use when sending emails out