fix: elvis warning

This commit is contained in:
Zhongwen Deng 2022-03-04 14:58:43 +08:00
parent 153e1bcb91
commit 6ff2db6180
7 changed files with 53 additions and 25 deletions

View File

@ -260,17 +260,20 @@ call_pre_config_update(#{?MOD := HandlerName}, OldRawConf, UpdateReq, ConfKeyPat
call_pre_config_update(_Handlers, OldRawConf, UpdateReq, _ConfKeyPath) -> call_pre_config_update(_Handlers, OldRawConf, UpdateReq, _ConfKeyPath) ->
merge_to_old_config(UpdateReq, OldRawConf). merge_to_old_config(UpdateReq, OldRawConf).
call_post_config_update(#{?MOD := HandlerName}, OldConf, NewConf, AppEnvs, UpdateReq, Result, ConfKeyPath) -> call_post_config_update(#{?MOD := HandlerName}, OldConf, NewConf,
AppEnvs, UpdateReq, Result, ConfKeyPath) ->
case erlang:function_exported(HandlerName, post_config_update, 5) of case erlang:function_exported(HandlerName, post_config_update, 5) of
true -> true ->
case HandlerName:post_config_update(ConfKeyPath, UpdateReq, NewConf, OldConf, AppEnvs) of case HandlerName:post_config_update(ConfKeyPath, UpdateReq,
NewConf, OldConf, AppEnvs) of
ok -> {ok, Result}; ok -> {ok, Result};
{ok, Result1} -> {ok, Result#{HandlerName => Result1}}; {ok, Result1} -> {ok, Result#{HandlerName => Result1}};
{error, Reason} -> {error, {post_config_update, HandlerName, Reason}} {error, Reason} -> {error, {post_config_update, HandlerName, Reason}}
end; end;
false -> {ok, Result} false -> {ok, Result}
end; end;
call_post_config_update(_Handlers, _OldConf, _NewConf, _AppEnvs, _UpdateReq, Result, _ConfKeyPath) -> call_post_config_update(_Handlers, _OldConf, _NewConf, _AppEnvs,
_UpdateReq, Result, _ConfKeyPath) ->
{ok, Result}. {ok, Result}.
save_configs(ConfKeyPath, AppEnvs, CheckedConf, NewRawConf, OverrideConf, UpdateArgs, Opts) -> save_configs(ConfKeyPath, AppEnvs, CheckedConf, NewRawConf, OverrideConf, UpdateArgs, Opts) ->

View File

@ -61,8 +61,8 @@ deep_find([Key | KeyPath] = Path, Map) when is_map(Map) ->
{ok, SubMap} -> deep_find(KeyPath, SubMap); {ok, SubMap} -> deep_find(KeyPath, SubMap);
error -> {not_found, Path, Map} error -> {not_found, Path, Map}
end; end;
deep_find(_KeyPath, Data) -> deep_find(KeyPath, Data) ->
{not_found, _KeyPath, Data}. {not_found, KeyPath, Data}.
-spec deep_put(config_key_path(), map(), term()) -> map(). -spec deep_put(config_key_path(), map(), term()) -> map().
deep_put([], _Map, Data) -> deep_put([], _Map, Data) ->

View File

@ -21,6 +21,7 @@
-dialyzer(no_contracts). -dialyzer(no_contracts).
-dialyzer(no_unused). -dialyzer(no_unused).
-dialyzer(no_fail_call). -dialyzer(no_fail_call).
-elvis([{elvis_style, invalid_dynamic_call, disable}]).
-include("emqx_authentication.hrl"). -include("emqx_authentication.hrl").
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
@ -382,7 +383,8 @@ after idling for 'Keepalive * backoff * 2'."""
, {"max_inflight", , {"max_inflight",
sc(range(1, 65535), sc(range(1, 65535),
#{ default => 32, #{ default => 32,
desc => "Maximum size of the Inflight Window storing QoS1/2 messages delivered but un-acked." desc => "Maximum size of the Inflight Window storing QoS1/2"
" messages delivered but un-acked."
}) })
} }
, {"retry_interval", , {"retry_interval",
@ -400,7 +402,8 @@ after idling for 'Keepalive * backoff * 2'."""
, {"await_rel_timeout", , {"await_rel_timeout",
sc(duration(), sc(duration(),
#{ default => "300s", #{ default => "300s",
desc => "The QoS2 messages (Client -> Broker) will be dropped if awaiting PUBREL timeout." desc => "The QoS2 messages (Client -> Broker) will be dropped"
" if awaiting PUBREL timeout."
}) })
} }
, {"session_expiry_interval", , {"session_expiry_interval",
@ -1099,7 +1102,8 @@ fields("trace") ->
default => text, default => text,
desc => """ desc => """
Determine the format of the payload format in the trace file.<br> Determine the format of the payload format in the trace file.<br>
`text`: Text-based protocol or plain text protocol. It is recommended when payload is JSON encoded.<br> `text`: Text-based protocol or plain text protocol.
It is recommended when payload is JSON encoded.<br>
`hex`: Binary hexadecimal encode. It is recommended when payload is a custom binary protocol.<br> `hex`: Binary hexadecimal encode. It is recommended when payload is a custom binary protocol.<br>
`hidden`: payload is obfuscated as `******` `hidden`: payload is obfuscated as `******`
""" """

View File

@ -35,7 +35,9 @@
%% Hocon Schema %% Hocon Schema
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
roots() -> [{config, #{type => hoconsc:union([hoconsc:ref(?MODULE, type1), hoconsc:ref(?MODULE, type2)])}}]. roots() -> [{config, #{type => hoconsc:union([
hoconsc:ref(?MODULE, type1),
hoconsc:ref(?MODULE, type2)])}}].
fields(type1) -> fields(type1) ->
[ {mechanism, {enum, ['password-based']}} [ {mechanism, {enum, ['password-based']}}

View File

@ -83,26 +83,33 @@ schema("/authorization/sources") ->
, get => , get =>
#{ description => <<"List all authorization sources">> #{ description => <<"List all authorization sources">>
, responses => , responses =>
#{ 200 => mk( array(hoconsc:union([ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)])) #{ 200 => mk( array(hoconsc:union(
[ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)]))
, #{desc => <<"Authorization source">>}) , #{desc => <<"Authorization source">>})
} }
} }
, post => , post =>
#{ description => <<"Add a new source">> #{ description => <<"Add a new source">>
, 'requestBody' => mk( hoconsc:union([ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)]) , 'requestBody' => mk( hoconsc:union(
[ref(?API_SCHEMA_MODULE, Type)
|| Type <- authz_sources_types(detailed)])
, #{desc => <<"Source config">>}) , #{desc => <<"Source config">>})
, responses => , responses =>
#{ 204 => <<"Authorization source created successfully">> #{ 204 => <<"Authorization source created successfully">>
, 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>) , 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST],
<<"Bad Request">>)
} }
} }
, put => , put =>
#{ description => <<"Update all sources">> #{ description => <<"Update all sources">>
, 'requestBody' => mk( array(hoconsc:union([ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)])) , 'requestBody' => mk( array(hoconsc:union(
[ref(?API_SCHEMA_MODULE, Type)
|| Type <- authz_sources_types(detailed)]))
, #{desc => <<"Sources">>}) , #{desc => <<"Sources">>})
, responses => , responses =>
#{ 204 => <<"Authorization source updated successfully">> #{ 204 => <<"Authorization source updated successfully">>
, 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>) , 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST],
<<"Bad Request">>)
} }
} }
}; };
@ -112,7 +119,9 @@ schema("/authorization/sources/:type") ->
#{ description => <<"Get a authorization source">> #{ description => <<"Get a authorization source">>
, parameters => parameters_field() , parameters => parameters_field()
, responses => , responses =>
#{ 200 => mk( hoconsc:union([ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)]) #{ 200 => mk( hoconsc:union(
[ref(?API_SCHEMA_MODULE, Type)
|| Type <- authz_sources_types(detailed)])
, #{desc => <<"Authorization source">>}) , #{desc => <<"Authorization source">>})
, 404 => emqx_dashboard_swagger:error_codes([?NOT_FOUND], <<"Not Found">>) , 404 => emqx_dashboard_swagger:error_codes([?NOT_FOUND], <<"Not Found">>)
} }
@ -120,7 +129,8 @@ schema("/authorization/sources/:type") ->
, put => , put =>
#{ description => <<"Update source">> #{ description => <<"Update source">>
, parameters => parameters_field() , parameters => parameters_field()
, 'requestBody' => mk( hoconsc:union([ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)])) , 'requestBody' => mk( hoconsc:union([ref(?API_SCHEMA_MODULE, Type)
|| Type <- authz_sources_types(detailed)]))
, responses => , responses =>
#{ 204 => <<"Authorization source updated successfully">> #{ 204 => <<"Authorization source updated successfully">>
, 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>) , 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>)

