Update the /configs/ endpoint for http server

This commit is contained in:
TeoV
2020-08-30 09:46:26 +03:00
committed by Dan Christian Bogos
parent b97c442ced
commit b18bbd6e8c
4 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

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

View File

@@ -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",