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