View File

@ -315,19 +315,22 @@ a crash dump"
sc(emqx_schema:duration(), sc(emqx_schema:duration(),
#{ mapping => "vm_args.-kernel net_ticktime" #{ mapping => "vm_args.-kernel net_ticktime"
, default => "2m" , default => "2m"
, desc => "This is the approximate time an EMQX node may be unresponsive until it is considered down and thereby disconnected." , desc => "This is the approximate time an EMQX node may"
" be unresponsive until it is considered down and thereby disconnected."
})} })}
, {"dist_listen_min", , {"dist_listen_min",
sc(range(1024, 65535), sc(range(1024, 65535),
#{ mapping => "kernel.inet_dist_listen_min" #{ mapping => "kernel.inet_dist_listen_min"
, default => 6369 , default => 6369
, desc => "Lower bound for the port range where EMQX broker listens for peer connections." , desc => "Lower bound for the port range where"
" EMQX broker listens for peer connections."
})} })}
, {"dist_listen_max", , {"dist_listen_max",
sc(range(1024, 65535), sc(range(1024, 65535),
#{ mapping => "kernel.inet_dist_listen_max" #{ mapping => "kernel.inet_dist_listen_max"
, default => 6369 , default => 6369
, desc => "Upper bound for the port range where EMQX broker listens for peer connections." , desc => "Upper bound for the port range "
"where EMQX broker listens for peer connections."
})} })}
, {"backtrace_depth", , {"backtrace_depth",
sc(integer(), sc(integer(),
@ -455,7 +458,8 @@ fields("rpc") ->
#{ mapping => "gen_rpc.port_discovery" #{ mapping => "gen_rpc.port_discovery"
, default => stateless , default => stateless
, desc => "<code>manual</code>: discover ports by <code>tcp_server_port</code>.<br/>" , desc => "<code>manual</code>: discover ports by <code>tcp_server_port</code>.<br/>"
"<code>stateless</code>: discover ports in a stateless manner, using the following algorithm. " "<code>stateless</code>: discover ports in a stateless manner,"
" using the following algorithm. "
"If node name is <code>emqxN@127.0.0.1</code>, where the N is an integer, " "If node name is <code>emqxN@127.0.0.1</code>, where the N is an integer, "
"then the listening port will be 5370 + N." "then the listening port will be 5370 + N."
})} })}
@ -464,7 +468,8 @@ fields("rpc") ->
#{ mapping => "gen_rpc.tcp_server_port" #{ mapping => "gen_rpc.tcp_server_port"
, default => 5369 , default => 5369
, desc => "Listening port used by RPC local service.<br/> " , desc => "Listening port used by RPC local service.<br/> "
"Note that this config only takes effect when rpc.port_discovery is set to manual." "Note that this config only takes effect "
"when rpc.port_discovery is set to manual."
})} })}
, {"ssl_server_port", , {"ssl_server_port",
sc(integer(), sc(integer(),
@ -497,7 +502,8 @@ fields("rpc") ->
sc(file(), sc(file(),
#{ mapping => "gen_rpc.keyfile" #{ mapping => "gen_rpc.keyfile"
, desc => "Path to the private key file for the <code>rpc.certfile</code>.<br/>" , desc => "Path to the private key file for the <code>rpc.certfile</code>.<br/>"
"Note: contents of this file are secret, so it's necessary to set permissions to 600." "Note: contents of this file are secret, so it's necessary to "
"set permissions to 600."
})} })}
, {"cacertfile", , {"cacertfile",
sc(file(), sc(file(),
@ -528,7 +534,8 @@ fields("rpc") ->
sc(emqx_schema:duration_s(), sc(emqx_schema:duration_s(),
#{ mapping => "gen_rpc.socket_keepalive_idle" #{ mapping => "gen_rpc.socket_keepalive_idle"
, default => "7200s" , default => "7200s"
, desc => "How long the connections between the brokers should remain open after the last message is sent." , desc => "How long the connections between the brokers should remain open "
"after the last message is sent."
})} })}
, {"socket_keepalive_interval", , {"socket_keepalive_interval",
sc(emqx_schema:duration_s(), sc(emqx_schema:duration_s(),

View File

@ -91,12 +91,14 @@ init_per_suite(Config) ->
ok = emqx_common_test_helpers:start_apps([emqx_rule_engine, emqx_connector, ok = emqx_common_test_helpers:start_apps([emqx_rule_engine, emqx_connector,
emqx_bridge, emqx_dashboard], fun set_special_configs/1), emqx_bridge, emqx_dashboard], fun set_special_configs/1),
ok = emqx_common_test_helpers:load_config(emqx_connector_schema, <<"connectors: {}">>), ok = emqx_common_test_helpers:load_config(emqx_connector_schema, <<"connectors: {}">>),
ok = emqx_common_test_helpers:load_config(emqx_rule_engine_schema, <<"rule_engine {rules {}}">>), ok = emqx_common_test_helpers:load_config(emqx_rule_engine_schema,
<<"rule_engine {rules {}}">>),
ok = emqx_common_test_helpers:load_config(emqx_bridge_schema, ?BRIDGE_CONF_DEFAULT), ok = emqx_common_test_helpers:load_config(emqx_bridge_schema, ?BRIDGE_CONF_DEFAULT),
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
emqx_common_test_helpers:stop_apps([emqx_rule_engine, emqx_connector, emqx_bridge, emqx_dashboard]), emqx_common_test_helpers:stop_apps([emqx_rule_engine,
emqx_connector, emqx_bridge, emqx_dashboard]),
ok. ok.
set_special_configs(emqx_dashboard) -> set_special_configs(emqx_dashboard) ->