Skip to content

Commit

Permalink
reduce calls to authenticate/authorize (2600hz#6180)
Browse files Browse the repository at this point in the history
- remove excessive calls when folding the authenticate & authorize
  bindings in crossbar
  • Loading branch information
lazedo authored and jamesaimonetti committed Dec 4, 2019
1 parent 9b517c1 commit de7cf92
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 31 deletions.
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_api_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
%%------------------------------------------------------------------------------
-spec init() -> ok.
init() ->
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.api_auth">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.api_auth">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.api_auth">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.api_auth">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.api_auth">>, ?MODULE, 'validate'),
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_apps_link.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
%%------------------------------------------------------------------------------
-spec init() -> 'ok'.
init() ->
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.apps_link">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.apps_link">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.apps_link">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.apps_link">>, ?MODULE, 'validate'),
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_apps_store.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ init() ->
_ = crossbar_bindings:bind(<<"*.content_types_provided.apps_store">>, ?MODULE, 'content_types_provided'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.apps_store">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.apps_store">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.apps_store">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.apps_store">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.validate.apps_store">>, ?MODULE, 'validate'),
_ = crossbar_bindings:bind(<<"*.execute.put.apps_store">>, ?MODULE, 'put'),
_ = crossbar_bindings:bind(<<"*.execute.post.apps_store">>, ?MODULE, 'post'),
Expand Down
12 changes: 11 additions & 1 deletion applications/crossbar/src/modules/cb_basic_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,22 @@ is_expired(Context, JObj) ->
set_auth_doc(Context, JObj) ->
AuthAccountId = kz_doc:account_id(JObj),
OwnerId = kz_doc:id(JObj),
Setters = [{fun cb_context:set_auth_doc/2, JObj}
Setters = [{fun cb_context:set_auth_doc/2, auth_doc(JObj)}
,{fun cb_context:set_auth_account_id/2, AuthAccountId}
| maybe_add_is_admins(AuthAccountId, OwnerId)
],
cb_context:setters(Context, Setters).

-spec auth_doc(kz_json:object()) -> kz_json:object().
auth_doc(JObj) ->
kz_json:from_list(
[{<<"account_id">>, kz_doc:account_id(JObj)}
,{<<"identity_sig">>, kzd_users:signature_secret(JObj)}
,{<<"iss">>, <<"kazoo">>}
,{<<"method">>, kz_term:to_binary(?MODULE)}
,{<<"owner_id">>, kz_doc:id(JObj)}
]).

-spec maybe_add_is_admins(kz_term:api_ne_binary(), kz_term:api_ne_binary()) -> cb_context:setters().
maybe_add_is_admins(?NE_BINARY = AuthAccountId, ?NE_BINARY = OwnerId) ->
[{fun cb_context:set_is_superduper_admin/2, cb_context:is_superduper_admin(AuthAccountId)}
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_clicktocall.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
init() ->
Bindings = [{<<"*.allowed_methods.clicktocall">>, 'allowed_methods'}
,{<<"*.resource_exists.clicktocall">>, 'resource_exists'}
,{<<"*.authenticate">>, 'authenticate'}
,{<<"*.authorize">>, 'authorize'}
,{<<"*.authenticate.clicktocall">>, 'authenticate'}
,{<<"*.authorize.clicktocall">>, 'authorize'}
,{<<"*.validate.clicktocall">>, 'validate'}
,{<<"*.execute.put.clicktocall">>, 'put'}
,{<<"*.execute.post.clicktocall">>, 'post'}
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_ips.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
%%------------------------------------------------------------------------------
-spec init() -> 'ok'.
init() ->
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.ips">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.ips">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.ips">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.ips">>, ?MODULE, 'validate'),
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_media.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ init() ->
_ = crossbar_bindings:bind(<<"*.content_types_provided.media">>, ?MODULE, 'content_types_provided'),
_ = crossbar_bindings:bind(<<"*.content_types_accepted.media">>, ?MODULE, 'content_types_accepted'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.media">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.media">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.resource_exists.media">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.languages_provided.media">>, ?MODULE, 'languages_provided'),
_ = crossbar_bindings:bind(<<"*.validate.media">>, ?MODULE, 'validate'),
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_notifications.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
-spec init() -> 'ok'.
init() ->
_ = crossbar_bindings:bind(<<"*.allowed_methods.notifications">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.notifications">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.resource_exists.notifications">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.content_types_provided.notifications">>, ?MODULE, 'content_types_provided'),
_ = crossbar_bindings:bind(<<"*.content_types_accepted.notifications">>, ?MODULE, 'content_types_accepted'),
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_presence.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
-spec init() -> ok.
init() ->
Bindings = [{<<"*.allowed_methods.presence">>, 'allowed_methods'}
,{<<"*.authenticate">>, 'authenticate'}
,{<<"*.authorize">>, 'authorize'}
,{<<"*.authenticate.presence">>, 'authenticate'}
,{<<"*.authorize.presence">>, 'authorize'}
,{<<"*.resource_exists.presence">>, 'resource_exists'}
,{<<"*.content_types_provided.presence">>, 'content_types_provided'}
,{<<"*.validate.presence">>, 'validate'}
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_rates.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
-spec init() -> 'ok'.
init() ->
_ = init_db(),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.rates">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.rates">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.rates">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.rates">>, ?MODULE, 'validate'),
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_registrations.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
init() ->
_ = crossbar_bindings:bind(<<"*.allowed_methods.registrations">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.registrations">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.registrations">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.validate.registrations">>, ?MODULE, 'validate'),
_ = crossbar_bindings:bind(<<"*.execute.delete.registrations">>, ?MODULE, 'delete').

Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_resources.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ init() ->
,{<<"*.execute.post.resources">>, 'post'}
,{<<"*.execute.patch.resources">>, 'patch'}
,{<<"*.execute.delete.resources">>, 'delete'}
,{<<"*.authorize">>, 'authorize'}
,{<<"*.authorize.resources">>, 'authorize'}
]).

-spec maybe_start_jobs_listener() -> pid().
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_schemas.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
init() ->
_ = crossbar_bindings:bind(<<"*.allowed_methods.schemas">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.schemas">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.schemas">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.schemas">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.validate.schemas">>, ?MODULE, 'validate'),
ok.

Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_storage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
%%------------------------------------------------------------------------------
-spec init() -> 'ok'.
init() ->
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.storage">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.storage">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.storage">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.storage">>, ?MODULE, 'validate'),
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ init() ->
_ = crossbar_bindings:bind(<<"*.allowed_methods.sup">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.sup">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.sup">>, ?MODULE, 'validate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.sup">>, ?MODULE, 'authorize'),
Ret.

%%------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_tasks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
%%------------------------------------------------------------------------------
-spec init() -> 'ok'.
init() ->
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.tasks">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.tasks">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.tasks">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.tasks">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.content_types_accepted.tasks">>, ?MODULE, 'content_types_accepted'),
Expand Down
2 changes: 1 addition & 1 deletion applications/crossbar/src/modules/cb_token_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
init() ->
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.early_authenticate">>, ?MODULE, 'early_authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authorize.token_auth">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.token_auth">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.token_auth">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.token_auth">>, ?MODULE, 'validate'),
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_user_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
%%------------------------------------------------------------------------------
-spec init() -> ok.
init() ->
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.user_auth">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.user_auth">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.user_auth">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.user_auth">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.user_auth">>, ?MODULE, 'validate'),
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_webhooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ init() ->
_ = kz_datamgr:revise_doc_from_file(?KZ_SCHEMA_DB, ?APP, <<"schemas/webhooks.json">>),
init_master_account_db(),
_ = crossbar_bindings:bind(<<"*.allowed_methods.webhooks">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.webhooks">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.webhooks">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.resource_exists.webhooks">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.webhooks">>, ?MODULE, 'validate'),
_ = crossbar_bindings:bind(<<"*.execute.put.webhooks">>, ?MODULE, 'put'),
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_websockets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
%%------------------------------------------------------------------------------
-spec init() -> 'ok'.
init() ->
_ = crossbar_bindings:bind(<<"*.authenticate">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.authenticate.websockets">>, ?MODULE, 'authenticate'),
_ = crossbar_bindings:bind(<<"*.authorize.websockets">>, ?MODULE, 'authorize'),
_ = crossbar_bindings:bind(<<"*.allowed_methods.websockets">>, ?MODULE, 'allowed_methods'),
_ = crossbar_bindings:bind(<<"*.resource_exists.websockets">>, ?MODULE, 'resource_exists'),
_ = crossbar_bindings:bind(<<"*.validate.websockets">>, ?MODULE, 'validate').
Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/src/modules/cb_whitelabel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
%%------------------------------------------------------------------------------
-spec init() -> 'ok'.
init() ->
Bindings = [{<<"*.authenticate">>, 'authenticate'}
,{<<"*.authorize">>, 'authorize'}
Bindings = [{<<"*.authenticate.whitelabel">>, 'authenticate'}
,{<<"*.authorize.whitelabel">>, 'authorize'}
,{<<"*.content_types_provided.whitelabel">>, 'content_types_provided'}
,{<<"*.content_types_accepted.whitelabel">>, 'content_types_accepted'}
,{<<"*.allowed_methods.whitelabel">>, 'allowed_methods'}
Expand Down

0 comments on commit de7cf92

Please sign in to comment.