SessionS to rewrite the tenant via AttributeS

This commit is contained in:
DanB
2019-02-21 12:58:08 +01:00
parent 00302d2a5d
commit db7826a5d7
3 changed files with 31 additions and 0 deletions

View File

@@ -1592,6 +1592,11 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection,
if err := sS.attrS.Call(utils.AttributeSv1ProcessEvent,
attrArgs, &rplyEv); err == nil {
args.CGREvent = *rplyEv.CGREvent
if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has {
// special case when we want to overwrite the tenant
args.CGREvent.Tenant = tntIface.(string)
delete(args.CGREvent.Event, utils.MetaTenant)
}
authReply.Attributes = &rplyEv
} else if err.Error() != utils.ErrNotFound.Error() {
return utils.NewErrAttributeS(err)
@@ -1822,6 +1827,11 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection,
if err := sS.attrS.Call(utils.AttributeSv1ProcessEvent,
attrArgs, &rplyEv); err == nil {
args.CGREvent = *rplyEv.CGREvent
if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has {
// special case when we want to overwrite the tenant
args.CGREvent.Tenant = tntIface.(string)
delete(args.CGREvent.Event, utils.MetaTenant)
}
rply.Attributes = &rplyEv
} else if err.Error() != utils.ErrNotFound.Error() {
return utils.NewErrAttributeS(err)
@@ -2022,6 +2032,11 @@ func (sS *SessionS) BiRPCv1UpdateSession(clnt rpcclient.RpcClientConnection,
if err := sS.attrS.Call(utils.AttributeSv1ProcessEvent,
attrArgs, &rplyEv); err == nil {
args.CGREvent = *rplyEv.CGREvent
if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has {
// special case when we want to overwrite the tenant
args.CGREvent.Tenant = tntIface.(string)
delete(args.CGREvent.Event, utils.MetaTenant)
}
rply.Attributes = &rplyEv
} else if err.Error() != utils.ErrNotFound.Error() {
return utils.NewErrAttributeS(err)
@@ -2292,6 +2307,11 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.RpcClientConnection,
if err := sS.attrS.Call(utils.AttributeSv1ProcessEvent,
attrArgs, &rplyEv); err == nil {
args.CGREvent = *rplyEv.CGREvent
if tntIface, has := args.CGREvent.Event[utils.MetaTenant]; has {
// special case when we want to overwrite the tenant
args.CGREvent.Tenant = tntIface.(string)
delete(args.CGREvent.Event, utils.MetaTenant)
}
rply.Attributes = &rplyEv
} else if err.Error() != utils.ErrNotFound.Error() {
return utils.NewErrAttributeS(err)

View File

@@ -22,6 +22,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"
"time"
)
@@ -161,3 +162,12 @@ func (ev *CGREvent) Clone() (clned *CGREvent) {
}
return
}
// RemFldsWithPrefix will remove fields starting with prefix from event
func (ev *CGREvent) RemFldsWithPrefix(prfx string) {
for fldName := range ev.Event {
if strings.HasPrefix(fldName, prfx) {
delete(ev.Event, fldName)
}
}
}

View File

@@ -550,6 +550,7 @@ const (
CGRDebitInterval = "CGRDebitInterval"
MetaAsr = "*asr"
Version = "Version"
MetaTenant = "*tenant"
)
// Migrator Action