style(api): proplists imports removed
This commit is contained in:
parent
ea384ec6b5
commit
796c071af5
|
@ -22,8 +22,6 @@
|
|||
-include_lib("emqx/include/emqx.hrl").
|
||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
|
||||
-import(proplists, [get_value/2]).
|
||||
|
||||
%% Nodes and Brokers API
|
||||
-export([ list_nodes/0
|
||||
, lookup_node/1
|
||||
|
@ -135,11 +133,11 @@ node_info(Node) when Node =:= node() ->
|
|||
BrokerInfo = emqx_sys:info(),
|
||||
Info#{node => node(),
|
||||
otp_release => iolist_to_binary(otp_rel()),
|
||||
memory_total => get_value(allocated, Memory),
|
||||
memory_used => get_value(used, Memory),
|
||||
memory_total => proplists:get_value(allocated, Memory),
|
||||
memory_used => proplists:get_value(used, Memory),
|
||||
process_available => erlang:system_info(process_limit),
|
||||
process_used => erlang:system_info(process_count),
|
||||
max_fds => get_value(max_fds, lists:usort(lists:flatten(erlang:system_info(check_io)))),
|
||||
max_fds => proplists:get_value(max_fds, lists:usort(lists:flatten(erlang:system_info(check_io)))),
|
||||
connections => ets:info(emqx_channel, size),
|
||||
node_status => 'Running',
|
||||
uptime => iolist_to_binary(proplists:get_value(uptime, BrokerInfo)),
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
-include("emqx_mgmt.hrl").
|
||||
|
||||
-import(proplists, [get_value/2]).
|
||||
|
||||
-rest_api(#{name => add_app,
|
||||
method => 'POST',
|
||||
path => "/apps/",
|
||||
|
@ -58,12 +56,12 @@
|
|||
]).
|
||||
|
||||
add_app(_Bindings, Params) ->
|
||||
AppId = get_value(<<"app_id">>, Params),
|
||||
Name = get_value(<<"name">>, Params),
|
||||
Secret = get_value(<<"secret">>, Params),
|
||||
Desc = get_value(<<"desc">>, Params),
|
||||
Status = get_value(<<"status">>, Params),
|
||||
Expired = get_value(<<"expired">>, Params),
|
||||
AppId = proplists:get_value(<<"app_id">>, Params),
|
||||
Name = proplists:get_value(<<"name">>, Params),
|
||||
Secret = proplists:get_value(<<"secret">>, Params),
|
||||
Desc = proplists:get_value(<<"desc">>, Params),
|
||||
Status = proplists:get_value(<<"status">>, Params),
|
||||
Expired = proplists:get_value(<<"expired">>, Params),
|
||||
case emqx_mgmt_auth:add_app(AppId, Name, Secret, Desc, Status, Expired) of
|
||||
{ok, AppSecret} -> minirest:return({ok, #{secret => AppSecret}});
|
||||
{error, Reason} -> minirest:return({error, Reason})
|
||||
|
@ -92,10 +90,10 @@ lookup_app(#{appid := AppId}, _Params) ->
|
|||
end.
|
||||
|
||||
update_app(#{appid := AppId}, Params) ->
|
||||
Name = get_value(<<"name">>, Params),
|
||||
Desc = get_value(<<"desc">>, Params),
|
||||
Status = get_value(<<"status">>, Params),
|
||||
Expired = get_value(<<"expired">>, Params),
|
||||
Name = proplists:get_value(<<"name">>, Params),
|
||||
Desc = proplists:get_value(<<"desc">>, Params),
|
||||
Status = proplists:get_value(<<"status">>, Params),
|
||||
Expired = proplists:get_value(<<"expired">>, Params),
|
||||
case emqx_mgmt_auth:update_app(AppId, Name, Desc, Status, Expired) of
|
||||
ok -> minirest:return();
|
||||
{error, Reason} -> minirest:return({error, Reason})
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
-include("emqx_mgmt.hrl").
|
||||
|
||||
-import(proplists, [get_value/2]).
|
||||
|
||||
-rest_api(#{name => list_banned,
|
||||
method => 'GET',
|
||||
path => "/banned/",
|
||||
|
@ -65,7 +63,7 @@ delete(#{as := As, who := Who}, _) ->
|
|||
case pipeline([fun ensure_required/1,
|
||||
fun validate_params/1], Params) of
|
||||
{ok, NParams} ->
|
||||
do_delete(get_value(<<"as">>, NParams), get_value(<<"who">>, NParams)),
|
||||
do_delete(proplists:get_value(<<"as">>, NParams), proplists:get_value(<<"who">>, NParams)),
|
||||
minirest:return();
|
||||
{error, Code, Message} ->
|
||||
minirest:return({error, Code, Message})
|
||||
|
@ -95,7 +93,7 @@ ensure_required(Params) when is_list(Params) ->
|
|||
|
||||
validate_params(Params) ->
|
||||
#{enum_values := AsEnums, message := Msg} = enum_values(as),
|
||||
case lists:member(get_value(<<"as">>, Params), AsEnums) of
|
||||
case lists:member(proplists:get_value(<<"as">>, Params), AsEnums) of
|
||||
true -> {ok, Params};
|
||||
false ->
|
||||
{error, ?ERROR8, Msg}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx/include/emqx.hrl").
|
||||
|
||||
-import(proplists, [get_value/2]).
|
||||
|
||||
-define(CLIENT_QS_SCHEMA, {emqx_channel_info,
|
||||
[{<<"clientid">>, binary},
|
||||
{<<"username">>, binary},
|
||||
|
@ -187,8 +185,8 @@ list_acl_cache(#{clientid := ClientId}, _Params) ->
|
|||
end.
|
||||
|
||||
set_ratelimit_policy(#{clientid := ClientId}, Params) ->
|
||||
P = [{conn_bytes_in, get_value(<<"conn_bytes_in">>, Params)},
|
||||
{conn_messages_in, get_value(<<"conn_messages_in">>, Params)}],
|
||||
P = [{conn_bytes_in, proplists:get_value(<<"conn_bytes_in">>, Params)},
|
||||
{conn_messages_in, proplists:get_value(<<"conn_messages_in">>, Params)}],
|
||||
case [{K, parse_ratelimit_str(V)} || {K, V} <- P, V =/= undefined] of
|
||||
[] -> minirest:return();
|
||||
Policy ->
|
||||
|
@ -207,7 +205,7 @@ clean_ratelimit(#{clientid := ClientId}, _Params) ->
|
|||
end.
|
||||
|
||||
set_quota_policy(#{clientid := ClientId}, Params) ->
|
||||
P = [{conn_messages_routing, get_value(<<"conn_messages_routing">>, Params)}],
|
||||
P = [{conn_messages_routing, proplists:get_value(<<"conn_messages_routing">>, Params)}],
|
||||
case [{K, parse_ratelimit_str(V)} || {K, V} <- P, V =/= undefined] of
|
||||
[] -> minirest:return();
|
||||
Policy ->
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
-include("emqx_mgmt.hrl").
|
||||
|
||||
-import(proplists, [ get_value/2
|
||||
, get_value/3
|
||||
]).
|
||||
|
||||
-rest_api(#{name => mqtt_subscribe,
|
||||
method => 'POST',
|
||||
path => "/mqtt/subscribe",
|
||||
|
@ -78,10 +74,10 @@ publish(_Bindings, Params) ->
|
|||
{ClientId, Topic, Qos, Retain, Payload} = parse_publish_params(Params),
|
||||
case do_publish(ClientId, Topic, Qos, Retain, Payload) of
|
||||
{ok, MsgIds} ->
|
||||
case get_value(<<"return">>, Params, undefined) of
|
||||
case proplists:get_value(<<"return">>, Params, undefined) of
|
||||
undefined -> minirest:return(ok);
|
||||
_Val ->
|
||||
case get_value(<<"topics">>, Params, undefined) of
|
||||
case proplists:get_value(<<"topics">>, Params, undefined) of
|
||||
undefined -> minirest:return({ok, #{msgid => lists:last(MsgIds)}});
|
||||
_ -> minirest:return({ok, #{msgids => MsgIds}})
|
||||
end
|
||||
|
@ -118,7 +114,7 @@ loop_subscribe([Params | ParamsN], Acc) ->
|
|||
{_, Code0, _Reason} -> Code0
|
||||
end,
|
||||
Result = #{clientid => ClientId,
|
||||
topic => resp_topic(get_value(<<"topic">>, Params), get_value(<<"topics">>, Params, <<"">>)),
|
||||
topic => resp_topic(proplists:get_value(<<"topic">>, Params), proplists:get_value(<<"topics">>, Params, <<"">>)),
|
||||
code => Code},
|
||||
loop_subscribe(ParamsN, [Result | Acc]).
|
||||
|
||||
|
@ -132,7 +128,7 @@ loop_publish([Params | ParamsN], Acc) ->
|
|||
{ok, _} -> 0;
|
||||
{_, Code0, _} -> Code0
|
||||
end,
|
||||
Result = #{topic => resp_topic(get_value(<<"topic">>, Params), get_value(<<"topics">>, Params, <<"">>)),
|
||||
Result = #{topic => resp_topic(proplists:get_value(<<"topic">>, Params), proplists:get_value(<<"topics">>, Params, <<"">>)),
|
||||
code => Code},
|
||||
loop_publish(ParamsN, [Result | Acc]).
|
||||
|
||||
|
@ -147,7 +143,7 @@ loop_unsubscribe([Params | ParamsN], Acc) ->
|
|||
{_, Code0, _} -> Code0
|
||||
end,
|
||||
Result = #{clientid => ClientId,
|
||||
topic => resp_topic(get_value(<<"topic">>, Params), get_value(<<"topics">>, Params, <<"">>)),
|
||||
topic => resp_topic(proplists:get_value(<<"topic">>, Params), proplists:get_value(<<"topics">>, Params, <<"">>)),
|
||||
code => Code},
|
||||
loop_unsubscribe(ParamsN, [Result | Acc]).
|
||||
|
||||
|
@ -182,24 +178,24 @@ do_unsubscribe(ClientId, Topic) ->
|
|||
end.
|
||||
|
||||
parse_subscribe_params(Params) ->
|
||||
ClientId = get_value(<<"clientid">>, Params),
|
||||
Topics = topics(filter, get_value(<<"topic">>, Params), get_value(<<"topics">>, Params, <<"">>)),
|
||||
QoS = get_value(<<"qos">>, Params, 0),
|
||||
ClientId = proplists:get_value(<<"clientid">>, Params),
|
||||
Topics = topics(filter, proplists:get_value(<<"topic">>, Params), proplists:get_value(<<"topics">>, Params, <<"">>)),
|
||||
QoS = proplists:get_value(<<"qos">>, Params, 0),
|
||||
{ClientId, Topics, QoS}.
|
||||
|
||||
parse_publish_params(Params) ->
|
||||
Topics = topics(name, get_value(<<"topic">>, Params), get_value(<<"topics">>, Params, <<"">>)),
|
||||
ClientId = get_value(<<"clientid">>, Params),
|
||||
Payload = decode_payload(get_value(<<"payload">>, Params, <<>>),
|
||||
get_value(<<"encoding">>, Params, <<"plain">>)),
|
||||
Qos = get_value(<<"qos">>, Params, 0),
|
||||
Retain = get_value(<<"retain">>, Params, false),
|
||||
Topics = topics(name, proplists:get_value(<<"topic">>, Params), proplists:get_value(<<"topics">>, Params, <<"">>)),
|
||||
ClientId = proplists:get_value(<<"clientid">>, Params),
|
||||
Payload = decode_payload(proplists:get_value(<<"payload">>, Params, <<>>),
|
||||
proplists:get_value(<<"encoding">>, Params, <<"plain">>)),
|
||||
Qos = proplists:get_value(<<"qos">>, Params, 0),
|
||||
Retain = proplists:get_value(<<"retain">>, Params, false),
|
||||
Payload1 = maybe_maps_to_binary(Payload),
|
||||
{ClientId, Topics, Qos, Retain, Payload1}.
|
||||
|
||||
parse_unsubscribe_params(Params) ->
|
||||
ClientId = get_value(<<"clientid">>, Params),
|
||||
Topic = get_value(<<"topic">>, Params),
|
||||
ClientId = proplists:get_value(<<"clientid">>, Params),
|
||||
Topic = proplists:get_value(<<"topic">>, Params),
|
||||
{ClientId, Topic}.
|
||||
|
||||
topics(Type, undefined, Topics0) ->
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
-module(emqx_mgmt_http).
|
||||
|
||||
-import(proplists, [get_value/3]).
|
||||
|
||||
-export([ start_listeners/0
|
||||
, handle_request/2
|
||||
, stop_listeners/0
|
||||
|
@ -58,8 +56,8 @@ start_listener({Proto, Port, Options}) when Proto == https ->
|
|||
minirest:start_https(listener_name(Proto), ranch_opts(Port, Options), Dispatch).
|
||||
|
||||
ranch_opts(Port, Options0) ->
|
||||
NumAcceptors = get_value(num_acceptors, Options0, 4),
|
||||
MaxConnections = get_value(max_connections, Options0, 512),
|
||||
NumAcceptors = proplists:get_value(num_acceptors, Options0, 4),
|
||||
MaxConnections = proplists:get_value(max_connections, Options0, 512),
|
||||
Options = lists:foldl(fun({K, _V}, Acc) when K =:= max_connections orelse K =:= num_acceptors ->
|
||||
Acc;
|
||||
({inet6, true}, Acc) -> [inet6 | Acc];
|
||||
|
|
Loading…
Reference in New Issue