fix(authn-authz-api): fix authn/authz test cases fail

This commit is contained in:
Turtle 2021-08-24 17:35:38 +08:00 committed by turtleDeng
parent e0c05242a7
commit bc325e55fc
10 changed files with 65 additions and 83 deletions

View File

@ -21,13 +21,13 @@
-include("emqx_authn.hrl"). -include("emqx_authn.hrl").
-export([ api_spec/0 -export([ api_spec/0
, authentication/3 , authentication/2
, authenticators/3 , authenticators/2
, authenticators2/3 , authenticators2/2
, move/3 , move/2
, import_users/3 , import_users/2
, users/3 , users/2
, users2/3 , users2/2
]). ]).
-define(EXAMPLE_1, #{name => <<"example 1">>, -define(EXAMPLE_1, #{name => <<"example 1">>,
@ -1289,22 +1289,19 @@ definitions() ->
, #{<<"error">> => ErrorDef} , #{<<"error">> => ErrorDef}
]. ].
authentication(post, _Params, Request) -> authentication(post, #{body := Config}) ->
{ok, Body, _} = cowboy_req:read_body(Request), case Config of
case emqx_json:decode(Body, [return_maps]) of
#{<<"enable">> := Enable} -> #{<<"enable">> := Enable} ->
{ok, _} = emqx_authn:update_config([authentication, enable], {enable, Enable}), {ok, _} = emqx_authn:update_config([authentication, enable], {enable, Enable}),
{204}; {204};
_ -> _ ->
serialize_error({missing_parameter, enable}) serialize_error({missing_parameter, enable})
end; end;
authentication(get, _Params, _Request) -> authentication(get, _Params) ->
Enabled = emqx_authn:is_enabled(), Enabled = emqx_authn:is_enabled(),
{200, #{enabled => Enabled}}. {200, #{enabled => Enabled}}.
authenticators(post, _Params, Request) -> authenticators(post, #{body := Config}) ->
{ok, Body, _} = cowboy_req:read_body(Request),
Config = emqx_json:decode(Body, [return_maps]),
case emqx_authn:update_config([authentication, authenticators], {create_authenticator, Config}) of case emqx_authn:update_config([authentication, authenticators], {create_authenticator, Config}) of
{ok, #{post_config_update := #{emqx_authn := #{id := ID, name := Name}}, {ok, #{post_config_update := #{emqx_authn := #{id := ID, name := Name}},
raw_config := RawConfig}} -> raw_config := RawConfig}} ->
@ -1313,7 +1310,7 @@ authenticators(post, _Params, Request) ->
{error, {_, _, Reason}} -> {error, {_, _, Reason}} ->
serialize_error(Reason) serialize_error(Reason)
end; end;
authenticators(get, _Params, _Request) -> authenticators(get, _Params) ->
RawConfig = get_raw_config([authentication, authenticators]), RawConfig = get_raw_config([authentication, authenticators]),
{ok, Authenticators} = emqx_authn:list_authenticators(?CHAIN), {ok, Authenticators} = emqx_authn:list_authenticators(?CHAIN),
NAuthenticators = lists:zipwith(fun(#{<<"name">> := Name} = Config, #{id := ID, name := Name}) -> NAuthenticators = lists:zipwith(fun(#{<<"name">> := Name} = Config, #{id := ID, name := Name}) ->
@ -1321,8 +1318,7 @@ authenticators(get, _Params, _Request) ->
end, RawConfig, Authenticators), end, RawConfig, Authenticators),
{200, NAuthenticators}. {200, NAuthenticators}.
authenticators2(get, _Params, Request) -> authenticators2(get, #{bindings := #{id := AuthenticatorID}}) ->
AuthenticatorID = cowboy_req:binding(id, Request),
case emqx_authn:lookup_authenticator(?CHAIN, AuthenticatorID) of case emqx_authn:lookup_authenticator(?CHAIN, AuthenticatorID) of
{ok, #{id := ID, name := Name}} -> {ok, #{id := ID, name := Name}} ->
RawConfig = get_raw_config([authentication, authenticators]), RawConfig = get_raw_config([authentication, authenticators]),
@ -1331,10 +1327,7 @@ authenticators2(get, _Params, Request) ->
{error, Reason} -> {error, Reason} ->
serialize_error(Reason) serialize_error(Reason)
end; end;
authenticators2(put, _Params, Request) -> authenticators2(put, #{bindings := #{id := AuthenticatorID}, body := Config}) ->
AuthenticatorID = cowboy_req:binding(id, Request),
{ok, Body, _} = cowboy_req:read_body(Request),
Config = emqx_json:decode(Body, [return_maps]),
case emqx_authn:update_config([authentication, authenticators], case emqx_authn:update_config([authentication, authenticators],
{update_or_create_authenticator, AuthenticatorID, Config}) of {update_or_create_authenticator, AuthenticatorID, Config}) of
{ok, #{post_config_update := #{emqx_authn := #{id := ID, name := Name}}, {ok, #{post_config_update := #{emqx_authn := #{id := ID, name := Name}},
@ -1344,8 +1337,7 @@ authenticators2(put, _Params, Request) ->
{error, {_, _, Reason}} -> {error, {_, _, Reason}} ->
serialize_error(Reason) serialize_error(Reason)
end; end;
authenticators2(delete, _Params, Request) -> authenticators2(delete, #{bindings := #{id := AuthenticatorID}}) ->
AuthenticatorID = cowboy_req:binding(id, Request),
case emqx_authn:update_config([authentication, authenticators], {delete_authenticator, AuthenticatorID}) of case emqx_authn:update_config([authentication, authenticators], {delete_authenticator, AuthenticatorID}) of
{ok, _} -> {ok, _} ->
{204}; {204};
@ -1353,10 +1345,8 @@ authenticators2(delete, _Params, Request) ->
serialize_error(Reason) serialize_error(Reason)
end. end.
move(post, _Params, Request) -> move(post, #{bindings := #{id := AuthenticatorID}, body := Body}) ->
AuthenticatorID = cowboy_req:binding(id, Request), case Body of
{ok, Body, _} = cowboy_req:read_body(Request),
case emqx_json:decode(Body, [return_maps]) of
#{<<"position">> := Position} -> #{<<"position">> := Position} ->
case emqx_authn:update_config([authentication, authenticators], {move_authenticator, AuthenticatorID, Position}) of case emqx_authn:update_config([authentication, authenticators], {move_authenticator, AuthenticatorID, Position}) of
{ok, _} -> {204}; {ok, _} -> {204};
@ -1366,10 +1356,8 @@ move(post, _Params, Request) ->
serialize_error({missing_parameter, position}) serialize_error({missing_parameter, position})
end. end.
import_users(post, _Params, Request) -> import_users(post, #{bindings := #{id := AuthenticatorID}, body := Body}) ->
AuthenticatorID = cowboy_req:binding(id, Request), case Body of
{ok, Body, _} = cowboy_req:read_body(Request),
case emqx_json:decode(Body, [return_maps]) of
#{<<"filename">> := Filename} -> #{<<"filename">> := Filename} ->
case emqx_authn:import_users(?CHAIN, AuthenticatorID, Filename) of case emqx_authn:import_users(?CHAIN, AuthenticatorID, Filename) of
ok -> {204}; ok -> {204};
@ -1379,12 +1367,9 @@ import_users(post, _Params, Request) ->
serialize_error({missing_parameter, filename}) serialize_error({missing_parameter, filename})
end. end.
users(post, _Params, Request) -> users(post, #{bindings := #{id := AuthenticatorID}, body := UserInfo}) ->
AuthenticatorID = cowboy_req:binding(id, Request), case UserInfo of
{ok, Body, _} = cowboy_req:read_body(Request), #{ <<"user_id">> := UserID, <<"password">> := Password} ->
case emqx_json:decode(Body, [return_maps]) of
#{ <<"user_id">> := UserID
, <<"password">> := Password} = UserInfo ->
Superuser = maps:get(<<"superuser">>, UserInfo, false), Superuser = maps:get(<<"superuser">>, UserInfo, false),
case emqx_authn:add_user(?CHAIN, AuthenticatorID, #{ user_id => UserID case emqx_authn:add_user(?CHAIN, AuthenticatorID, #{ user_id => UserID
, password => Password , password => Password
@ -1399,8 +1384,7 @@ users(post, _Params, Request) ->
_ -> _ ->
serialize_error({missing_parameter, user_id}) serialize_error({missing_parameter, user_id})
end; end;
users(get, _Params, Request) -> users(get, #{bindings := #{id := AuthenticatorID}}) ->
AuthenticatorID = cowboy_req:binding(id, Request),
case emqx_authn:list_users(?CHAIN, AuthenticatorID) of case emqx_authn:list_users(?CHAIN, AuthenticatorID) of
{ok, Users} -> {ok, Users} ->
{200, Users}; {200, Users};
@ -1408,11 +1392,9 @@ users(get, _Params, Request) ->
serialize_error(Reason) serialize_error(Reason)
end. end.
users2(patch, _Params, Request) -> users2(patch, #{bindings := #{id := AuthenticatorID,
AuthenticatorID = cowboy_req:binding(id, Request), user_id := UserID},
UserID = cowboy_req:binding(user_id, Request), body := UserInfo}) ->
{ok, Body, _} = cowboy_req:read_body(Request),
UserInfo = emqx_json:decode(Body, [return_maps]),
NUserInfo = maps:with([<<"password">>, <<"superuser">>], UserInfo), NUserInfo = maps:with([<<"password">>, <<"superuser">>], UserInfo),
case NUserInfo =:= #{} of case NUserInfo =:= #{} of
true -> true ->
@ -1425,18 +1407,14 @@ users2(patch, _Params, Request) ->
serialize_error(Reason) serialize_error(Reason)
end end
end; end;
users2(get, _Params, Request) -> users2(get, #{bindings := #{id := AuthenticatorID, user_id := UserID}}) ->
AuthenticatorID = cowboy_req:binding(id, Request),
UserID = cowboy_req:binding(user_id, Request),
case emqx_authn:lookup_user(?CHAIN, AuthenticatorID, UserID) of case emqx_authn:lookup_user(?CHAIN, AuthenticatorID, UserID) of
{ok, User} -> {ok, User} ->
{200, User}; {200, User};
{error, Reason} -> {error, Reason} ->
serialize_error(Reason) serialize_error(Reason)
end; end;
users2(delete, _Params, Request) -> users2(delete, #{bindings := #{id := AuthenticatorID, user_id := UserID}}) ->
AuthenticatorID = cowboy_req:binding(id, Request),
UserID = cowboy_req:binding(user_id, Request),
case emqx_authn:delete_user(?CHAIN, AuthenticatorID, UserID) of case emqx_authn:delete_user(?CHAIN, AuthenticatorID, UserID) of
ok -> ok ->
{204}; {204};

View File

@ -40,9 +40,9 @@
topics => [<<"#">>]}). topics => [<<"#">>]}).
-export([ api_spec/0 -export([ api_spec/0
, rules/3 , rules/2
, rule/3 , rule/2
, move_rule/3 , move_rule/2
]). ]).
api_spec() -> api_spec() ->
@ -418,7 +418,7 @@ move_rule_api() ->
}, },
{"/authorization/:id/move", Metadata, move_rule}. {"/authorization/:id/move", Metadata, move_rule}.
rules(get, _Params, Request) -> rules(get, #{query_string := Query}) ->
Rules = lists:foldl(fun (#{type := _Type, enable := true, annotations := #{id := Id} = Annotations} = Rule, AccIn) -> Rules = lists:foldl(fun (#{type := _Type, enable := true, annotations := #{id := Id} = Annotations} = Rule, AccIn) ->
NRule = case emqx_resource:health_check(Id) of NRule = case emqx_resource:health_check(Id) of
ok -> ok ->
@ -430,11 +430,10 @@ rules(get, _Params, Request) ->
(Rule, AccIn) -> (Rule, AccIn) ->
lists:append(AccIn, [Rule]) lists:append(AccIn, [Rule])
end, [], emqx_authz:lookup()), end, [], emqx_authz:lookup()),
Query = cowboy_req:parse_qs(Request), case maps:is_key(<<"page">>, Query) andalso maps:is_key(<<"limit">>, Query) of
case lists:keymember(<<"page">>, 1, Query) andalso lists:keymember(<<"limit">>, 1, Query) of
true -> true ->
{<<"page">>, Page} = lists:keyfind(<<"page">>, 1, Query), Page = maps:get(<<"page">>, Query),
{<<"limit">>, Limit} = lists:keyfind(<<"limit">>, 1, Query), Limit = maps:get(<<"limit">>, Query),
Index = (binary_to_integer(Page) - 1) * binary_to_integer(Limit), Index = (binary_to_integer(Page) - 1) * binary_to_integer(Limit),
{_, Rules1} = lists:split(Index, Rules), {_, Rules1} = lists:split(Index, Rules),
case binary_to_integer(Limit) < length(Rules1) of case binary_to_integer(Limit) < length(Rules1) of
@ -445,18 +444,14 @@ rules(get, _Params, Request) ->
end; end;
false -> {200, #{rules => Rules}} false -> {200, #{rules => Rules}}
end; end;
rules(post, _Params, Request) -> rules(post, #{body := RawConfig}) ->
{ok, Body, _} = cowboy_req:read_body(Request),
RawConfig = jsx:decode(Body, [return_maps]),
case emqx_authz:update(head, [RawConfig]) of case emqx_authz:update(head, [RawConfig]) of
{ok, _} -> {204}; {ok, _} -> {204};
{error, Reason} -> {error, Reason} ->
{400, #{code => <<"BAD_REQUEST">>, {400, #{code => <<"BAD_REQUEST">>,
messgae => atom_to_binary(Reason)}} messgae => atom_to_binary(Reason)}}
end; end;
rules(put, _Params, Request) -> rules(put, #{body := RawConfig}) ->
{ok, Body, _} = cowboy_req:read_body(Request),
RawConfig = jsx:decode(Body, [return_maps]),
case emqx_authz:update(replace, RawConfig) of case emqx_authz:update(replace, RawConfig) of
{ok, _} -> {204}; {ok, _} -> {204};
{error, Reason} -> {error, Reason} ->
@ -464,8 +459,7 @@ rules(put, _Params, Request) ->
messgae => atom_to_binary(Reason)}} messgae => atom_to_binary(Reason)}}
end. end.
rule(get, _Params, Request) -> rule(get, #{bindings := #{id := Id}}) ->
Id = cowboy_req:binding(id, Request),
case emqx_authz:lookup(Id) of case emqx_authz:lookup(Id) of
{error, Reason} -> {404, #{messgae => atom_to_binary(Reason)}}; {error, Reason} -> {404, #{messgae => atom_to_binary(Reason)}};
Rule -> Rule ->
@ -481,10 +475,7 @@ rule(get, _Params, Request) ->
end end
end; end;
rule(put, _Params, Request) -> rule(put, #{bindings := #{id := RuleId}, body := RawConfig}) ->
RuleId = cowboy_req:binding(id, Request),
{ok, Body, _} = cowboy_req:read_body(Request),
RawConfig = jsx:decode(Body, [return_maps]),
case emqx_authz:update({replace_once, RuleId}, RawConfig) of case emqx_authz:update({replace_once, RuleId}, RawConfig) of
{ok, _} -> {204}; {ok, _} -> {204};
{error, not_found_rule} -> {error, not_found_rule} ->
@ -494,18 +485,15 @@ rule(put, _Params, Request) ->
{400, #{code => <<"BAD_REQUEST">>, {400, #{code => <<"BAD_REQUEST">>,
messgae => atom_to_binary(Reason)}} messgae => atom_to_binary(Reason)}}
end; end;
rule(delete, _Params, Request) -> rule(delete, #{bindings := #{id := RuleId}}) ->
RuleId = cowboy_req:binding(id, Request),
case emqx_authz:update({replace_once, RuleId}, #{}) of case emqx_authz:update({replace_once, RuleId}, #{}) of
{ok, _} -> {204}; {ok, _} -> {204};
{error, Reason} -> {error, Reason} ->
{400, #{code => <<"BAD_REQUEST">>, {400, #{code => <<"BAD_REQUEST">>,
messgae => atom_to_binary(Reason)}} messgae => atom_to_binary(Reason)}}
end. end.
move_rule(post, _Params, Request) -> move_rule(post, #{bindings := #{id := RuleId}, body := Body}) ->
RuleId = cowboy_req:binding(id, Request), #{<<"position">> := Position} = Body,
{ok, Body, _} = cowboy_req:read_body(Request),
#{<<"position">> := Position} = jsx:decode(Body, [return_maps]),
case emqx_authz:move(RuleId, Position) of case emqx_authz:move(RuleId, Position) of
{ok, _} -> {204}; {ok, _} -> {204};
{error, not_found_rule} -> {error, not_found_rule} ->

View File

@ -35,6 +35,8 @@
-define(API_VERSION, "v5"). -define(API_VERSION, "v5").
-define(BASE_PATH, "api"). -define(BASE_PATH, "api").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
-define(RULE1, #{<<"principal">> => <<"all">>, -define(RULE1, #{<<"principal">> => <<"all">>,
<<"topics">> => [<<"#">>], <<"topics">> => [<<"#">>],
<<"action">> => <<"all">>, <<"action">> => <<"all">>,
@ -75,6 +77,7 @@ groups() ->
init_per_suite(Config) -> init_per_suite(Config) ->
ekka_mnesia:start(), ekka_mnesia:start(),
emqx_mgmt_auth:mnesia(boot), emqx_mgmt_auth:mnesia(boot),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_management, emqx_authz], fun set_special_configs/1), ok = emqx_ct_helpers:start_apps([emqx_management, emqx_authz], fun set_special_configs/1),
{ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false), {ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false),
{ok, _} = emqx:update_config([zones, default, authorization, enable], true), {ok, _} = emqx:update_config([zones, default, authorization, enable], true),

