mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added Stir/Shaken APIs to DispatcherS
This commit is contained in:
committed by
Dan Christian Bogos
parent
c3cea2d52d
commit
bd8949eb8c
@@ -95,6 +95,9 @@ type SessionSv1Interface interface {
|
||||
SetPassiveSession(args *sessions.Session, reply *string) error
|
||||
ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error
|
||||
DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error
|
||||
|
||||
STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error
|
||||
STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error
|
||||
}
|
||||
|
||||
type ResponderInterface interface {
|
||||
|
||||
@@ -520,6 +520,13 @@ func (dS *DispatcherSessionSv1) SyncSessions(args *utils.TenantWithArgDispatcher
|
||||
return dS.dS.SessionSv1SyncSessions(args, rply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherSessionSv1) STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error {
|
||||
return dS.dS.SessionSv1STIRAuthenticate(args, reply)
|
||||
}
|
||||
func (dS *DispatcherSessionSv1) STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error {
|
||||
return dS.dS.SessionSv1STIRIdentity(args, reply)
|
||||
}
|
||||
|
||||
func NewDispatcherResponder(dps *dispatchers.DispatcherService) *DispatcherResponder {
|
||||
return &DispatcherResponder{dS: dps}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~*req.APIKey:thr12345,,,*req.APIMeth
|
||||
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~*req.APIKey:sup12345,,,*req.APIMethods,*constant,SupplierSv1.Ping&SupplierSv1.GetSuppliers&SupplierSv1.GetSupplierProfilesForEvent,false,20
|
||||
cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.APIKey:stat12345,,,*req.APIMethods,*constant,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20
|
||||
cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.APIKey:res12345,,,*req.APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources&ResourceSv1.GetResource,false,20
|
||||
cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent&SessionSv1.GetCost,false,20
|
||||
cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent&SessionSv1.GetCost&SessionSv1.STIRAuthenticate&SessionSv1.STIRIdentity,false,20
|
||||
cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.APIKey:rsp12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20
|
||||
cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.APIKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20
|
||||
cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.APIKey:grd12345,,,*req.APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20
|
||||
|
||||
|
@@ -9,7 +9,7 @@ cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~*req.APIKey:thr12345,,,*req.APIMeth
|
||||
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~*req.APIKey:sup12345,,,*req.APIMethods,*constant,SupplierSv1.Ping&SupplierSv1.GetSuppliers&SupplierSv1.GetSupplierProfilesForEvent,false,20
|
||||
cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.APIKey:stat12345,,,*req.APIMethods,*constant,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20
|
||||
cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.APIKey:res12345,,,*req.APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources&ResourceSv1.GetResource,false,20
|
||||
cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent&SessionSv1.GetCost,false,20
|
||||
cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.APIKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent&SessionSv1.GetCost&SessionSv1.STIRAuthenticate&SessionSv1.STIRIdentity,false,20
|
||||
cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.APIKey:rsp12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20
|
||||
cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.APIKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20
|
||||
cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.APIKey:grd12345,,,*req.APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20
|
||||
|
||||
|
@@ -482,3 +482,41 @@ func (dS *DispatcherService) SessionSv1DeactivateSessions(args *utils.SessionIDs
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaSessionS, routeID,
|
||||
utils.SessionSv1DeactivateSessions, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if args.ArgDispatcher == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
|
||||
}
|
||||
if err = dS.authorize(utils.SessionSv1STIRAuthenticate,
|
||||
tnt, args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var routeID *string
|
||||
if args.ArgDispatcher != nil {
|
||||
routeID = args.ArgDispatcher.RouteID
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaSessionS, routeID,
|
||||
utils.SessionSv1STIRAuthenticate, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if args.ArgDispatcher == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
|
||||
}
|
||||
if err = dS.authorize(utils.SessionSv1STIRIdentity,
|
||||
tnt, args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var routeID *string
|
||||
if args.ArgDispatcher != nil {
|
||||
routeID = args.ArgDispatcher.RouteID
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaSessionS, routeID,
|
||||
utils.SessionSv1STIRIdentity, args, reply)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,9 @@ var sTestsDspSession = []func(t *testing.T){
|
||||
testDspSessionGetCost,
|
||||
testDspSessionReplicate,
|
||||
testDspSessionPassive,
|
||||
|
||||
testDspSessionSTIRAuthenticate,
|
||||
testDspSessionSTIRIdentity,
|
||||
testDspSessionForceDisconect,
|
||||
}
|
||||
|
||||
@@ -972,3 +975,48 @@ func testDspSessionGetCost(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testDspSessionSTIRAuthenticate(t *testing.T) {
|
||||
var rply string
|
||||
if err := dispEngine.RPC.Call(utils.SessionSv1STIRAuthenticate,
|
||||
&sessions.V1STIRAuthenticateArgs{
|
||||
Attest: []string{"A"},
|
||||
PayloadMaxDuration: "-1",
|
||||
DestinationTn: "1002",
|
||||
Identity: "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiL3Vzci9zaGFyZS9jZ3JhdGVzL3N0aXIvc3Rpcl9wdWJrZXkucGVtIn0.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxMDAyIl19LCJpYXQiOjE1ODcwMzg4MDIsIm9yaWciOnsidG4iOiIxMDAxIn0sIm9yaWdpZCI6IjEyMzQ1NiJ9.cMEMlFnfyTu8uxfeU4RoZTamA7ifFT9Ibwrvi1_LKwL2xAU6fZ_CSIxKbtyOpNhM_sV03x7CfA_v0T4sHkifzg;info=</usr/share/cgrates/stir/stir_pubkey.pem>;ppt=shaken",
|
||||
OriginatorTn: "1001",
|
||||
ArgDispatcher: &utils.ArgDispatcher{
|
||||
APIKey: utils.StringPointer("ses12345"),
|
||||
},
|
||||
}, &rply); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if rply != utils.OK {
|
||||
t.Errorf("Expected: %s ,received: %s", utils.OK, rply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSessionSTIRIdentity(t *testing.T) {
|
||||
payload := &utils.PASSporTPayload{
|
||||
Dest: utils.PASSporTDestinationsIdentity{Tn: []string{"1002"}},
|
||||
IAT: 1587019822,
|
||||
Orig: utils.PASSporTOriginsIdentity{Tn: "1001"},
|
||||
OrigID: "123456",
|
||||
}
|
||||
args := &sessions.V1STIRIdentityArgs{
|
||||
Payload: payload,
|
||||
PublicKeyPath: "/usr/share/cgrates/stir/stir_pubkey.pem",
|
||||
PrivateKeyPath: "/usr/share/cgrates/stir/stir_privatekey.pem",
|
||||
OverwriteIAT: true,
|
||||
ArgDispatcher: &utils.ArgDispatcher{
|
||||
APIKey: utils.StringPointer("ses12345"),
|
||||
},
|
||||
}
|
||||
var rply string
|
||||
if err := dispEngine.RPC.Call(utils.SessionSv1STIRIdentity,
|
||||
args, &rply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := sessions.AuthStirShaken(rply, "1001", "", "1002", "", utils.NewStringSet([]string{"A"}), 10*time.Minute); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,7 @@ type V1STIRAuthenticateArgs struct {
|
||||
OriginatorTn string // the expected originator telephone number
|
||||
OriginatorURI string // the expected originator URI; if this is populated the OriginatorTn is ignored
|
||||
PayloadMaxDuration string // the duration the payload is valid after it's creation
|
||||
*utils.ArgDispatcher
|
||||
}
|
||||
|
||||
// V1STIRIdentityArgs are the arguments for STIRIdentity API
|
||||
@@ -252,4 +253,5 @@ type V1STIRIdentityArgs struct {
|
||||
PublicKeyPath string // the path to the public key used in the header
|
||||
PrivateKeyPath string // the private key path
|
||||
OverwriteIAT bool // if true the IAT from payload is overwrited with the present unix timestamp
|
||||
*utils.ArgDispatcher
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user