-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(emqx_auth): implement API to re-order all authenticators/authz sources #12509
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
feat(emqx_auth): implement API to re-order all authenticators/authz sources #12509
Conversation
bc60f2d
to
fbed936
Compare
API:
|
fbed936
to
7c4abb6
Compare
{NewSources, NotFoundTypes, RemOldSources} = | ||
lists:foldr( | ||
fun(Type, {NewSourcesAcc, NotFoundTypesAcc, RemOldSourcesAcc}) -> | ||
case lists:keytake(Type, 1, RemOldSourcesAcc) of | ||
{value, {_Type, Source}, RemOldSourcesAcc1} -> | ||
{[Source | NewSourcesAcc], NotFoundTypesAcc, RemOldSourcesAcc1}; | ||
false -> | ||
{NewSourcesAcc, [Type | NotFoundTypesAcc], RemOldSourcesAcc} | ||
end | ||
end, | ||
{[], [], OldSourcesWithTypes}, | ||
NewSourcesOrder1 | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: impl a loop function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -1253,6 +1292,19 @@ serialize_error({unknown_authn_type, Type}) -> | |||
code => <<"BAD_REQUEST">>, | |||
message => binfmt("Unknown type '~p'", [Type]) | |||
}}; | |||
serialize_error(#{not_found := NotFound, not_reordered := NotReordered}) -> | |||
NotFoundFmt = "Authenticators: ~p are not found", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it produce [<<"redis">>, <<"mysql">>]
?
if yes, maybe better to use [~ts]
for a lists:join(",", NotFound)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -582,6 +582,121 @@ t_source_move(_) -> | |||
|
|||
ok. | |||
|
|||
t_sources_reorder(_) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for regression purpose, maybe add a disabled source (the enable/disable state should not affect ordering).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done for both authz and authn.
authorization_sources_order_put.desc: | ||
"""Reorder all authorization sources.""" | ||
authorization_sources_order_put.label: | ||
"""Reorder authorization sources""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Reorder authorization sources""" | |
"""Reorder Authorization Sources""" |
rel/i18n/emqx_authn_api.hocon
Outdated
authentication_order_put.desc: | ||
"""Reorder all authenticators in global authentication chain.""" | ||
authentication_order_put.label: | ||
"""Reorder authenticators""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Reorder authenticators""" | |
"""Reorder Authenticators""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
do_pre_config_update(_ConfPath, {reorder_authenticators, NewOrder}, OldConfig) -> | ||
OldConfigWithIds = [{authenticator_id(Auth), Auth} || Auth <- OldConfig], | ||
{NewConfig, NotFoundIds, RemOldConfig} = | ||
lists:foldr( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: implement a loop function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Is this based on what's returned in the GET APIs ? |
I was asking if the |
…ources Fixes: EMQX-11770
7c4abb6
to
7272ef2
Compare
Fixes EMQX-11770
Release version:
v/e5.6.0
Summary
PR Checklist
Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:
changes/(ce|ee)/(feat|perf|fix|breaking)-<PR-id>.en.md
filesChecklist for CI (.github/workflows) changes
changes/
dir for user-facing artifacts update