Przeglądaj źródła

fix(authn): add the case when the instance does not exist

zhouzb 4 lat temu
rodzic
commit
5aa8ba45d3
1 zmienionych plików z 10 dodań i 4 usunięć
  1. 10 4
      apps/emqx/src/emqx_authentication_config.erl

+ 10 - 4
apps/emqx/src/emqx_authentication_config.erl

@@ -121,8 +121,12 @@ do_post_config_update({delete_authenticator, ChainName, AuthenticatorID}, _NewCo
             {error, Reason}
             {error, Reason}
     end;
     end;
 do_post_config_update({update_authenticator, ChainName, AuthenticatorID, Config}, NewConfig, _OldConfig, _AppEnvs) ->
 do_post_config_update({update_authenticator, ChainName, AuthenticatorID, Config}, NewConfig, _OldConfig, _AppEnvs) ->
-    NConfig = get_authenticator_config(authenticator_id(Config), NewConfig),
-    emqx_authentication:update_authenticator(ChainName, AuthenticatorID, NConfig);
+    case get_authenticator_config(authenticator_id(Config), NewConfig) of
+        {error, not_found} ->
+            {error, {not_found, {authenticator, AuthenticatorID}}};
+        NConfig ->
+            emqx_authentication:update_authenticator(ChainName, AuthenticatorID, NConfig)
+    end;
 do_post_config_update({move_authenticator, ChainName, AuthenticatorID, Position}, _NewConfig, _OldConfig, _AppEnvs) ->
 do_post_config_update({move_authenticator, ChainName, AuthenticatorID, Position}, _NewConfig, _OldConfig, _AppEnvs) ->
     emqx_authentication:move_authenticator(ChainName, AuthenticatorID, Position).
     emqx_authentication:move_authenticator(ChainName, AuthenticatorID, Position).
 
 
@@ -205,8 +209,10 @@ clear_certs(CertsDir, Config) ->
     ok = emqx_tls_lib:delete_ssl_files(CertsDir, undefined, OldSSL).
     ok = emqx_tls_lib:delete_ssl_files(CertsDir, undefined, OldSSL).
 
 
 get_authenticator_config(AuthenticatorID, AuthenticatorsConfig) ->
 get_authenticator_config(AuthenticatorID, AuthenticatorsConfig) ->
-    [C] = [C0 || C0 <- AuthenticatorsConfig, AuthenticatorID == authenticator_id(C0)],
-    C.
+    case [C0 || C0 <- AuthenticatorsConfig, AuthenticatorID == authenticator_id(C0)] of
+        [C | _] -> C;
+        [] -> {error, not_found}
+    end.
 
 
 split_by_id(ID, AuthenticatorsConfig) ->
 split_by_id(ID, AuthenticatorsConfig) ->
     case lists:foldl(
     case lists:foldl(