From 9594b6df32687026b31edc56bcf86e19efc40c59 Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Wed, 26 Jun 2024 17:34:16 +0800 Subject: [PATCH] chore: warning overrided when restart authn --- .../src/emqx_authn_mnesia.erl | 20 +++++++++++++++++-- rel/i18n/emqx_authn_mnesia_schema.hocon | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl b/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl index dd4ae4845..028718aa4 100644 --- a/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl +++ b/apps/emqx_auth_mnesia/src/emqx_authn_mnesia.erl @@ -339,8 +339,24 @@ run_fuzzy_filter( %%------------------------------------------------------------------------------ insert_user(UserGroup, UserID, PasswordHash, Salt, IsSuperuser) -> - UserInfoRecord = user_info_record(UserGroup, UserID, PasswordHash, Salt, IsSuperuser), - insert_user(UserInfoRecord). + UserInfoRecord = + #user_info{user_id = DBUserID} = + user_info_record(UserGroup, UserID, PasswordHash, Salt, IsSuperuser), + case mnesia:read(?TAB, DBUserID, write) of + [] -> + insert_user(UserInfoRecord); + [UserInfoRecord] -> + ok; + [_] -> + ?SLOG(warning, #{ + msg => "bootstrap_authentication_overridden_in_the_built_in_database", + user_id => UserID, + group_id => UserGroup, + suggestion => + "If you have made changes in other way, remove the user_id from the bootstrap file." + }), + insert_user(UserInfoRecord) + end. insert_user(#user_info{} = UserInfoRecord) -> mnesia:write(?TAB, UserInfoRecord, write). diff --git a/rel/i18n/emqx_authn_mnesia_schema.hocon b/rel/i18n/emqx_authn_mnesia_schema.hocon index 010d32f61..ad90dbe19 100644 --- a/rel/i18n/emqx_authn_mnesia_schema.hocon +++ b/rel/i18n/emqx_authn_mnesia_schema.hocon @@ -11,14 +11,16 @@ user_id_type.label: bootstrap_file.desc: """The bootstrap file imports users into the built-in database. -the file content format is determined by `bootstrap_type`.""" +The file content format is determined by `bootstrap_type`. +Remove the item from the bootstrap file when you have made changes in other way, +otherwise, after restarting, the bootstrap item will be overridden again.""" bootstrap_file.label: """Bootstrap File Path""" bootstrap_type.desc: -"""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}.` +"""`plain`: bootstrap_file.csv 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.csv 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.""" }