diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go index a27bd8eb3..6964d709e 100644 --- a/apier/v1/resourcesv1.go +++ b/apier/v1/resourcesv1.go @@ -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 diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index dcd1cf59e..4762987ef 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -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{ diff --git a/engine/resources.go b/engine/resources.go index a95d01303..b0f33d416 100755 --- a/engine/resources.go +++ b/engine/resources.go @@ -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 }