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