View File

@ -21,6 +21,7 @@
-include("emqx_authz.hrl"). -include("emqx_authz.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
@ -33,6 +34,7 @@ init_per_suite(Config) ->
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, remove, fun(_) -> ok end ), meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_authz]),
{ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false), {ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false),

View File

@ -22,6 +22,8 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
@ -33,6 +35,7 @@ init_per_suite(Config) ->
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, remove, fun(_) -> ok end ), meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_authz]),
{ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false), {ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false),
{ok, _} = emqx:update_config([zones, default, authorization, enable], true), {ok, _} = emqx:update_config([zones, default, authorization, enable], true),

View File

@ -22,6 +22,8 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
@ -33,6 +35,7 @@ init_per_suite(Config) ->
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
meck:expect(emqx_resource, remove, fun(_) -> ok end ), meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_authz]),
{ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false), {ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false),

View File

@ -22,6 +22,8 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
@ -33,6 +35,7 @@ init_per_suite(Config) ->
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
meck:expect(emqx_resource, remove, fun(_) -> ok end ), meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_authz]),
{ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false), {ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false),

View File

@ -21,6 +21,7 @@
-include("emqx_authz.hrl"). -include("emqx_authz.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
@ -33,6 +34,7 @@ init_per_suite(Config) ->
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
meck:expect(emqx_resource, remove, fun(_) -> ok end ), meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_authz]),
{ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false), {ok, _} = emqx:update_config([zones, default, authorization, cache, enable], false),

