Skip to content

Commit

Permalink
improve the logging when auth_account_id is not set, most likely beca…
Browse files Browse the repository at this point in the history
…use token_auth is not loaded (#2679)
  • Loading branch information
mark2600 authored and lazedo committed Oct 7, 2016
1 parent 28f575a commit 0ae2001
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions applications/blackhole/src/modules/bh_authz_subscribe.erl
Expand Up @@ -34,7 +34,16 @@ authorize_account(Context, #{account_id := <<"*">>}) ->
'false' -> bh_context:add_error(Context, <<"unauthorized wildcard account id">>)
end;
authorize_account(Context, #{account_id := AccountId}) ->
case kz_util:is_in_account_hierarchy(bh_context:auth_account_id(Context), AccountId, 'true') of
'true' -> Context;
AuthAccount = bh_context:auth_account_id(Context),
maybe_authorize_account(Context, AuthAccount, AccountId).

-spec maybe_authorize_account(bh_context:context(), binary(), binary()) -> bh_context:context().
maybe_authorize_account(Context, 'undefined', _AccountId) ->
lager:warning("auth_account_id is not set, maybe you need to start bh_token_auth ?"),
bh_context:add_error(Context, <<"auth_account_id not set">>);

maybe_authorize_account(Context, AuthAccountId, AccountId) ->
case kz_util:is_in_account_hierarchy(AuthAccountId, AccountId, 'true') of
'true' -> Context;
'false' -> bh_context:add_error(Context, <<"unauthorized account id">>)
end.

0 comments on commit 0ae2001

Please sign in to comment.