mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
KamailioAgent with support for reply_route
This commit is contained in:
@@ -40,12 +40,13 @@ const (
|
||||
KamTRLabel = "tr_label"
|
||||
KamHashEntry = "h_entry"
|
||||
KamHashID = "h_id"
|
||||
KamReplyRoute = "reply_route"
|
||||
KamCGRSubsystems = "cgr_subsystems"
|
||||
EvapiConnID = "EvapiConnID" // used to share connID info in event for remote disconnects
|
||||
)
|
||||
|
||||
var (
|
||||
kamReservedEventFields = []string{EVENT, KamTRIndex, KamTRLabel, KamCGRSubsystems}
|
||||
kamReservedEventFields = []string{EVENT, KamTRIndex, KamTRLabel, KamCGRSubsystems, KamReplyRoute}
|
||||
kamReservedCDRFields = append(kamReservedEventFields, KamHashEntry, KamHashID) // HashEntry and id are needed in events for disconnects
|
||||
)
|
||||
|
||||
@@ -239,7 +240,11 @@ func (kev KamEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) {
|
||||
// AsKamAuthReply builds up a Kamailio AuthReply based on arguments and reply from SessionS
|
||||
func (kev KamEvent) AsKamAuthReply(authArgs *sessions.V1AuthorizeArgs,
|
||||
authReply *sessions.V1AuthorizeReply, rplyErr error) (kar *KamAuthReply, err error) {
|
||||
kar = &KamAuthReply{Event: CGR_AUTH_REPLY,
|
||||
evName := CGR_AUTH_REPLY
|
||||
if kamRouReply, has := kev[KamReplyRoute]; has {
|
||||
evName = kamRouReply
|
||||
}
|
||||
kar = &KamAuthReply{Event: evName,
|
||||
TransactionIndex: kev[KamTRIndex],
|
||||
TransactionLabel: kev[KamTRLabel],
|
||||
}
|
||||
|
||||
@@ -253,6 +253,45 @@ func TestKamEvAsKamAuthReply(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, rcv)
|
||||
}
|
||||
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().DefaultTenant),
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Time: &sTime,
|
||||
Event: kamEv.AsMapStringInterface(),
|
||||
},
|
||||
}
|
||||
authRply = &sessions.V1AuthorizeReply{
|
||||
Attributes: &engine.AttrSProcessEventReply{
|
||||
MatchedProfile: "ATTR_1001_ACCOUNT_PROFILE",
|
||||
AlteredFields: []string{"Password", utils.RequestType},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestKamEvAsKamAuthReply",
|
||||
Context: utils.StringPointer("account_profile"),
|
||||
Event: map[string]interface{}{
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Account: "1001",
|
||||
"Password": "check123",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
expected = &KamAuthReply{
|
||||
Event: "CGR_PROFILE_REPLY",
|
||||
Attributes: "Password:check123,RequestType:*prepaid",
|
||||
}
|
||||
if rcv, err := kamEv.AsKamAuthReply(authArgs, authRply, nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKamEvV1InitSessionArgs(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user