ソースを参照

chore: warning overrided when restart authn

zhongwencool 1 年間 前
コミット
9594b6df32

+ 18 - 2
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).

+ 5 - 3
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."""
 
 }