Initial SureTax configuration

This commit is contained in:
DanB
2015-10-04 12:14:41 +02:00
parent b78918fc87
commit 9674f0ad31
6 changed files with 64 additions and 1 deletions

View File

@@ -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
}

View File

@@ -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
},
}`

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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
}