diff --git a/config/config.go b/config/config.go index 900d7020a..015a6e8c8 100644 --- a/config/config.go +++ b/config/config.go @@ -238,6 +238,7 @@ type CGRConfig struct { MailerAuthUser string // Authenticate to email server using this user MailerAuthPass string // Authenticate to email server with this password MailerFromAddr string // From address used when sending emails out + SureTax *SureTaxCfg // Load here SureTax configuration, as pointer so we can have runtime reloads in the future DataFolderPath string // Path towards data folder, for tests internal usage, not loading out of .json options ConfigReloads map[string]chan struct{} // Signals to specific entities that a config reload should occur // Cache defaults loaded from json and needing clones @@ -462,6 +463,11 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { return err } + jsnSureTaxCfg, err := jsnCfg.SureTaxJsonCfg() + if err != nil { + return err + } + // All good, start populating config variables if jsnTpDbCfg != nil { if jsnTpDbCfg.Db_type != nil { @@ -796,5 +802,18 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { self.MailerFromAddr = *jsnMailerCfg.From_address } } + + if jsnSureTaxCfg != nil { + self.SureTax = new(SureTaxCfg) // Reset previous values + if jsnSureTaxCfg.Url != nil { + self.SureTax.Url = *jsnSureTaxCfg.Url + } + if jsnSureTaxCfg.Client_number != nil { + self.SureTax.ClientNumber = *jsnSureTaxCfg.Client_number + } + if jsnSureTaxCfg.Validation_key != nil { + self.SureTax.ValidationKey = *jsnSureTaxCfg.Validation_key + } + } return nil } diff --git a/config/config_defaults.go b/config/config_defaults.go index c6a1ede8a..ab5cdc961 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -279,4 +279,10 @@ const CGRATES_CFG_JSON = ` }, +"suretax": { + "url": "", // API url + "client_number": "", // client number, provided by SureTax + "validation_key": "", // validation key provided by SureTax +}, + }` diff --git a/config/config_json.go b/config/config_json.go index 353ec4a8a..33d7663a6 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -52,6 +52,7 @@ const ( ALIASESSERV_JSN = "aliases" USERSERV_JSN = "users" MAILER_JSN = "mailer" + SURETAX_JSON = "suretax" ) // Loads the json config out of io.Reader, eg other sources than file, maybe over http @@ -292,3 +293,15 @@ func (self CgrJsonCfg) MailerJsonCfg() (*MailerJsonCfg, error) { } return cfg, nil } + +func (self CgrJsonCfg) SureTaxJsonCfg() (*SureTaxJsonCfg, error) { + rawCfg, hasKey := self[SURETAX_JSON] + if !hasKey { + return nil, nil + } + cfg := new(SureTaxJsonCfg) + if err := json.Unmarshal(*rawCfg, cfg); err != nil { + return nil, err + } + return cfg, nil +} diff --git a/config/config_json_test.go b/config/config_json_test.go index fb027cc3d..036da9e96 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -444,7 +444,6 @@ func TestDfUserServJsonCfg(t *testing.T) { } func TestDfMailerJsonCfg(t *testing.T) { - eCfg := &MailerJsonCfg{ Server: utils.StringPointer("localhost"), Auth_user: utils.StringPointer("cgrates"), @@ -458,6 +457,19 @@ func TestDfMailerJsonCfg(t *testing.T) { } } +func TestDfSureTaxJsonCfg(t *testing.T) { + eCfg := &SureTaxJsonCfg{ + Url: utils.StringPointer(""), + Client_number: utils.StringPointer(""), + Validation_key: utils.StringPointer(""), + } + if cfg, err := dfCgrJsonCfg.SureTaxJsonCfg(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eCfg, cfg) { + t.Error("Received: ", cfg) + } +} + func TestNewCgrJsonCfgFromFile(t *testing.T) { cgrJsonCfg, err := NewCgrJsonCfgFromFile("cfg_data.json") if err != nil { diff --git a/config/libconfig.go b/config/libconfig.go index 9b964066f..723cd79cf 100644 --- a/config/libconfig.go +++ b/config/libconfig.go @@ -29,3 +29,9 @@ type CdrReplicationCfg struct { Attempts int // Number of attempts if not success CdrFilter utils.RSRFields // Only replicate if the filters here are matching } + +type SureTaxCfg struct { + Url string + ClientNumber string + ValidationKey string +} diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 2965c7d43..8d16356ed 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -253,3 +253,10 @@ type MailerJsonCfg struct { Auth_passwd *string From_address *string } + +// SureTax config section +type SureTaxJsonCfg struct { + Url *string // API url + Client_number *string // client number provided by SureTax + Validation_key *string // validation key provided by SureTax +}