From 57c1c418d6495f614cc6fa0206558e76a5385523 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Mon, 9 May 2022 23:45:38 +0200 Subject: [PATCH 1/2] docs(authn): use a string alias for user_id_type --- apps/emqx_authn/i18n/emqx_authn_mnesia_i18n.conf | 12 ++++++------ .../src/simple_authn/emqx_authn_mnesia.erl | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/emqx_authn/i18n/emqx_authn_mnesia_i18n.conf b/apps/emqx_authn/i18n/emqx_authn_mnesia_i18n.conf index 5287bf3ef..0d07217d9 100644 --- a/apps/emqx_authn/i18n/emqx_authn_mnesia_i18n.conf +++ b/apps/emqx_authn/i18n/emqx_authn_mnesia_i18n.conf @@ -1,20 +1,20 @@ emqx_authn_mnesia { authentication { desc { - en: """Configuration of authenticator using built-in database as authentication data source.""" + en: """Configuration of authenticator using built-in database as data source.""" zh: """使用内置数据库作为认证数据源的认证器的配置项。""" } } user_id_type { desc { - en: """Specify whether to use ClientID or Username as User ID for authentication.""" - zh: """指定使用 ClientID 还是 Username 作为 User ID 进行认证。""" + en: """Specify whether to use `clientid` or `username` for authentication.""" + zh: """指定使用客户端ID `clientid` 还是用户名 `username` 进行认证。""" } - + label: { - en: """User ID Type""" - zh: """用户 ID 类型""" + en: """Authentication ID Type""" + zh: """认证 ID 类型""" } } diff --git a/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl b/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl index 88a7aca77..3451709f0 100644 --- a/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl +++ b/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl @@ -115,7 +115,7 @@ desc(?CONF_NS) -> desc(_) -> undefined. -user_id_type(type) -> user_id_type(); +user_id_type(type) -> typerefl:alias("string", user_id_type()); user_id_type(desc) -> ?DESC(?FUNCTION_NAME); user_id_type(default) -> <<"username">>; user_id_type(required) -> true; From 60ca1cb2a5aee00ca9db279661620149566e8eb0 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 11 May 2022 09:02:55 +0200 Subject: [PATCH 2/2] refactor(authn): use hocon enum type for user_id_type --- apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl | 5 +---- apps/emqx_dashboard/src/emqx_dashboard_swagger.erl | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl b/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl index 3451709f0..8af4cdd8c 100644 --- a/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl +++ b/apps/emqx_authn/src/simple_authn/emqx_authn_mnesia.erl @@ -53,7 +53,6 @@ group_match_spec/1 ]). --type user_id_type() :: clientid | username. -type user_group() :: binary(). -type user_id() :: binary(). @@ -64,8 +63,6 @@ is_superuser :: boolean() }). --reflect_type([user_id_type/0]). - -export([mnesia/1]). -boot_mnesia({mnesia, [boot]}). @@ -115,7 +112,7 @@ desc(?CONF_NS) -> desc(_) -> undefined. -user_id_type(type) -> typerefl:alias("string", user_id_type()); +user_id_type(type) -> hoconsc:enum([clientid, username]); user_id_type(desc) -> ?DESC(?FUNCTION_NAME); user_id_type(default) -> <<"username">>; user_id_type(required) -> true; diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index db468726b..4e4ebed57 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -580,9 +580,6 @@ hocon_schema_to_spec(?UNION(Types), LocalModule) -> hocon_schema_to_spec(Atom, _LocalModule) when is_atom(Atom) -> {#{type => string, enum => [Atom]}, []}. -%% todo: Find a way to fetch enum value from user_id_type(). -typename_to_spec("user_id_type()", _Mod) -> - #{type => string, enum => [clientid, username]}; typename_to_spec("term()", _Mod) -> #{type => string, example => <<"any">>}; typename_to_spec("boolean()", _Mod) ->