mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 15:48:44 +05:00
Updated sentrypeer filter value types
This commit is contained in:
committed by
Dan Christian Bogos
parent
8ed7bdd060
commit
2c1f5012fc
@@ -270,7 +270,7 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
|
||||
case utils.MetaAPIBan:
|
||||
_, err = dm.GetAPIBan(utils.EmptyString, config.CgrConfig().APIBanCfg().Keys, false, false, true)
|
||||
case utils.MetaSentryPeer:
|
||||
_, err = GetSentryPeer(utils.EmptyString, config.CgrConfig().SentryPeerCfg().Addr, config.CgrConfig().SentryPeerCfg().Token, utils.EmptyString, false, true)
|
||||
_, err = GetSentryPeer(utils.EmptyString, config.CgrConfig().SentryPeerCfg().Url, config.CgrConfig().SentryPeerCfg().Token, utils.EmptyString, false, true)
|
||||
}
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound && err != utils.ErrDSPProfileNotFound && err != utils.ErrDSPHostNotFound {
|
||||
|
||||
@@ -121,19 +121,27 @@ func WeightFromDynamics(dWs []*utils.DynamicWeight,
|
||||
return 0.0, nil
|
||||
}
|
||||
|
||||
func GetSentryPeer(val, addr, token, path string, cacheRead, cacheWrite bool) (found bool, err error) {
|
||||
func GetSentryPeer(val, url, token, path string, cacheRead, cacheWrite bool) (found bool, err error) {
|
||||
valpath := utils.ConcatenatedKey(path, val)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.MetaSentryPeer, valpath); ok && x != nil { // Attempt to find in cache first
|
||||
return x.(bool), nil
|
||||
}
|
||||
}
|
||||
switch path {
|
||||
case "*ip":
|
||||
url += "ip-addresses/"
|
||||
case "*number":
|
||||
url += "phone-numbers/"
|
||||
}
|
||||
var req *http.Request
|
||||
if req, err = http.NewRequest("GET", addr+path+"/"+val, nil); err != nil {
|
||||
if req, err = http.NewRequest("GET", url+val, nil); err != nil {
|
||||
return
|
||||
}
|
||||
req.Header = http.Header{
|
||||
"Authorization": {fmt.Sprintf("Bearer %s", token)},
|
||||
if token != "" {
|
||||
req.Header = http.Header{
|
||||
"Authorization": {fmt.Sprintf("Bearer %s", token)},
|
||||
}
|
||||
}
|
||||
var resp *http.Response
|
||||
resp, err = http.DefaultClient.Do(req)
|
||||
|
||||
@@ -656,10 +656,10 @@ func (fltr *FilterRule) passSentryPeer(dDP utils.DataProvider) (bool, error) {
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if fltr.Values[0] != "phone-numbers" && fltr.Values[0] != "ip-addresses" {
|
||||
if fltr.Values[0] != "*number" && fltr.Values[0] != "*ip" {
|
||||
return false, fmt.Errorf("invalid value for sentrypeer filter: <%s>", fltr.Values[0])
|
||||
}
|
||||
return GetSentryPeer(strVal, config.CgrConfig().SentryPeerCfg().Addr, config.CgrConfig().SentryPeerCfg().Token, fltr.Values[0], true, true)
|
||||
return GetSentryPeer(strVal, config.CgrConfig().SentryPeerCfg().Url, config.CgrConfig().SentryPeerCfg().Token, fltr.Values[0], true, true)
|
||||
}
|
||||
|
||||
func parseTime(rsr *config.RSRParser, dDp utils.DataProvider) (_ time.Time, err error) {
|
||||
|
||||
Reference in New Issue
Block a user