View File

@ -265,11 +265,11 @@ list_listener(Params) ->
format(list_listener_(Params)). format(list_listener_(Params)).
list_listener_(#{node := Node, id := Identifier}) -> list_listener_(#{node := Node, id := Identifier}) ->
emqx_mgmt:get_listener(Node, Identifier); emqx_mgmt:get_listener(b2a(Node), b2a(Identifier));
list_listener_(#{id := Identifier}) -> list_listener_(#{id := Identifier}) ->
emqx_mgmt:list_listeners_by_id(Identifier); emqx_mgmt:list_listeners_by_id(b2a(Identifier));
list_listener_(#{node := Node}) -> list_listener_(#{node := Node}) ->
emqx_mgmt:list_listeners(Node); emqx_mgmt:list_listeners(b2a(Node));
list_listener_(#{}) -> list_listener_(#{}) ->
emqx_mgmt:list_listeners(). emqx_mgmt:list_listeners().

View File

@ -118,13 +118,13 @@ node_stats_api() ->
nodes(get, _Params) -> nodes(get, _Params) ->
list(#{}). list(#{}).
node(get, #{bingings := #{node_name := NodeName}}) -> node(get, #{bindings := #{node_name := NodeName}}) ->
get_node(binary_to_atom(NodeName, utf8)). get_node(binary_to_atom(NodeName, utf8)).
node_metrics(get, #{bingings := #{node_name := NodeName}}) -> node_metrics(get, #{bindings := #{node_name := NodeName}}) ->
get_metrics(binary_to_atom(NodeName, utf8)). get_metrics(binary_to_atom(NodeName, utf8)).
node_stats(get, #{bingings := #{node_name := NodeName}}) -> node_stats(get, #{bindings := #{node_name := NodeName}}) ->
get_stats(binary_to_atom(NodeName, utf8)). get_stats(binary_to_atom(NodeName, utf8)).
%%%============================================================================================== %%%==============================================================================================
@ -135,7 +135,7 @@ list(#{}) ->
get_node(Node) -> get_node(Node) ->
case emqx_mgmt:lookup_node(Node) of case emqx_mgmt:lookup_node(Node) of
#{node_status := 'ERROR'} -> {error, _} ->
{400, #{code => 'SOURCE_ERROR', message => <<"rpc_failed">>}}; {400, #{code => 'SOURCE_ERROR', message => <<"rpc_failed">>}};
NodeInfo -> NodeInfo ->
{200, format(Node, NodeInfo)} {200, format(Node, NodeInfo)}