diff --git a/apps/emqx_authn/src/emqx_authn_api.erl b/apps/emqx_authn/src/emqx_authn_api.erl index de3e0b5d3..74b1990fa 100644 --- a/apps/emqx_authn/src/emqx_authn_api.erl +++ b/apps/emqx_authn/src/emqx_authn_api.erl @@ -74,6 +74,8 @@ , serialize_error/1 ]). +-elvis([{elvis_style, god_modules, disable}]). + api_spec() -> emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). diff --git a/apps/emqx_gateway/src/emqx_gateway_api_authn.erl b/apps/emqx_gateway/src/emqx_gateway_api_authn.erl index e529bf2ae..f5b6b3dff 100644 --- a/apps/emqx_gateway/src/emqx_gateway_api_authn.erl +++ b/apps/emqx_gateway/src/emqx_gateway_api_authn.erl @@ -173,7 +173,7 @@ schema("/gateway/:name/authentication") -> put => #{ description => <<"Update authentication for the gateway">> , parameters => params_gateway_name_in_path() - , requestBody => schema_authn() + , 'requestBody' => schema_authn() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -185,7 +185,7 @@ schema("/gateway/:name/authentication") -> post => #{ description => <<"Add authentication for the gateway">> , parameters => params_gateway_name_in_path() - , requestBody => schema_authn() + , 'requestBody' => schema_authn() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -289,7 +289,7 @@ schema("/gateway/:name/authentication/import_users") -> , post => #{ description => <<"Import users into the gateway authentication">> , parameters => params_gateway_name_in_path() - , requestBody => emqx_dashboard_swagger:schema_with_examples( + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( ref(emqx_authn_api, request_import_users), emqx_authn_api:request_import_users_examples() ) diff --git a/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl b/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl index 25bfc5b5c..db3d3d96c 100644 --- a/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl +++ b/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl @@ -179,7 +179,7 @@ schema("/gateway/:name/listeners") -> post => #{ description => <<"Create the gateway listener">> , parameters => params_gateway_name_in_path() - , requestBody => emqx_dashboard_swagger:schema_with_examples( + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( ref(listener), examples_listener()) , responses => @@ -223,7 +223,7 @@ schema("/gateway/:name/listeners/:id") -> #{ description => <<"Update the gateway listener">> , parameters => params_gateway_name_in_path() ++ params_listener_id_in_path() - , requestBody => emqx_dashboard_swagger:schema_with_examples( + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( ref(listener), examples_listener()) , responses => @@ -254,7 +254,7 @@ schema("/gateway/:name/listeners/:id/authentication") -> #{ description => <<"Add authentication for the listener">> , parameters => params_gateway_name_in_path() ++ params_listener_id_in_path() - , requestBody => schema_authn() + , 'requestBody' => schema_authn() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -267,7 +267,7 @@ schema("/gateway/:name/listeners/:id/authentication") -> #{ description => <<"Update authentication for the listener">> , parameters => params_gateway_name_in_path() ++ params_listener_id_in_path() - , requestBody => schema_authn() + , 'requestBody' => schema_authn() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -387,7 +387,7 @@ fields(dtls_listener_opts) -> lists_key_without([], _N, L) -> L; -lists_key_without([K|Ks], N, L) -> +lists_key_without([K | Ks], N, L) -> lists_key_without(Ks, N, lists:keydelete(K, N, L)). common_listener_opts() -> diff --git a/apps/emqx_gateway/src/emqx_gateway_http.erl b/apps/emqx_gateway/src/emqx_gateway_http.erl index 41923a66e..52fba3c70 100644 --- a/apps/emqx_gateway/src/emqx_gateway_http.erl +++ b/apps/emqx_gateway/src/emqx_gateway_http.erl @@ -70,6 +70,10 @@ , listeners => [] }. +-elvis([{elvis_style, god_modules, disable}]). +-elvis([{elvis_style, no_nested_try_catch, disable}]). + + -define(DEFAULT_CALL_TIMEOUT, 15000). %%-------------------------------------------------------------------- @@ -371,7 +375,7 @@ with_gateway(GwName0, Fun) -> -spec checks(list(), map()) -> ok. checks([], _) -> ok; -checks([K|Ks], Map) -> +checks([K | Ks], Map) -> case maps:is_key(K, Map) of true -> checks(Ks, Map); false -> diff --git a/apps/emqx_gateway/src/emqx_gateway_insta_sup.erl b/apps/emqx_gateway/src/emqx_gateway_insta_sup.erl index 4c0417fa9..efb3f6fe6 100644 --- a/apps/emqx_gateway/src/emqx_gateway_insta_sup.erl +++ b/apps/emqx_gateway/src/emqx_gateway_insta_sup.erl @@ -52,6 +52,8 @@ stopped_at :: integer() | undefined }). +-elvis([{elvis_style, invalid_dynamic_call, disable}]). + %%-------------------------------------------------------------------- %% APIs %%-------------------------------------------------------------------- @@ -237,13 +239,13 @@ init_authn(GwName, Config) -> do_init_authn([], Names) -> Names; -do_init_authn([{_ChainName, _AuthConf = #{enable := false}}|More], Names) -> +do_init_authn([{_ChainName, _AuthConf = #{enable := false}} | More], Names) -> do_init_authn(More, Names); -do_init_authn([{ChainName, AuthConf}|More], Names) when is_map(AuthConf) -> +do_init_authn([{ChainName, AuthConf} | More], Names) when is_map(AuthConf) -> _ = application:ensure_all_started(emqx_authn), do_create_authn_chain(ChainName, AuthConf), - do_init_authn(More, [ChainName|Names]); -do_init_authn([_BadConf|More], Names) -> + do_init_authn(More, [ChainName | Names]); +do_init_authn([_BadConf | More], Names) -> do_init_authn(More, Names). authns(GwName, Config) -> @@ -312,13 +314,13 @@ do_update_one_by_one(NCfg, State = #state{ OAuths = authns(GwName, OCfg), NAuths = authns(GwName, NCfg), - if - Status == stopped, NEnable == true -> + case {Status, NEnable} of + {stopped, true} -> NState = State#state{config = NCfg}, cb_gateway_load(NState); - Status == stopped, NEnable == false -> + {stopped, false} -> {ok, State#state{config = NCfg}}; - Status == running, NEnable == true -> + {running, true} -> NState = case NAuths == OAuths of true -> State; false -> @@ -329,12 +331,12 @@ do_update_one_by_one(NCfg, State = #state{ end, %% XXX: minimum impact update ??? cb_gateway_update(NCfg, NState); - Status == running, NEnable == false -> + {running, false} -> case cb_gateway_unload(State) of {ok, NState} -> {ok, NState#state{config = NCfg}}; {error, Reason} -> {error, Reason} end; - true -> + _ -> throw(nomatch) end. @@ -432,7 +434,7 @@ cb_gateway_update(Config, end. start_child_process([]) -> []; -start_child_process([Indictor|_] = ChildPidOrSpecs) -> +start_child_process([Indictor | _] = ChildPidOrSpecs) -> case erlang:is_pid(Indictor) of true -> ChildPidOrSpecs; diff --git a/apps/emqx_gateway/src/emqx_gateway_utils.erl b/apps/emqx_gateway/src/emqx_gateway_utils.erl index 8c824a1a1..5d17fe6ca 100644 --- a/apps/emqx_gateway/src/emqx_gateway_utils.erl +++ b/apps/emqx_gateway/src/emqx_gateway_utils.erl @@ -66,6 +66,8 @@ -define(DEFAULT_OOM_POLICY, #{max_heap_size => 4194304, message_queue_len => 32000}). +-elvis([{elvis_style, god_modules, disable}]). + -spec childspec(supervisor:worker(), Mod :: atom()) -> supervisor:child_spec(). childspec(Type, Mod) -> @@ -202,7 +204,7 @@ stringfy(T) when is_list(T); is_binary(T) -> stringfy(T) -> iolist_to_binary(io_lib:format("~0p", [T])). --spec parse_address(binary()|list()) -> {list(), integer()}. +-spec parse_address(binary() | list()) -> {list(), integer()}. parse_address(S) when is_binary(S); is_list(S) -> S1 = case is_binary(S) of true -> lists:reverse(binary_to_list(S)); @@ -234,9 +236,9 @@ normalize_config(RawConf) -> [bind, tcp, ssl, udp, dtls] ++ proplists:get_keys(SocketOpts), Confs), Cfg = maps:merge(Cfg0, RemainCfgs), - [{Type, Name, ListenOn, SocketOpts, Cfg}|AccIn2] + [{Type, Name, ListenOn, SocketOpts, Cfg} | AccIn2] end, [], Liss), - [Listeners|AccIn1] + [Listeners | AccIn1] end, [], LisMap)). esockd_opts(Type, Opts0) ->