From b18bbd6e8cb3e90c35e5f60484af2fe2168576fe Mon Sep 17 00:00:00 2001 From: TeoV Date: Sun, 30 Aug 2020 09:46:26 +0300 Subject: [PATCH] Update the /configs/ endpoint for http server --- config/config.go | 9 +++++---- config/config_defaults.go | 2 +- config/config_json_test.go | 2 +- config/suretaxcfg_test.go | 6 +++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index dbf40bc56..0c3b87da0 100755 --- a/config/config.go +++ b/config/config.go @@ -1624,8 +1624,9 @@ func (cfg *CGRConfig) AsMapInterface(separator string) map[string]interface{} { func HandlerConfigS(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() w.Header().Set("Content-Type", "application/json") - // check if the path exists - fi, err := os.Stat(r.URL.Path) + // take out the /configs prefix and use the rest of url as path + path := strings.TrimPrefix(r.URL.Path, "/configs") + fi, err := os.Stat(path) if err != nil { if os.IsNotExist(err) { w.WriteHeader(404) @@ -1637,9 +1638,9 @@ func HandlerConfigS(w http.ResponseWriter, r *http.Request) { } switch mode := fi.Mode(); { case mode.IsDir(): - handleConfigSFolder(r.URL.Path, w) + handleConfigSFolder(path, w) case mode.IsRegular(): - handleConfigSFile(r.URL.Path, w) + handleConfigSFile(path, w) } return } diff --git a/config/config_defaults.go b/config/config_defaults.go index c4feb63d5..c33ae7d27 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -185,7 +185,7 @@ 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": "/configs" // configs + "configs": "/configs/" // configs }, diff --git a/config/config_json_test.go b/config/config_json_test.go index abe0e391d..327a8e7b9 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -1557,7 +1557,7 @@ 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: utils.StringPointer("/configs"), + Configs: utils.StringPointer("/configs/"), } if cfg, err := dfCgrJSONCfg.HttpJsonCfg(); err != nil { t.Error(err) diff --git a/config/suretaxcfg_test.go b/config/suretaxcfg_test.go index ab261f49f..d84191cee 100644 --- a/config/suretaxcfg_test.go +++ b/config/suretaxcfg_test.go @@ -68,12 +68,16 @@ func TestSureTaxCfgloadFromJsonCfg(t *testing.T) { "tax_exemption_code_list": "", }, }` + tLocal, err := time.LoadLocation("Local") + if err != nil { + t.Error(err) + } expected = SureTaxCfg{ Url: utils.EmptyString, ClientNumber: utils.EmptyString, ValidationKey: utils.EmptyString, BusinessUnit: utils.EmptyString, - Timezone: &time.Location{}, + Timezone: tLocal, IncludeLocalCost: false, ReturnFileCode: "0", ResponseGroup: "03",