mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 16:18:44 +05:00
Add HTTP config option freeswiwtch_cdrs_url
This commit is contained in:
committed by
Dan Christian Bogos
parent
66a69d3ea7
commit
ac6a1c0597
@@ -728,6 +728,7 @@ func startRpc(server *utils.Server, internalRaterChan,
|
||||
cfg.HTTPWSURL,
|
||||
cfg.HTTPUseBasicAuth,
|
||||
cfg.HTTPAuthUsers,
|
||||
cfg.HTTPFreeswitchCDRSURL,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -275,6 +275,7 @@ type CGRConfig struct {
|
||||
HTTPWSURL string // WebSocket relative URL ("" to disable)
|
||||
HTTPUseBasicAuth bool // Use basic auth for HTTP API
|
||||
HTTPAuthUsers map[string]string // Basic auth user:password map (base64 passwords)
|
||||
HTTPFreeswitchCDRSURL string // Freeswitch CDRS relative URL ("" to disable)
|
||||
DefaultReqType string // Use this request type if not defined on top
|
||||
DefaultCategory string // set default type of record
|
||||
DefaultTenant string // set default tenant
|
||||
@@ -945,6 +946,9 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
if jsnHttpCfg.Auth_users != nil {
|
||||
self.HTTPAuthUsers = *jsnHttpCfg.Auth_users
|
||||
}
|
||||
if jsnHttpCfg.Freeswitch_cdrs_url != nil {
|
||||
self.HTTPFreeswitchCDRSURL = *jsnHttpCfg.Freeswitch_cdrs_url
|
||||
}
|
||||
}
|
||||
|
||||
if jsnFilterSCfg != nil {
|
||||
|
||||
@@ -83,11 +83,12 @@ const CGRATES_CFG_JSON = `
|
||||
},
|
||||
|
||||
|
||||
"http": { // HTTP server configuration
|
||||
"json_rpc_url": "/jsonrpc", // JSON RPC relative URL ("" to disable)
|
||||
"ws_url": "/ws", // WebSockets 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 "})
|
||||
"http": { // HTTP server configuration
|
||||
"json_rpc_url": "/jsonrpc", // JSON RPC relative URL ("" to disable)
|
||||
"ws_url": "/ws", // WebSockets 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 "})
|
||||
"freeswitch_cdrs_url": "/freeswitchcdrs", // Freeswitch CDRS relative URL ("" to disable)
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -946,10 +946,11 @@ func TestNewCgrJsonCfgFromFile(t *testing.T) {
|
||||
|
||||
func TestDfHttpJsonCfg(t *testing.T) {
|
||||
eCfg := &HTTPJsonCfg{
|
||||
Json_rpc_url: utils.StringPointer("/jsonrpc"),
|
||||
Ws_url: utils.StringPointer("/ws"),
|
||||
Use_basic_auth: utils.BoolPointer(false),
|
||||
Auth_users: utils.MapStringStringPointer(map[string]string{})}
|
||||
Json_rpc_url: utils.StringPointer("/jsonrpc"),
|
||||
Ws_url: utils.StringPointer("/ws"),
|
||||
Use_basic_auth: utils.BoolPointer(false),
|
||||
Auth_users: utils.MapStringStringPointer(map[string]string{}),
|
||||
Freeswitch_cdrs_url: utils.StringPointer("/freeswitchcdrs")}
|
||||
if cfg, err := dfCgrJsonCfg.HttpJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eCfg, cfg) {
|
||||
|
||||
@@ -831,6 +831,9 @@ func TestCgrCfgJSONDefaultsHTTP(t *testing.T) {
|
||||
if !reflect.DeepEqual(cgrCfg.HTTPAuthUsers, map[string]string{}) {
|
||||
t.Error(cgrCfg.HTTPAuthUsers)
|
||||
}
|
||||
if cgrCfg.HTTPFreeswitchCDRSURL != "/freeswitchcdrs" {
|
||||
t.Error(cgrCfg.HTTPFreeswitchCDRSURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRadiusAgentCfg(t *testing.T) {
|
||||
|
||||
@@ -51,10 +51,11 @@ type ListenJsonCfg struct {
|
||||
|
||||
// HTTP config section
|
||||
type HTTPJsonCfg struct {
|
||||
Json_rpc_url *string
|
||||
Ws_url *string
|
||||
Use_basic_auth *bool
|
||||
Auth_users *map[string]string
|
||||
Json_rpc_url *string
|
||||
Ws_url *string
|
||||
Use_basic_auth *bool
|
||||
Auth_users *map[string]string
|
||||
Freeswitch_cdrs_url *string
|
||||
}
|
||||
|
||||
// Database config
|
||||
|
||||
@@ -173,7 +173,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
io.Copy(w, res)
|
||||
}
|
||||
|
||||
func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string, useBasicAuth bool, userList map[string]string) {
|
||||
func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string,
|
||||
useBasicAuth bool, userList map[string]string, freeswitchCDRSURL string) {
|
||||
s.RLock()
|
||||
enabled := s.rpcEnabled
|
||||
s.RUnlock()
|
||||
@@ -215,6 +216,18 @@ func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string, useB
|
||||
if useBasicAuth {
|
||||
Logger.Info("<HTTP> enabling basic auth")
|
||||
}
|
||||
if enabled && freeswitchCDRSURL != "" {
|
||||
s.Lock()
|
||||
s.httpEnabled = true
|
||||
s.Unlock()
|
||||
Logger.Info("<HTTP> enabling handler for FreeswitchCDRS-URL")
|
||||
if useBasicAuth {
|
||||
http.HandleFunc(freeswitchCDRSURL, use(handleRequest, basicAuth(userList)))
|
||||
} else {
|
||||
http.HandleFunc(freeswitchCDRSURL, handleRequest)
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Info(fmt.Sprintf("<HTTP> start listening at <%s>", addr))
|
||||
http.ListenAndServe(addr, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user