Resources.AllowUsage return reply message

This commit is contained in:
TeoV
2018-01-08 13:39:01 +02:00
committed by Dan Christian Bogos
parent e5f7287501
commit 9fce5d8808
3 changed files with 14 additions and 15 deletions

View File

@@ -44,8 +44,8 @@ func (rsv1 *ResourceSv1) GetResourcesForEvent(args utils.ArgRSv1ResourceUsage, r
}
// AuthorizeResources checks if there are limits imposed for event
func (rsv1 *ResourceSv1) AuthorizeResources(args utils.ArgRSv1ResourceUsage, allowed *bool) error {
return rsv1.rls.V1AuthorizeResources(args, allowed)
func (rsv1 *ResourceSv1) AuthorizeResources(args utils.ArgRSv1ResourceUsage, reply *string) error {
return rsv1.rls.V1AuthorizeResources(args, reply)
}
// V1InitiateResourceUsage records usage for an event

View File

@@ -357,7 +357,7 @@ func testV1RsAllocateResource(t *testing.T) {
}
func testV1RsAuthorizeResources(t *testing.T) {
var authorized bool
var reply string
argsRU := utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
CGREvent: utils.CGREvent{
@@ -369,10 +369,10 @@ func testV1RsAuthorizeResources(t *testing.T) {
},
Units: 6,
}
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, argsRU, &authorized); err != nil {
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, argsRU, &reply); err != nil {
t.Error(err)
} else if !authorized { // already 3 usages active before allow call, we should have now more than allowed
t.Error("resource is not authorized")
} else if reply != utils.OK { // already 3 usages active before allow call, we should have now more than allowed
t.Error("Unexpected reply returned", reply)
}
argsRU = utils.ArgRSv1ResourceUsage{
UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
@@ -386,10 +386,10 @@ func testV1RsAuthorizeResources(t *testing.T) {
Units: 7,
}
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, argsRU, &authorized); err != nil {
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, argsRU, &reply); err != nil {
t.Error(err)
} else if authorized { // already 3 usages active before allow call, we should have now more than allowed
t.Error("resource should not be allowed")
} else if reply != "" { // already 3 usages active before allow call, we should have now more than allowed
t.Error("Unexpected reply returned", reply)
}
}
@@ -422,11 +422,10 @@ func testV1RsReleaseResource(t *testing.T) {
},
Units: 7,
}
var allowed bool
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, argsRU, &allowed); err != nil {
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, argsRU, &reply); err != nil {
t.Error(err)
} else if !allowed {
t.Error("resource should be allowed")
} else if reply != utils.OK {
t.Error("Unexpected reply returned", reply)
}
var rs *engine.Resources
args := &utils.ArgRSv1ResourceUsage{

View File

@@ -531,7 +531,7 @@ func (rS *ResourceService) V1ResourcesForEvent(args utils.ArgRSv1ResourceUsage,
}
// V1AuthorizeResources queries service to find if an Usage is allowed
func (rS *ResourceService) V1AuthorizeResources(args utils.ArgRSv1ResourceUsage, allow *bool) (err error) {
func (rS *ResourceService) V1AuthorizeResources(args utils.ArgRSv1ResourceUsage, reply *string) (err error) {
if missing := utils.MissingStructFields(&args, []string{"CGREvent.Tenant", "UsageID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
@@ -554,7 +554,7 @@ func (rS *ResourceService) V1AuthorizeResources(args utils.ArgRSv1ResourceUsage,
}
return err
}
*allow = true
*reply = utils.OK
return
}