Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ejabberd auth #1593

Merged
merged 4 commits into from
Dec 7, 2017
Merged

Ejabberd auth #1593

merged 4 commits into from
Dec 7, 2017

Conversation

avlindfors
Copy link
Contributor

This PR addresses #

Proposed changes include:

  • describe the functionality changes
  • describe new or updated tests
  • describe changes to the documentation

alexanderlindfors added 2 commits December 1, 2017 17:19
Added get and set_generic_opt functions
Remove calls to ejabberd_config to access auth_opts
Make those calls through functions in ejabberd_auth instead
Copy link
Member

@fenek fenek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim of this refactor is to hide the existence of auth_opts from specific auth backends, so they can access auth options without caring if/where they are nested in some config tuple.

set_generic_opts/3,
get_generic_opt/2,
get_generic_opt/3,
get_jwt_username_key/1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 36-42 are too specific, they shouldn't be provided as API here. 33-35 should be sufficient for ejabberd_auth_* modules. ejabberd_auth shouldn't be aware about specific possible config keys inside auth_opts.

Opt :: atom(),
KVs :: [tuple()]) -> {atomic|aborted, _}.
set_generic_opts(Host, Opt, KVs) ->
OldOpts = ejabberd_config:get_local_option(Opt, Host),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_generic_opts should access auth_opts by default, so the API here should be set_opt(Host, Opt, Val) (including the function name change).

-spec get_generic_opt(Host :: ejabberd:server(),
Opt :: atom(),
Key :: ejabberd:key()) -> undefined | ejabberd:value().
get_generic_opt(Host, Opt) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it that useful to fetch all options? I would rather expect an API like get_opt(Host, Opt) and get_opt(Host, Opt, Default).

AuthOpts = ejabberd_config:get_local_option(auth_opts, Host),
{_, AuthHost} = lists:keyfind(host, 1, AuthOpts),
AuthOpts = ejabberd_auth:get_generic_opt(Host, auth_opts),
AuthHost = ejabberd_auth:get_host(Host),
PoolSize = proplists:get_value(connection_pool_size, AuthOpts, 10),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be fetched with accessors from ejabberd_auth as well.

The API functions made less specific and should prevent
backend modules any knowledge of the auth_opts config tuples
Copy link
Member

@fenek fenek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I found only one line that could look nicer. :)

src/scram.erl Outdated
false;
AuthOpts ->
{password_format, scram} == lists:keyfind(password_format, 1, AuthOpts)
case ejabberd_auth:get_opt(Host, password_format) of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ejabberd_auth:get_opt(Host, password_format) == scram looks even better. :)

Change from case construct to comparison
@fenek fenek merged commit 63635cc into master Dec 7, 2017
@fenek fenek deleted the ejabberd-auth branch December 7, 2017 23:19
@fenek fenek added this to the 2.1.1 milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants