mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated Sessions Auth API
This commit is contained in:
committed by
Dan Christian Bogos
parent
25ed4f63ea
commit
5d540bc179
@@ -111,14 +111,17 @@ func processAttributeS(ctx *context.Context, connMgr *engine.ConnManager, cgrEv
|
||||
|
||||
// rateSCostForEvent will process the event with RateS in order to get the cost
|
||||
func rateSCostForEvent(ctx *context.Context, connMgr *engine.ConnManager, cgrEv *utils.CGREvent,
|
||||
rateSConns, rpIDs []string) (rplyCost *utils.RateProfileCost, err error) {
|
||||
rateSConns, rpIDs []string) (_ *utils.RateProfileCost, err error) {
|
||||
if len(rateSConns) == 0 {
|
||||
return nil, utils.NewErrNotConnected(utils.RateS)
|
||||
}
|
||||
tmp := cgrEv.APIOpts[utils.OptsRatesRateProfileIDs]
|
||||
cgrEv.APIOpts[utils.OptsRatesRateProfileIDs] = utils.CloneStringSlice(rpIDs)
|
||||
var tmpReply utils.RateProfileCost
|
||||
if err = connMgr.Call(ctx, rateSConns, utils.RateSv1CostForEvent,
|
||||
cgrEv, &tmpReply); err != nil {
|
||||
err = connMgr.Call(ctx, rateSConns, utils.RateSv1CostForEvent,
|
||||
cgrEv, &tmpReply)
|
||||
cgrEv.APIOpts[utils.OptsRatesRateProfileIDs] = tmp
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return &tmpReply, nil
|
||||
|
||||
@@ -166,7 +166,7 @@ func (sma *AsteriskAgent) handleStasisStart(ev *SMAsteriskEvent) {
|
||||
return
|
||||
}
|
||||
//authorize Session
|
||||
authArgs := ev.V1AuthorizeArgs()
|
||||
authArgs := ev.AsCGREvent()
|
||||
if authArgs == nil {
|
||||
sma.hangupChannel(ev.ChannelID(),
|
||||
fmt.Sprintf("<%s> event: %s cannot generate auth session arguments",
|
||||
@@ -199,7 +199,7 @@ func (sma *AsteriskAgent) handleStasisStart(ev *SMAsteriskEvent) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if authArgs.GetMaxUsage {
|
||||
if utils.OptAsBool(authArgs.APIOpts, utils.OptsAccountS) {
|
||||
if authReply.MaxUsage == nil ||
|
||||
authReply.MaxUsage.Compare(utils.NewDecimal(0, 0)) == 0 {
|
||||
sma.hangupChannel(ev.ChannelID(), "")
|
||||
@@ -235,7 +235,7 @@ func (sma *AsteriskAgent) handleStasisStart(ev *SMAsteriskEvent) {
|
||||
}
|
||||
// Done with processing event, cache it for later use
|
||||
sma.evCacheMux.Lock()
|
||||
sma.eventsCache[ev.ChannelID()] = authArgs.CGREvent
|
||||
sma.eventsCache[ev.ChannelID()] = authArgs
|
||||
sma.evCacheMux.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package agents
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -269,31 +267,12 @@ func (smaEv *SMAsteriskEvent) AsMapStringInterface() (mp map[string]interface{})
|
||||
}
|
||||
|
||||
// AsCGREvent converts AsteriskEvent into CGREvent
|
||||
func (smaEv *SMAsteriskEvent) AsCGREvent() (cgrEv *utils.CGREvent, err error) {
|
||||
cgrEv = &utils.CGREvent{
|
||||
func (smaEv *SMAsteriskEvent) AsCGREvent() *utils.CGREvent {
|
||||
return &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(smaEv.Tenant(),
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: smaEv.AsMapStringInterface(),
|
||||
APIOpts: smaEv.opts,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (smaEv *SMAsteriskEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) {
|
||||
cgrEv, err := smaEv.AsCGREvent()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
args = &sessions.V1AuthorizeArgs{
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
if smaEv.Subsystems() == utils.EmptyString {
|
||||
utils.Logger.Warning(fmt.Sprintf("<%s> cgr_flags variable is not set, using defaults",
|
||||
utils.AsteriskAgent))
|
||||
args.GetMaxUsage = true
|
||||
return
|
||||
}
|
||||
args.ParseFlags(smaEv.Subsystems(), utils.PlusChar)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -340,58 +339,6 @@ func TestSMAEventExtraParameters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMAEventV1AuthorizeArgs(t *testing.T) {
|
||||
var ev map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(stasisStart), &ev); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
smaEv := NewSMAsteriskEvent(ev, "127.0.0.1", "")
|
||||
cgrEv, err := smaEv.AsCGREvent()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
exp := &sessions.V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
if rcv := smaEv.V1AuthorizeArgs(); !reflect.DeepEqual(exp.GetMaxUsage, rcv.GetMaxUsage) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp.GetMaxUsage, rcv.GetMaxUsage)
|
||||
}
|
||||
|
||||
stasisStart2 := `{"type":"StasisStart","timestamp":"2018-11-25T05:03:26.464-0500","args":["cgr_reqtype=*prepaid","cgr_route=route1","cgr_flags=*accounts+*attributes+*resources+*stats+*routes+*thresholds"],"channel":{"id":"1543140206.0","dialplan":{"context":"internal","exten":"1002","priority":4},"caller":{"name":"","number":"1001"},"name":"PJSIP/1001-00000000","state":"Ring","connected":{"name":"","number":""},"language":"en","accountcode":"","creationtime":"2018-11-25T05:03:26.463-0500"},"asterisk_id":"08:00:27:b7:b8:1f","application":"cgrates_auth"}`
|
||||
var ev2 map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(stasisStart2), &ev2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
smaEv2 := NewSMAsteriskEvent(ev2, "127.0.0.1", "")
|
||||
//smaEv2.parseStasisArgs()
|
||||
cgrEv2, err := smaEv2.AsCGREvent()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
exp2 := &sessions.V1AuthorizeArgs{
|
||||
GetAttributes: true,
|
||||
AuthorizeResources: true,
|
||||
GetMaxUsage: true,
|
||||
ProcessThresholds: true,
|
||||
ProcessStats: true,
|
||||
GetRoutes: true,
|
||||
CGREvent: cgrEv2,
|
||||
}
|
||||
if rcv := smaEv2.V1AuthorizeArgs(); !reflect.DeepEqual(exp2.GetAttributes, rcv.GetAttributes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp2.GetAttributes, rcv.GetAttributes)
|
||||
} else if !reflect.DeepEqual(exp2.AuthorizeResources, rcv.AuthorizeResources) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp2.AuthorizeResources, rcv.AuthorizeResources)
|
||||
} else if !reflect.DeepEqual(exp2.GetMaxUsage, rcv.GetMaxUsage) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp2.GetMaxUsage, rcv.GetMaxUsage)
|
||||
} else if !reflect.DeepEqual(exp2.ProcessThresholds, rcv.ProcessThresholds) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp2.ProcessThresholds, rcv.ProcessThresholds)
|
||||
} else if !reflect.DeepEqual(exp2.ProcessStats, rcv.ProcessStats) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", exp2.ProcessStats, rcv.ProcessStats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestType(t *testing.T) {
|
||||
var ev map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(stasisStart), &ev); err != nil {
|
||||
|
||||
@@ -128,27 +128,24 @@ func TestProcessRequest(t *testing.T) {
|
||||
var id string
|
||||
if arg == nil {
|
||||
t.Errorf("args is nil")
|
||||
} else if rargs, can := arg.(*sessions.V1AuthorizeArgs); !can {
|
||||
t.Errorf("args is not of sessions.V1AuthorizeArgs type")
|
||||
} else if rargs, can := arg.(*utils.CGREvent); !can {
|
||||
t.Errorf("args is not of utils.CGREvent type")
|
||||
} else {
|
||||
id = rargs.ID
|
||||
}
|
||||
expargs := &sessions.V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: id,
|
||||
Event: map[string]interface{}{
|
||||
"Account": "1001",
|
||||
"Category": "call",
|
||||
"Destination": "1003",
|
||||
"OriginHost": "local",
|
||||
"OriginID": "123456",
|
||||
"ToR": "*voice",
|
||||
"Usage": "10s",
|
||||
},
|
||||
APIOpts: map[string]interface{}{},
|
||||
expargs := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: id,
|
||||
Event: map[string]interface{}{
|
||||
"Account": "1001",
|
||||
"Category": "call",
|
||||
"Destination": "1003",
|
||||
"OriginHost": "local",
|
||||
"OriginID": "123456",
|
||||
"ToR": "*voice",
|
||||
"Usage": "10s",
|
||||
},
|
||||
APIOpts: map[string]interface{}{},
|
||||
}
|
||||
if !reflect.DeepEqual(expargs, arg) {
|
||||
t.Errorf("Expected:%s ,received: %s", utils.ToJSON(expargs), utils.ToJSON(arg))
|
||||
|
||||
@@ -149,8 +149,8 @@ func (fsa *FSsessions) onChannelPark(fsev FSEvent, connIdx int) {
|
||||
return
|
||||
}
|
||||
fsev[VarCGROriginHost] = utils.FirstNonEmpty(fsev[VarCGROriginHost], fsa.cfg.EventSocketConns[connIdx].Alias) // rewrite the OriginHost variable if it is empty
|
||||
authArgs := fsev.V1AuthorizeArgs()
|
||||
authArgs.CGREvent.Event[FsConnID] = connIdx // Attach the connection ID
|
||||
authArgs := fsev.AsCGREvent(fsa.timezone)
|
||||
authArgs.Event[FsConnID] = connIdx // Attach the connection ID
|
||||
var authReply sessions.V1AuthorizeReply
|
||||
if err := fsa.connMgr.Call(fsa.ctx, fsa.cfg.SessionSConns, utils.SessionSv1AuthorizeEvent, authArgs, &authReply); err != nil {
|
||||
utils.Logger.Err(
|
||||
@@ -178,7 +178,7 @@ func (fsa *FSsessions) onChannelPark(fsev FSEvent, connIdx int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if authArgs.GetMaxUsage {
|
||||
if utils.OptAsBool(authArgs.APIOpts, utils.OptsAccountS) {
|
||||
if authReply.MaxUsage == nil ||
|
||||
authReply.MaxUsage.Compare(utils.NewDecimal(0, 0)) == 0 {
|
||||
fsa.unparkCall(fsev.GetUUID(), connIdx,
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/fsock"
|
||||
)
|
||||
@@ -391,24 +390,6 @@ func (fsev FSEvent) AsMapStringInterface(timezone string) map[string]interface{}
|
||||
return mp
|
||||
}
|
||||
|
||||
// V1AuthorizeArgs returns the arguments used in SMGv1.Authorize
|
||||
func (fsev FSEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) {
|
||||
cgrEv := fsev.AsCGREvent(config.CgrConfig().GeneralCfg().DefaultTimezone)
|
||||
cgrEv.Event[utils.Usage] = config.CgrConfig().SessionSCfg().GetDefaultUsage(utils.IfaceAsString(cgrEv.Event[utils.ToR])) // no billsec available in auth
|
||||
args = &sessions.V1AuthorizeArgs{ // defaults
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := fsev[VarCGRFlags]
|
||||
if !has {
|
||||
utils.Logger.Warning(fmt.Sprintf("<%s> cgr_flags variable is not set, using defaults",
|
||||
utils.FreeSWITCHAgent))
|
||||
args.GetMaxUsage = true
|
||||
return
|
||||
}
|
||||
args.ParseFlags(subsystems, utils.InfieldSep)
|
||||
return
|
||||
}
|
||||
|
||||
// SliceAsFsArray Converts a slice of strings into a FS array string, contains len(array) at first index since FS does not support len(ARRAY::) for now
|
||||
func SliceAsFsArray(slc []string) (arry string) {
|
||||
if len(slc) == 0 {
|
||||
|
||||
@@ -1004,39 +1004,3 @@ variable_rtp_audio_rtcp_octet_count: 0`
|
||||
t.Errorf("Expecting: %s, received: %s", fsCDR.CGRID, smCDR.CGRID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsEvV1AuthorizeArgs(t *testing.T) {
|
||||
timezone := config.CgrConfig().GeneralCfg().DefaultTimezone
|
||||
ev := NewFSEvent(hangupEv)
|
||||
expected := &sessions.V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: ev.GetTenant(utils.MetaDefault),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: ev.AsMapStringInterface(timezone),
|
||||
},
|
||||
GetRoutes: true,
|
||||
GetAttributes: true,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: utils.MetaEventCost,
|
||||
}
|
||||
expected.Event[utils.Usage] = config.CgrConfig().SessionSCfg().GetDefaultUsage(utils.MetaVoice)
|
||||
rcv := ev.V1AuthorizeArgs()
|
||||
if !reflect.DeepEqual(expected.CGREvent.Tenant, rcv.CGREvent.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Tenant, rcv.CGREvent.Tenant)
|
||||
} else if !reflect.DeepEqual(expected.CGREvent.Event, rcv.CGREvent.Event) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Event, rcv.CGREvent.Event)
|
||||
} else if !reflect.DeepEqual(expected.CGREvent.Event, rcv.CGREvent.Event) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Event, rcv.CGREvent.Event)
|
||||
} else if !reflect.DeepEqual(expected.GetMaxUsage, rcv.GetMaxUsage) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetMaxUsage, rcv.GetMaxUsage)
|
||||
} else if !reflect.DeepEqual(expected.GetRoutes, rcv.GetRoutes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetRoutes, rcv.GetRoutes)
|
||||
} else if !reflect.DeepEqual(expected.GetAttributes, rcv.GetAttributes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetAttributes, rcv.GetAttributes)
|
||||
} else if !reflect.DeepEqual(expected.RoutesMaxCost, rcv.RoutesMaxCost) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.RoutesMaxCost, rcv.RoutesMaxCost)
|
||||
} else if !reflect.DeepEqual(expected.RoutesIgnoreErrors, rcv.RoutesIgnoreErrors) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.RoutesIgnoreErrors, rcv.RoutesIgnoreErrors)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ func (ka *KamailioAgent) onCgrAuth(evData []byte, connIdx int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
authArgs := kev.V1AuthorizeArgs()
|
||||
authArgs := kev.AsCGREvent(ka.timezone)
|
||||
if authArgs == nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<%s> event: %s cannot generate auth session arguments",
|
||||
utils.KamailioAgent, kev[utils.OriginID]))
|
||||
return
|
||||
}
|
||||
authArgs.CGREvent.Event[EvapiConnID] = connIdx // Attach the connection ID
|
||||
authArgs.Event[EvapiConnID] = connIdx // Attach the connection ID
|
||||
var authReply sessions.V1AuthorizeReply
|
||||
// take the error after calling SessionSv1.AuthorizeEvent
|
||||
// and send it as parameter to AsKamAuthReply
|
||||
|
||||
@@ -20,7 +20,6 @@ package agents
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -169,25 +168,8 @@ func (kev KamEvent) String() string {
|
||||
return utils.ToJSON(kev)
|
||||
}
|
||||
|
||||
// V1AuthorizeArgs returns the arguments used in SessionSv1.AuthorizeEvent
|
||||
func (kev KamEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) {
|
||||
cgrEv := kev.AsCGREvent(config.CgrConfig().GeneralCfg().DefaultTimezone)
|
||||
args = &sessions.V1AuthorizeArgs{
|
||||
CGREvent: cgrEv,
|
||||
}
|
||||
subsystems, has := kev[utils.CGRFlags]
|
||||
if !has {
|
||||
utils.Logger.Warning(fmt.Sprintf("<%s> cgr_flags variable is not set, using defaults",
|
||||
utils.KamailioAgent))
|
||||
args.GetMaxUsage = true
|
||||
return
|
||||
}
|
||||
args.ParseFlags(subsystems, utils.InfieldSep)
|
||||
return
|
||||
}
|
||||
|
||||
// AsKamAuthReply builds up a Kamailio AuthReply based on arguments and reply from SessionS
|
||||
func (kev KamEvent) AsKamAuthReply(authArgs *sessions.V1AuthorizeArgs,
|
||||
func (kev KamEvent) AsKamAuthReply(authArgs *utils.CGREvent,
|
||||
authReply *sessions.V1AuthorizeReply, rplyErr error) (kar *KamReply, err error) {
|
||||
evName := CGR_AUTH_REPLY
|
||||
if kamRouReply, has := kev[KamReplyRoute]; has {
|
||||
@@ -201,13 +183,13 @@ func (kev KamEvent) AsKamAuthReply(authArgs *sessions.V1AuthorizeArgs,
|
||||
kar.Error = rplyErr.Error()
|
||||
return
|
||||
}
|
||||
if authArgs.GetAttributes && authReply.Attributes != nil {
|
||||
if authReply.Attributes != nil {
|
||||
kar.Attributes = authReply.Attributes.Digest()
|
||||
}
|
||||
if authArgs.AuthorizeResources && authReply.ResourceAllocation != nil {
|
||||
if authReply.ResourceAllocation != nil {
|
||||
kar.ResourceAllocation = *authReply.ResourceAllocation
|
||||
}
|
||||
if authArgs.GetMaxUsage {
|
||||
if utils.OptAsBool(authArgs.APIOpts, utils.OptsAccountS) {
|
||||
if authReply.MaxUsage != nil {
|
||||
maxDur, _ := authReply.MaxUsage.Duration()
|
||||
kar.MaxUsage = maxDur.Seconds()
|
||||
@@ -215,14 +197,14 @@ func (kev KamEvent) AsKamAuthReply(authArgs *sessions.V1AuthorizeArgs,
|
||||
kar.MaxUsage = 0
|
||||
}
|
||||
}
|
||||
if authArgs.GetRoutes && authReply.RouteProfiles != nil {
|
||||
if authReply.RouteProfiles != nil {
|
||||
kar.Routes = authReply.RouteProfiles.Digest()
|
||||
}
|
||||
|
||||
if authArgs.ProcessThresholds && authReply.ThresholdIDs != nil {
|
||||
if authReply.ThresholdIDs != nil {
|
||||
kar.Thresholds = strings.Join(*authReply.ThresholdIDs, utils.FieldsSep)
|
||||
}
|
||||
if authArgs.ProcessStats && authReply.StatQueueIDs != nil {
|
||||
if authReply.StatQueueIDs != nil {
|
||||
kar.StatQueues = strings.Join(*authReply.StatQueueIDs, utils.FieldsSep)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -133,90 +133,6 @@ func TestKamEvAsCGREvent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestKamEvV1AuthorizeArgs(t *testing.T) {
|
||||
kamEv := KamEvent{"event": "CGR_CALL_END",
|
||||
"callid": "46c01a5c249b469e76333fc6bfa87f6a@0:0:0:0:0:0:0:0",
|
||||
"from_tag": "bf71ad59", "to_tag": "7351fecf",
|
||||
"cgr_reqtype": utils.MetaPostpaid, "cgr_account": "1001",
|
||||
"cgr_destination": "1002", "cgr_answertime": "1419839310",
|
||||
"cgr_duration": "3", "cgr_pdd": "4",
|
||||
utils.CGRRoute: "supplier2",
|
||||
utils.CGRDisconnectCause: "200",
|
||||
utils.CGRFlags: "*accounts;*routes;*routesEventCost;*rouIgnoreErrors"}
|
||||
expected := &sessions.V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
},
|
||||
GetRoutes: true,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: utils.MetaEventCost,
|
||||
}
|
||||
rcv := kamEv.V1AuthorizeArgs()
|
||||
if !reflect.DeepEqual(expected.CGREvent.Tenant, rcv.CGREvent.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Tenant, rcv.CGREvent.Tenant)
|
||||
} else if !reflect.DeepEqual(expected.CGREvent.Event, rcv.CGREvent.Event) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Event, rcv.CGREvent.Event)
|
||||
} else if !reflect.DeepEqual(expected.CGREvent.Event, rcv.CGREvent.Event) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Event, rcv.CGREvent.Event)
|
||||
} else if !reflect.DeepEqual(expected.GetMaxUsage, rcv.GetMaxUsage) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetMaxUsage, rcv.GetMaxUsage)
|
||||
} else if !reflect.DeepEqual(expected.GetRoutes, rcv.GetRoutes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetRoutes, rcv.GetRoutes)
|
||||
} else if !reflect.DeepEqual(expected.GetAttributes, rcv.GetAttributes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetAttributes, rcv.GetAttributes)
|
||||
} else if !reflect.DeepEqual(expected.RoutesMaxCost, rcv.RoutesMaxCost) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.RoutesMaxCost, rcv.RoutesMaxCost)
|
||||
} else if !reflect.DeepEqual(expected.RoutesIgnoreErrors, rcv.RoutesIgnoreErrors) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.RoutesIgnoreErrors, rcv.RoutesIgnoreErrors)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKamEvV1AuthorizeArgs2(t *testing.T) {
|
||||
kamEv := KamEvent{"event": "CGR_CALL_END",
|
||||
"callid": "46c01a5c249b469e76333fc6bfa87f6a@0:0:0:0:0:0:0:0",
|
||||
"from_tag": "bf71ad59", "to_tag": "7351fecf",
|
||||
"cgr_reqtype": utils.MetaPostpaid, "cgr_account": "1001",
|
||||
"cgr_destination": "1002", "cgr_answertime": "1419839310",
|
||||
"cgr_duration": "3", "cgr_pdd": "4",
|
||||
utils.CGRRoute: "supplier2",
|
||||
utils.CGRDisconnectCause: "200",
|
||||
utils.CGRFlags: "*accounts;*routes;*rouMaxCost:100;*rouIgnoreErrors"}
|
||||
expected := &sessions.V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
},
|
||||
GetRoutes: true,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: "100",
|
||||
}
|
||||
rcv := kamEv.V1AuthorizeArgs()
|
||||
if !reflect.DeepEqual(expected.CGREvent.Tenant, rcv.CGREvent.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Tenant, rcv.CGREvent.Tenant)
|
||||
} else if !reflect.DeepEqual(expected.CGREvent.Event, rcv.CGREvent.Event) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Event, rcv.CGREvent.Event)
|
||||
} else if !reflect.DeepEqual(expected.CGREvent.Event, rcv.CGREvent.Event) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.CGREvent.Event, rcv.CGREvent.Event)
|
||||
} else if !reflect.DeepEqual(expected.GetMaxUsage, rcv.GetMaxUsage) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetMaxUsage, rcv.GetMaxUsage)
|
||||
} else if !reflect.DeepEqual(expected.GetRoutes, rcv.GetRoutes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetRoutes, rcv.GetRoutes)
|
||||
} else if !reflect.DeepEqual(expected.GetAttributes, rcv.GetAttributes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.GetAttributes, rcv.GetAttributes)
|
||||
} else if !reflect.DeepEqual(expected.RoutesMaxCost, rcv.RoutesMaxCost) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.RoutesMaxCost, rcv.RoutesMaxCost)
|
||||
} else if !reflect.DeepEqual(expected.RoutesIgnoreErrors, rcv.RoutesIgnoreErrors) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected.RoutesIgnoreErrors, rcv.RoutesIgnoreErrors)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKamEvAsKamAuthReply(t *testing.T) {
|
||||
kamEv := KamEvent{"event": "CGR_CALL_END",
|
||||
"callid": "46c01a5c249b469e76333fc6bfa87f6a@0:0:0:0:0:0:0:0",
|
||||
@@ -225,15 +141,14 @@ func TestKamEvAsKamAuthReply(t *testing.T) {
|
||||
"cgr_destination": "1002", "cgr_answertime": "1419839310",
|
||||
"cgr_duration": "3", "cgr_pdd": "4",
|
||||
utils.CGRRoute: "supplier2",
|
||||
utils.CGRDisconnectCause: "200"}
|
||||
authArgs := &sessions.V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
},
|
||||
utils.CGRDisconnectCause: "200",
|
||||
utils.OptsAccountS: "true"}
|
||||
authArgs := &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
APIOpts: kamEv.GetOptions(),
|
||||
}
|
||||
authRply := &sessions.V1AuthorizeReply{
|
||||
MaxUsage: utils.NewDecimalFromFloat64(5 * float64(time.Second)),
|
||||
@@ -249,15 +164,14 @@ func TestKamEvAsKamAuthReply(t *testing.T) {
|
||||
}
|
||||
kamEv = KamEvent{"event": "CGR_PROFILE_REQUEST",
|
||||
"Tenant": "cgrates.org", "Account": "1001",
|
||||
KamReplyRoute: "CGR_PROFILE_REPLY"}
|
||||
authArgs = &sessions.V1AuthorizeArgs{
|
||||
GetAttributes: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
},
|
||||
KamReplyRoute: "CGR_PROFILE_REPLY",
|
||||
utils.OptsAttributeS: "true"}
|
||||
authArgs = &utils.CGREvent{
|
||||
Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant],
|
||||
config.CgrConfig().GeneralCfg().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
APIOpts: kamEv.GetOptions(),
|
||||
}
|
||||
authRply = &sessions.V1AuthorizeReply{
|
||||
Attributes: &engine.AttrSProcessEventReply{
|
||||
|
||||
@@ -64,25 +64,10 @@ func processRequest(ctx *context.Context, reqProcessor *config.RequestProcessor,
|
||||
fmt.Sprintf("<%s> DRY_RUN, processorID: %s, DiameterMessage: %s",
|
||||
agentName, reqProcessor.ID, agReq.Request.String()))
|
||||
case utils.MetaAuthorize:
|
||||
authArgs := sessions.NewV1AuthorizeArgs(
|
||||
reqProcessor.Flags.GetBool(utils.MetaAttributes),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaAttributes, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaThresholds),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaThresholds, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaStats),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaResources),
|
||||
reqProcessor.Flags.Has(utils.MetaAccounts),
|
||||
reqProcessor.Flags.GetBool(utils.MetaRoutes),
|
||||
reqProcessor.Flags.Has(utils.OptsRoutesIgnoreErrors),
|
||||
reqProcessor.Flags.Has(utils.MetaRoutesEventCost),
|
||||
cgrEv, reqProcessor.Flags.Has(utils.MetaFD),
|
||||
reqProcessor.Flags.ParamValue(utils.OptsRoutesMaxCost),
|
||||
)
|
||||
rply := new(sessions.V1AuthorizeReply)
|
||||
err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1AuthorizeEvent,
|
||||
authArgs, rply)
|
||||
rply.SetMaxUsageNeeded(authArgs.GetMaxUsage)
|
||||
cgrEv, rply)
|
||||
rply.SetMaxUsageNeeded(utils.OptAsBool(cgrEv.APIOpts, utils.OptsAccountS))
|
||||
agReq.setCGRReply(rply, err)
|
||||
case utils.MetaInitiate:
|
||||
rply := new(sessions.V1InitSessionReply)
|
||||
|
||||
@@ -198,25 +198,10 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R
|
||||
fmt.Sprintf("<%s> DRY_RUN, processorID: %s, CGREvent: %s",
|
||||
utils.RadiusAgent, reqProcessor.ID, utils.ToJSON(cgrEv)))
|
||||
case utils.MetaAuthorize:
|
||||
authArgs := sessions.NewV1AuthorizeArgs(
|
||||
reqProcessor.Flags.GetBool(utils.MetaAttributes),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaAttributes, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaThresholds),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaThresholds, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaStats),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaResources),
|
||||
reqProcessor.Flags.Has(utils.MetaAccounts),
|
||||
reqProcessor.Flags.GetBool(utils.MetaRoutes),
|
||||
reqProcessor.Flags.Has(utils.OptsRoutesIgnoreErrors),
|
||||
reqProcessor.Flags.Has(utils.MetaRoutesEventCost),
|
||||
cgrEv, reqProcessor.Flags.Has(utils.MetaFD),
|
||||
reqProcessor.Flags.ParamValue(utils.OptsRoutesMaxCost),
|
||||
)
|
||||
rply := new(sessions.V1AuthorizeReply)
|
||||
err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1AuthorizeEvent,
|
||||
authArgs, rply)
|
||||
rply.SetMaxUsageNeeded(authArgs.GetMaxUsage)
|
||||
cgrEv, rply)
|
||||
rply.SetMaxUsageNeeded(utils.OptAsBool(cgrEv.APIOpts, utils.OptsAccountS))
|
||||
agReq.setCGRReply(rply, err)
|
||||
case utils.MetaInitiate:
|
||||
rply := new(sessions.V1InitSessionReply)
|
||||
|
||||
@@ -411,25 +411,10 @@ func (sa *SIPAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
fmt.Sprintf("<%s> DRY_RUN, processorID: %s, CGREvent: %s",
|
||||
utils.SIPAgent, reqProcessor.ID, utils.ToJSON(cgrEv)))
|
||||
case utils.MetaAuthorize:
|
||||
authArgs := sessions.NewV1AuthorizeArgs(
|
||||
reqProcessor.Flags.GetBool(utils.MetaAttributes),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaAttributes, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaThresholds),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaThresholds, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaStats),
|
||||
reqProcessor.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs),
|
||||
reqProcessor.Flags.GetBool(utils.MetaResources),
|
||||
reqProcessor.Flags.Has(utils.MetaAccounts),
|
||||
reqProcessor.Flags.GetBool(utils.MetaRoutes),
|
||||
reqProcessor.Flags.Has(utils.OptsRoutesIgnoreErrors),
|
||||
reqProcessor.Flags.Has(utils.MetaRoutesEventCost),
|
||||
cgrEv, reqProcessor.Flags.Has(utils.MetaFD),
|
||||
reqProcessor.Flags.ParamValue(utils.OptsRoutesMaxCost),
|
||||
)
|
||||
rply := new(sessions.V1AuthorizeReply)
|
||||
err = sa.connMgr.Call(context.TODO(), sa.cfg.SIPAgentCfg().SessionSConns, utils.SessionSv1AuthorizeEvent,
|
||||
authArgs, rply)
|
||||
rply.SetMaxUsageNeeded(authArgs.GetMaxUsage)
|
||||
cgrEv, rply)
|
||||
rply.SetMaxUsageNeeded(utils.OptAsBool(cgrEv.APIOpts, utils.OptsAccountS))
|
||||
agReq.setCGRReply(rply, err)
|
||||
case utils.MetaEvent:
|
||||
rply := new(sessions.V1ProcessEventReply)
|
||||
|
||||
@@ -37,12 +37,12 @@ type SessionSv1 struct {
|
||||
sS *sessions.SessionS
|
||||
}
|
||||
|
||||
func (ssv1 *SessionSv1) AuthorizeEvent(ctx *context.Context, args *sessions.V1AuthorizeArgs,
|
||||
func (ssv1 *SessionSv1) AuthorizeEvent(ctx *context.Context, args *utils.CGREvent,
|
||||
rply *sessions.V1AuthorizeReply) error {
|
||||
return ssv1.sS.BiRPCv1AuthorizeEvent(ctx, args, rply)
|
||||
}
|
||||
|
||||
func (ssv1 *SessionSv1) AuthorizeEventWithDigest(ctx *context.Context, args *sessions.V1AuthorizeArgs,
|
||||
func (ssv1 *SessionSv1) AuthorizeEventWithDigest(ctx *context.Context, args *utils.CGREvent,
|
||||
rply *sessions.V1AuthorizeReplyWithDigest) error {
|
||||
return ssv1.sS.BiRPCv1AuthorizeEventWithDigest(ctx, args, rply)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
c := &CmdSessionsAuthorize{
|
||||
name: "session_authorize_event",
|
||||
rpcMethod: utils.SessionSv1AuthorizeEventWithDigest,
|
||||
rpcParams: &sessions.V1AuthorizeArgs{},
|
||||
rpcParams: &utils.CGREvent{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
type CmdSessionsAuthorize struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *sessions.V1AuthorizeArgs
|
||||
rpcParams *utils.CGREvent
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
@@ -50,9 +50,7 @@ func (self *CmdSessionsAuthorize) RpcMethod() string {
|
||||
|
||||
func (self *CmdSessionsAuthorize) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &sessions.V1AuthorizeArgs{
|
||||
CGREvent: new(utils.CGREvent),
|
||||
}
|
||||
self.rpcParams = new(utils.CGREvent)
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
@@ -35,28 +35,28 @@ func (dS *DispatcherService) SessionSv1Ping(args *utils.CGREvent, reply *string)
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaSessionS, utils.SessionSv1Ping, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *sessions.V1AuthorizeArgs,
|
||||
func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *utils.CGREvent,
|
||||
reply *sessions.V1AuthorizeReply) (err error) {
|
||||
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
|
||||
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if err = dS.authorize(utils.SessionSv1AuthorizeEvent, args.CGREvent.Tenant,
|
||||
if err = dS.authorize(utils.SessionSv1AuthorizeEvent, args.Tenant,
|
||||
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey])); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(context.TODO(), args.CGREvent, utils.MetaSessionS, utils.SessionSv1AuthorizeEvent, args, reply)
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaSessionS, utils.SessionSv1AuthorizeEvent, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs,
|
||||
func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *utils.CGREvent,
|
||||
reply *sessions.V1AuthorizeReplyWithDigest) (err error) {
|
||||
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
|
||||
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if err = dS.authorize(utils.SessionSv1AuthorizeEventWithDigest, args.CGREvent.Tenant,
|
||||
if err = dS.authorize(utils.SessionSv1AuthorizeEventWithDigest, args.Tenant,
|
||||
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey])); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(context.TODO(), args.CGREvent, utils.MetaSessionS, utils.SessionSv1AuthorizeEventWithDigest, args, reply)
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaSessionS, utils.SessionSv1AuthorizeEventWithDigest, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1InitiateSession(args *utils.CGREvent,
|
||||
|
||||
@@ -58,10 +58,8 @@ func TestDspSessionSv1PingErrorNil(t *testing.T) {
|
||||
func TestDspSessionSv1AuthorizeEventNil(t *testing.T) {
|
||||
cgrCfg := config.NewDefaultCGRConfig()
|
||||
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
|
||||
CGREvent := &sessions.V1AuthorizeArgs{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
},
|
||||
CGREvent := &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
}
|
||||
var reply *sessions.V1AuthorizeReply
|
||||
result := dspSrv.SessionSv1AuthorizeEvent(CGREvent, reply)
|
||||
@@ -75,10 +73,8 @@ func TestDspSessionSv1AuthorizeEventErrorNil(t *testing.T) {
|
||||
cgrCfg := config.NewDefaultCGRConfig()
|
||||
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
|
||||
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
|
||||
CGREvent := &sessions.V1AuthorizeArgs{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
},
|
||||
CGREvent := &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
}
|
||||
var reply *sessions.V1AuthorizeReply
|
||||
result := dspSrv.SessionSv1AuthorizeEvent(CGREvent, reply)
|
||||
@@ -91,10 +87,8 @@ func TestDspSessionSv1AuthorizeEventErrorNil(t *testing.T) {
|
||||
func TestDspSessionSv1AuthorizeEventWithDigestNil(t *testing.T) {
|
||||
cgrCfg := config.NewDefaultCGRConfig()
|
||||
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
|
||||
CGREvent := &sessions.V1AuthorizeArgs{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
},
|
||||
CGREvent := &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
}
|
||||
var reply *sessions.V1AuthorizeReplyWithDigest
|
||||
result := dspSrv.SessionSv1AuthorizeEventWithDigest(CGREvent, reply)
|
||||
@@ -108,10 +102,8 @@ func TestDspSessionSv1AuthorizeEventWithDigestErrorNil(t *testing.T) {
|
||||
cgrCfg := config.NewDefaultCGRConfig()
|
||||
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
|
||||
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
|
||||
CGREvent := &sessions.V1AuthorizeArgs{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
},
|
||||
CGREvent := &utils.CGREvent{
|
||||
Tenant: "tenant",
|
||||
}
|
||||
var reply *sessions.V1AuthorizeReplyWithDigest
|
||||
result := dspSrv.SessionSv1AuthorizeEventWithDigest(CGREvent, reply)
|
||||
|
||||
17
ers/ers.go
17
ers/ers.go
@@ -199,24 +199,9 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent,
|
||||
fmt.Sprintf("<%s> DRYRUN, reader: <%s>, CGREvent: <%s>",
|
||||
utils.ERs, rdrCfg.ID, utils.ToJSON(cgrEv)))
|
||||
case utils.MetaAuthorize:
|
||||
authArgs := sessions.NewV1AuthorizeArgs(
|
||||
rdrCfg.Flags.Has(utils.MetaAttributes),
|
||||
rdrCfg.Flags.ParamsSlice(utils.MetaAttributes, utils.MetaIDs),
|
||||
rdrCfg.Flags.Has(utils.MetaThresholds),
|
||||
rdrCfg.Flags.ParamsSlice(utils.MetaThresholds, utils.MetaIDs),
|
||||
rdrCfg.Flags.Has(utils.MetaStats),
|
||||
rdrCfg.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs),
|
||||
rdrCfg.Flags.Has(utils.MetaResources),
|
||||
rdrCfg.Flags.Has(utils.MetaAccounts),
|
||||
rdrCfg.Flags.Has(utils.MetaRoutes),
|
||||
rdrCfg.Flags.Has(utils.OptsRoutesIgnoreErrors),
|
||||
rdrCfg.Flags.Has(utils.MetaRoutesEventCost),
|
||||
cgrEv, rdrCfg.Flags.Has(utils.MetaFD),
|
||||
rdrCfg.Flags.ParamValue(utils.OptsRoutesMaxCost),
|
||||
)
|
||||
rply := new(sessions.V1AuthorizeReply)
|
||||
err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1AuthorizeEvent,
|
||||
authArgs, rply)
|
||||
cgrEv, rply)
|
||||
case utils.MetaInitiate:
|
||||
rply := new(sessions.V1InitSessionReply)
|
||||
err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1InitiateSession,
|
||||
|
||||
@@ -424,90 +424,6 @@ func (v1Rply *V1ProcessMessageReply) AsNavigableMap() map[string]*utils.DataNode
|
||||
return cgrReply
|
||||
}
|
||||
|
||||
// NewV1AuthorizeArgs is a constructor for V1AuthorizeArgs
|
||||
func NewV1AuthorizeArgs(attrs bool, attributeIDs []string,
|
||||
thrslds bool, thresholdIDs []string, statQueues bool, statIDs []string,
|
||||
res, maxUsage, routes, routesIgnoreErrs, routesEventCost bool,
|
||||
cgrEv *utils.CGREvent, forceDuration bool, routesMaxCost string) (args *V1AuthorizeArgs) {
|
||||
args = &V1AuthorizeArgs{
|
||||
GetAttributes: attrs,
|
||||
AuthorizeResources: res,
|
||||
GetMaxUsage: maxUsage,
|
||||
ProcessThresholds: thrslds,
|
||||
ProcessStats: statQueues,
|
||||
RoutesIgnoreErrors: routesIgnoreErrs,
|
||||
GetRoutes: routes,
|
||||
CGREvent: cgrEv,
|
||||
ForceDuration: forceDuration,
|
||||
}
|
||||
if routesEventCost {
|
||||
args.RoutesMaxCost = utils.MetaEventCost
|
||||
} else {
|
||||
args.RoutesMaxCost = routesMaxCost
|
||||
}
|
||||
if len(attributeIDs) != 0 {
|
||||
args.AttributeIDs = attributeIDs
|
||||
}
|
||||
if len(thresholdIDs) != 0 {
|
||||
args.ThresholdIDs = thresholdIDs
|
||||
}
|
||||
if len(statIDs) != 0 {
|
||||
args.StatIDs = statIDs
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// V1AuthorizeArgs are options available in auth request
|
||||
type V1AuthorizeArgs struct {
|
||||
GetAttributes bool
|
||||
AuthorizeResources bool
|
||||
GetMaxUsage bool
|
||||
ForceDuration bool
|
||||
ProcessThresholds bool
|
||||
ProcessStats bool
|
||||
GetRoutes bool
|
||||
RoutesMaxCost string
|
||||
RoutesIgnoreErrors bool
|
||||
AttributeIDs []string
|
||||
ThresholdIDs []string
|
||||
StatIDs []string
|
||||
*utils.CGREvent
|
||||
}
|
||||
|
||||
func (V1AuthorizeArgs) RPCClone() {} // disable rpcClonable from CGREvent
|
||||
|
||||
// ParseFlags will populate the V1AuthorizeArgs flags
|
||||
func (args *V1AuthorizeArgs) ParseFlags(flags, sep string) {
|
||||
for _, subsystem := range strings.Split(flags, sep) {
|
||||
switch {
|
||||
case subsystem == utils.MetaAccounts:
|
||||
args.GetMaxUsage = true
|
||||
case subsystem == utils.MetaResources:
|
||||
args.AuthorizeResources = true
|
||||
case subsystem == utils.MetaRoutes:
|
||||
args.GetRoutes = true
|
||||
case subsystem == utils.OptsRoutesIgnoreErrors:
|
||||
args.RoutesIgnoreErrors = true
|
||||
case subsystem == utils.MetaRoutesEventCost:
|
||||
args.RoutesMaxCost = utils.MetaEventCost
|
||||
case strings.HasPrefix(subsystem, utils.OptsRoutesMaxCost):
|
||||
args.RoutesMaxCost = strings.TrimPrefix(subsystem, utils.OptsRoutesMaxCost+utils.InInFieldSep)
|
||||
case strings.HasPrefix(subsystem, utils.MetaAttributes):
|
||||
args.GetAttributes = true
|
||||
args.AttributeIDs = getFlagIDs(subsystem)
|
||||
case strings.HasPrefix(subsystem, utils.MetaThresholds):
|
||||
args.ProcessThresholds = true
|
||||
args.ThresholdIDs = getFlagIDs(subsystem)
|
||||
case strings.HasPrefix(subsystem, utils.MetaStats):
|
||||
args.ProcessStats = true
|
||||
args.StatIDs = getFlagIDs(subsystem)
|
||||
case subsystem == utils.MetaFD:
|
||||
args.ForceDuration = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// V1AuthorizeReply are options available in auth reply
|
||||
type V1AuthorizeReply struct {
|
||||
Attributes *engine.AttrSProcessEventReply `json:",omitempty"`
|
||||
|
||||
@@ -1534,21 +1534,21 @@ func (sS *SessionS) BiRPCv1ReplicateSessions(ctx *context.Context,
|
||||
|
||||
// BiRPCv1AuthorizeEvent performs authorization for CGREvent based on specific components
|
||||
func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
args *V1AuthorizeArgs, authReply *V1AuthorizeReply) (err error) {
|
||||
if args.CGREvent == nil {
|
||||
args *utils.CGREvent, authReply *V1AuthorizeReply) (err error) {
|
||||
if args == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.CGREventString)
|
||||
}
|
||||
var withErrors bool
|
||||
if args.CGREvent.ID == "" {
|
||||
args.CGREvent.ID = utils.GenUUID()
|
||||
if args.ID == "" {
|
||||
args.ID = utils.GenUUID()
|
||||
}
|
||||
if args.CGREvent.Tenant == "" {
|
||||
args.CGREvent.Tenant = sS.cgrCfg.GeneralCfg().DefaultTenant
|
||||
if args.Tenant == "" {
|
||||
args.Tenant = sS.cgrCfg.GeneralCfg().DefaultTenant
|
||||
}
|
||||
|
||||
// RPC caching
|
||||
if sS.cgrCfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit != 0 {
|
||||
cacheKey := utils.ConcatenatedKey(utils.SessionSv1AuthorizeEvent, args.CGREvent.ID)
|
||||
cacheKey := utils.ConcatenatedKey(utils.SessionSv1AuthorizeEvent, args.ID)
|
||||
refID := guardian.Guardian.GuardIDs("",
|
||||
sS.cgrCfg.GeneralCfg().LockingTimeout, cacheKey) // RPC caching needs to be atomic
|
||||
defer guardian.Guardian.UnguardIDs(refID)
|
||||
@@ -1576,34 +1576,21 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
} else if attrS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if !(args.GetAttributes || attrS || utils.OptAsBool(args.APIOpts, utils.OptsSesMaxUsage) ||
|
||||
args.AuthorizeResources || utils.OptAsBool(args.APIOpts, utils.OptsSesResourceSAuthorize) ||
|
||||
args.GetRoutes || utils.OptAsBool(args.APIOpts, utils.OptsRouteS)) {
|
||||
if !(attrS || utils.OptAsBool(args.APIOpts, utils.OptsSesMaxUsage) ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsSesResourceSAuthorize) ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsRouteS)) {
|
||||
return // Nothing to do
|
||||
}
|
||||
if args.APIOpts == nil {
|
||||
args.APIOpts = make(map[string]interface{})
|
||||
}
|
||||
if v, has := args.APIOpts[utils.OptsAttributeS]; !has {
|
||||
/*
|
||||
if attrS, err = engine.FilterBoolCfgOpts(ctx, args.Tenant, args.CGREvent.AsDataProvider(), sS.filterS,
|
||||
sS.cgrCfg.CdrsCfg().Opts.Attributes); err != nil {
|
||||
return
|
||||
}
|
||||
*/
|
||||
} else if attrS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if args.GetAttributes || attrS {
|
||||
if attrS {
|
||||
if args.APIOpts == nil {
|
||||
args.APIOpts = make(map[string]interface{})
|
||||
}
|
||||
if args.AttributeIDs != nil {
|
||||
args.APIOpts[utils.OptsAttributesAttributeIDs] = args.AttributeIDs
|
||||
}
|
||||
rplyAttr, err := sS.processAttributes(ctx, args.CGREvent)
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args.CGREvent = rplyAttr.CGREvent
|
||||
args = rplyAttr.CGREvent
|
||||
authReply.Attributes = &rplyAttr
|
||||
} else if err.Error() != utils.ErrNotFound.Error() {
|
||||
return utils.NewErrAttributeS(err)
|
||||
@@ -1624,14 +1611,14 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
}
|
||||
if chrgS {
|
||||
var chrgrs []*engine.ChrgSProcessEventReply
|
||||
if chrgrs, err = sS.processChargerS(ctx, args.CGREvent); err != nil {
|
||||
if chrgrs, err = sS.processChargerS(ctx, args); err != nil {
|
||||
return
|
||||
}
|
||||
for _, chrgr := range chrgrs {
|
||||
runEvents[chrgr.ChargerSProfile] = chrgr.CGREvent
|
||||
}
|
||||
} else {
|
||||
runEvents[utils.MetaRaw] = args.CGREvent
|
||||
runEvents[utils.MetaRaw] = args
|
||||
}
|
||||
var acntS bool
|
||||
if v, has := args.APIOpts[utils.OptsAccountS]; !has {
|
||||
@@ -1647,16 +1634,14 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
if acntS {
|
||||
var maxAbstracts map[string]*utils.Decimal
|
||||
if maxAbstracts, err = sS.accounSMaxAbstracts(ctx, runEvents); err != nil {
|
||||
return err
|
||||
authReply.MaxUsage = getMaxUsageFromRuns(maxAbstracts)
|
||||
}
|
||||
authReply.MaxUsage = getMaxUsageFromRuns(maxAbstracts)
|
||||
}
|
||||
if args.AuthorizeResources ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsSesResourceSAuthorize) {
|
||||
if utils.OptAsBool(args.APIOpts, utils.OptsSesResourceSAuthorize) {
|
||||
if len(sS.cgrCfg.SessionSCfg().ResourceSConns) == 0 {
|
||||
return utils.NewErrNotConnected(utils.ResourceS)
|
||||
}
|
||||
originID, _ := args.CGREvent.FieldAsString(utils.OriginID)
|
||||
originID, _ := args.FieldAsString(utils.OriginID)
|
||||
if originID == "" {
|
||||
originID = utils.UUIDSha1Prefix()
|
||||
}
|
||||
@@ -1669,11 +1654,8 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
}
|
||||
authReply.ResourceAllocation = &allocMsg
|
||||
}
|
||||
if args.GetRoutes ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsRouteS) {
|
||||
args.APIOpts[utils.OptsRoutesMaxCost] = utils.FirstNonEmpty(args.RoutesMaxCost, utils.IfaceAsString(args.APIOpts[utils.OptsSesRouteSMaxCost]))
|
||||
args.APIOpts[utils.OptsRoutesIgnoreErrors] = args.RoutesIgnoreErrors || utils.OptAsBool(args.APIOpts, utils.OptsSesRouteSIgnoreErrors)
|
||||
routesReply, err := sS.getRoutes(ctx, args.CGREvent.Clone())
|
||||
if utils.OptAsBool(args.APIOpts, utils.OptsRouteS) {
|
||||
routesReply, err := sS.getRoutes(ctx, args.Clone())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1692,20 +1674,16 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
} else if thdS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if args.ProcessThresholds ||
|
||||
thdS {
|
||||
if thdS {
|
||||
var thIDs []string
|
||||
if thIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesThresholdIDs); err != nil {
|
||||
return
|
||||
}
|
||||
if thIDs == nil {
|
||||
thIDs = args.ThresholdIDs
|
||||
}
|
||||
tIDs, err := sS.processThreshold(ctx, args.CGREvent, thIDs, true)
|
||||
tIDs, err := sS.processThreshold(ctx, args, thIDs, true)
|
||||
if err != nil && err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing event %+v with ThresholdS.",
|
||||
utils.SessionS, err.Error(), args.CGREvent))
|
||||
utils.SessionS, err.Error(), args))
|
||||
withErrors = true
|
||||
}
|
||||
authReply.ThresholdIDs = &tIDs
|
||||
@@ -1721,20 +1699,17 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
} else if stS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if args.ProcessStats || stS {
|
||||
if stS {
|
||||
var statIDs []string
|
||||
if statIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesStatIDs); err != nil {
|
||||
return
|
||||
}
|
||||
if statIDs == nil {
|
||||
statIDs = args.StatIDs
|
||||
}
|
||||
sIDs, err := sS.processStats(ctx, args.CGREvent, statIDs, false)
|
||||
sIDs, err := sS.processStats(ctx, args, statIDs, false)
|
||||
if err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing event %+v with StatS.",
|
||||
utils.SessionS, err.Error(), args.CGREvent))
|
||||
utils.SessionS, err.Error(), args))
|
||||
withErrors = true
|
||||
}
|
||||
authReply.StatQueueIDs = &sIDs
|
||||
@@ -1748,7 +1723,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
// BiRPCv1AuthorizeEventWithDigest performs authorization for CGREvent based on specific components
|
||||
// returning one level fields instead of multiple ones returned by BiRPCv1AuthorizeEvent
|
||||
func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context,
|
||||
args *V1AuthorizeArgs, authReply *V1AuthorizeReplyWithDigest) (err error) {
|
||||
args *utils.CGREvent, authReply *V1AuthorizeReplyWithDigest) (err error) {
|
||||
var initAuthRply V1AuthorizeReply
|
||||
if err = sS.BiRPCv1AuthorizeEvent(ctx, args, &initAuthRply); err != nil {
|
||||
return
|
||||
@@ -1764,11 +1739,10 @@ func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context,
|
||||
} else if attrS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if (args.GetAttributes || attrS) && initAuthRply.Attributes != nil {
|
||||
if attrS && initAuthRply.Attributes != nil {
|
||||
authReply.AttributesDigest = utils.StringPointer(initAuthRply.Attributes.Digest())
|
||||
}
|
||||
if args.AuthorizeResources ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsSesResourceSAuthorize) {
|
||||
if utils.OptAsBool(args.APIOpts, utils.OptsSesResourceSAuthorize) {
|
||||
authReply.ResourceAllocation = initAuthRply.ResourceAllocation
|
||||
}
|
||||
var acntS bool
|
||||
@@ -1786,8 +1760,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context,
|
||||
maxDur, _ := initAuthRply.MaxUsage.Duration()
|
||||
authReply.MaxUsage = maxDur.Seconds()
|
||||
}
|
||||
if args.GetRoutes ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsRouteS) {
|
||||
if utils.OptAsBool(args.APIOpts, utils.OptsRouteS) {
|
||||
authReply.RoutesDigest = utils.StringPointer(initAuthRply.RouteProfiles.Digest())
|
||||
}
|
||||
var thdS bool
|
||||
@@ -1801,7 +1774,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context,
|
||||
} else if thdS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if args.ProcessThresholds || thdS {
|
||||
if thdS {
|
||||
authReply.Thresholds = utils.StringPointer(
|
||||
strings.Join(*initAuthRply.ThresholdIDs, utils.FieldsSep))
|
||||
}
|
||||
@@ -1816,7 +1789,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context,
|
||||
} else if stS, err = utils.IfaceAsBool(v); err != nil {
|
||||
return
|
||||
}
|
||||
if args.ProcessStats || stS {
|
||||
if stS {
|
||||
authReply.StatQueues = utils.StringPointer(
|
||||
strings.Join(*initAuthRply.StatQueueIDs, utils.FieldsSep))
|
||||
}
|
||||
|
||||
@@ -942,90 +942,6 @@ func TestSessionSNewV1AuthorizeArgs(t *testing.T) {
|
||||
}
|
||||
*/
|
||||
|
||||
func TestV1AuthorizeArgsParseFlags1(t *testing.T) {
|
||||
v1authArgs := new(V1AuthorizeArgs)
|
||||
v1authArgs.CGREvent = new(utils.CGREvent)
|
||||
eOut := new(V1AuthorizeArgs)
|
||||
eOut.CGREvent = new(utils.CGREvent)
|
||||
//empty check
|
||||
strArg := ""
|
||||
v1authArgs.ParseFlags(strArg, utils.InfieldSep)
|
||||
if !reflect.DeepEqual(eOut, v1authArgs) {
|
||||
t.Errorf("Expecting %+v,\n received: %+v", eOut, v1authArgs)
|
||||
}
|
||||
//normal check -> without *dispatchers
|
||||
eOut = &V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
AuthorizeResources: true,
|
||||
GetRoutes: true,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: utils.MetaEventCost,
|
||||
GetAttributes: true,
|
||||
AttributeIDs: []string{"Attr1", "Attr2"},
|
||||
ProcessThresholds: true,
|
||||
ThresholdIDs: []string{"tr1", "tr2", "tr3"},
|
||||
ProcessStats: true,
|
||||
StatIDs: []string{"st1", "st2", "st3"},
|
||||
CGREvent: eOut.CGREvent,
|
||||
ForceDuration: true,
|
||||
}
|
||||
|
||||
strArg = "*accounts;*fd;*resources;*routes;*rouIgnoreErrors;*routesEventCost;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3"
|
||||
v1authArgs = new(V1AuthorizeArgs)
|
||||
v1authArgs.CGREvent = new(utils.CGREvent)
|
||||
v1authArgs.ParseFlags(strArg, utils.InfieldSep)
|
||||
if !reflect.DeepEqual(eOut, v1authArgs) {
|
||||
t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1authArgs))
|
||||
}
|
||||
// //normal check -> with *dispatchers
|
||||
eOut = &V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
AuthorizeResources: true,
|
||||
GetRoutes: true,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: utils.MetaEventCost,
|
||||
GetAttributes: true,
|
||||
AttributeIDs: []string{"Attr1", "Attr2"},
|
||||
ProcessThresholds: true,
|
||||
ThresholdIDs: []string{"tr1", "tr2", "tr3"},
|
||||
ProcessStats: true,
|
||||
StatIDs: []string{"st1", "st2", "st3"},
|
||||
CGREvent: eOut.CGREvent,
|
||||
ForceDuration: true,
|
||||
}
|
||||
|
||||
strArg = "*accounts;*fd;*resources;;*dispatchers;*routes;*rouIgnoreErrors;*routesEventCost;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3"
|
||||
v1authArgs = new(V1AuthorizeArgs)
|
||||
v1authArgs.CGREvent = new(utils.CGREvent)
|
||||
v1authArgs.ParseFlags(strArg, utils.InfieldSep)
|
||||
if !reflect.DeepEqual(eOut, v1authArgs) {
|
||||
t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1authArgs))
|
||||
}
|
||||
eOut = &V1AuthorizeArgs{
|
||||
GetMaxUsage: true,
|
||||
AuthorizeResources: true,
|
||||
GetRoutes: true,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: "100",
|
||||
GetAttributes: true,
|
||||
AttributeIDs: []string{"Attr1", "Attr2"},
|
||||
ProcessThresholds: true,
|
||||
ThresholdIDs: []string{"tr1", "tr2", "tr3"},
|
||||
ProcessStats: true,
|
||||
StatIDs: []string{"st1", "st2", "st3"},
|
||||
CGREvent: eOut.CGREvent,
|
||||
ForceDuration: true,
|
||||
}
|
||||
|
||||
strArg = "*accounts;*fd;*resources;;*dispatchers;*routes;*rouIgnoreErrors;*rouMaxCost:100;*attributes:Attr1&Attr2;*thresholds:tr1&tr2&tr3;*stats:st1&st2&st3"
|
||||
v1authArgs = new(V1AuthorizeArgs)
|
||||
v1authArgs.CGREvent = new(utils.CGREvent)
|
||||
v1authArgs.ParseFlags(strArg, utils.InfieldSep)
|
||||
if !reflect.DeepEqual(eOut, v1authArgs) {
|
||||
t.Errorf("Expecting %+v,\n received: %+v\n", utils.ToJSON(eOut), utils.ToJSON(v1authArgs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSV1AuthorizeReplyAsNavigableMap(t *testing.T) {
|
||||
splrs := engine.SortedRoutesList{
|
||||
{
|
||||
@@ -1426,93 +1342,6 @@ func TestSessionSrelocateSessionS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSNewV1AuthorizeArgsWithOpts(t *testing.T) {
|
||||
|
||||
cgrEv := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Event",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: "1002",
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "testkey",
|
||||
utils.OptsRouteID: "testrouteid",
|
||||
},
|
||||
}
|
||||
expected := &V1AuthorizeArgs{
|
||||
AuthorizeResources: true,
|
||||
GetAttributes: true,
|
||||
CGREvent: cgrEv,
|
||||
ForceDuration: true,
|
||||
}
|
||||
rply := NewV1AuthorizeArgs(true, nil, false, nil, false, nil, true, false,
|
||||
false, false, false, cgrEv, true, "")
|
||||
if !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
expected = &V1AuthorizeArgs{
|
||||
GetAttributes: true,
|
||||
AuthorizeResources: false,
|
||||
GetMaxUsage: true,
|
||||
ProcessThresholds: false,
|
||||
ProcessStats: true,
|
||||
GetRoutes: false,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: utils.MetaEventCost,
|
||||
CGREvent: cgrEv,
|
||||
ForceDuration: true,
|
||||
}
|
||||
rply = NewV1AuthorizeArgs(true, nil, false, nil, true, nil, false, true,
|
||||
false, true, true, cgrEv, true, "")
|
||||
if !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSNewV1AuthorizeArgsWithOpts2(t *testing.T) {
|
||||
|
||||
cgrEv := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Event",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: "1002",
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.OptsRouteID: "testrouteid",
|
||||
},
|
||||
}
|
||||
expected := &V1AuthorizeArgs{
|
||||
AuthorizeResources: true,
|
||||
GetAttributes: true,
|
||||
CGREvent: cgrEv,
|
||||
ForceDuration: true,
|
||||
}
|
||||
rply := NewV1AuthorizeArgs(true, nil, false, nil, false, nil, true, false, false,
|
||||
false, false, cgrEv, true, "")
|
||||
if !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
expected = &V1AuthorizeArgs{
|
||||
GetAttributes: true,
|
||||
AuthorizeResources: false,
|
||||
GetMaxUsage: true,
|
||||
ProcessThresholds: false,
|
||||
ProcessStats: true,
|
||||
GetRoutes: false,
|
||||
RoutesIgnoreErrors: true,
|
||||
RoutesMaxCost: utils.MetaEventCost,
|
||||
CGREvent: cgrEv,
|
||||
ForceDuration: true,
|
||||
}
|
||||
rply = NewV1AuthorizeArgs(true, nil, false, nil, true, nil, false, true, false,
|
||||
true, true, cgrEv, true, "")
|
||||
if !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSGetIndexedFilters(t *testing.T) {
|
||||
sSCfg := config.NewDefaultCGRConfig()
|
||||
mpStr := engine.NewInternalDB(nil, nil, true)
|
||||
|
||||
Reference in New Issue
Block a user