From 0ae200107b5cc48c0c18b17c66beeb4e48b8b375 Mon Sep 17 00:00:00 2001 From: Mark Magnusson Date: Fri, 7 Oct 2016 19:30:07 -0400 Subject: [PATCH] improve the logging when auth_account_id is not set, most likely because token_auth is not loaded (#2679) --- .../blackhole/src/modules/bh_authz_subscribe.erl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/applications/blackhole/src/modules/bh_authz_subscribe.erl b/applications/blackhole/src/modules/bh_authz_subscribe.erl index 1d98ad33620..4f2f85898b1 100644 --- a/applications/blackhole/src/modules/bh_authz_subscribe.erl +++ b/applications/blackhole/src/modules/bh_authz_subscribe.erl @@ -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.