From 24d2534641e345708d9866250370bf0d30069241 Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Wed, 26 Jun 2024 16:55:32 +0800 Subject: [PATCH] chore: apply review suggestion --- apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl | 7 ++++--- changes/ce/feat-13336.en.md | 2 +- rel/i18n/emqx_authn_mnesia_schema.hocon | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl b/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl index 85230537f..dd4ae4845 100644 --- a/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl +++ b/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl @@ -543,8 +543,9 @@ boostrap_user_from_file(Config, State) -> case maps:get(boostrap_file, Config, <<>>) of <<>> -> ok; - FileName -> + FileName0 -> #{boostrap_type := Type} = Config, + FileName = emqx_schema:naive_env_interpolation(FileName0), case file:read_file(FileName) of {ok, FileData} -> %% if there is a key conflict, override with the key which from the bootstrap file @@ -552,10 +553,10 @@ boostrap_user_from_file(Config, State) -> ok; {error, Reason} -> ?SLOG(warning, #{ - msg => "boostrap_authn(built_in_database)_failed", + msg => "boostrap_authn_built_in_database_failed", boostrap_file => FileName, boostrap_type => Type, - reason => Reason + reason => emqx_utils:explain_posix(Reason) }) end end. diff --git a/changes/ce/feat-13336.en.md b/changes/ce/feat-13336.en.md index 85223311c..ff09f624b 100644 --- a/changes/ce/feat-13336.en.md +++ b/changes/ce/feat-13336.en.md @@ -1 +1 @@ -Added support for configuring the bootstrap_file and bootstrap_type when using the built-in db authentication method. +Added new configs `bootstrap_file` and `bootstrap_type` for built-in database for authentication to support bootstrapping the table with csv and json file. diff --git a/rel/i18n/emqx_authn_mnesia_schema.hocon b/rel/i18n/emqx_authn_mnesia_schema.hocon index e32f1f772..010d32f61 100644 --- a/rel/i18n/emqx_authn_mnesia_schema.hocon +++ b/rel/i18n/emqx_authn_mnesia_schema.hocon @@ -10,13 +10,15 @@ user_id_type.label: """Authentication ID Type""" bootstrap_file.desc: -"""The bootstrap file imports users into the built-in database.""" +"""The bootstrap file imports users into the built-in database. +the file content format is determined by `bootstrap_type`.""" bootstrap_file.label: """Bootstrap File Path""" bootstrap_type.desc: -"""plain: bootstrap_file.cvs should be `user_id,password,is_superuser`. -hash: bootstrap_file.cvs should be `user_id,password_hash,salt,is_superuser`""" +"""plain: bootstrap_file.cvs should have lines of format `{user_id},{password},{is_superuser}` where `user_id` can be either clientid or username depending on `user_id_type`. +hash: bootstrap_file.cvs should have line of format `{user_id},{password_hash},{salt},{is_superuser}.` +All file format support is the same as `authentication/password_based:built_in_database/import_users` API.""" }