|
@@ -76,9 +76,10 @@
|
|
|
|
|
|
|
|
-define(FORMAT_FUN, {?MODULE, format_channel_info}).
|
|
-define(FORMAT_FUN, {?MODULE, format_channel_info}).
|
|
|
|
|
|
|
|
--define(CLIENT_ID_NOT_FOUND,
|
|
|
|
|
- <<"{\"code\": \"RESOURCE_NOT_FOUND\", \"reason\": \"Client id not found\"}">>
|
|
|
|
|
-).
|
|
|
|
|
|
|
+-define(CLIENTID_NOT_FOUND, #{
|
|
|
|
|
+ code => 'CLIENTID_NOT_FOUND',
|
|
|
|
|
+ message => <<"Client ID not found">>
|
|
|
|
|
+}).
|
|
|
|
|
|
|
|
api_spec() ->
|
|
api_spec() ->
|
|
|
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).
|
|
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).
|
|
@@ -219,7 +220,7 @@ schema("/clients/:clientid") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
|
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
@@ -232,7 +233,7 @@ schema("/clients/:clientid") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
204 => <<"Kick out client successfully">>,
|
|
204 => <<"Kick out client successfully">>,
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -247,7 +248,7 @@ schema("/clients/:clientid/authorization/cache") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, authz_cache), #{}),
|
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, authz_cache), #{}),
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
@@ -256,9 +257,9 @@ schema("/clients/:clientid/authorization/cache") ->
|
|
|
tags => ?TAGS,
|
|
tags => ?TAGS,
|
|
|
parameters => [{clientid, hoconsc:mk(binary(), #{in => path})}],
|
|
parameters => [{clientid, hoconsc:mk(binary(), #{in => path})}],
|
|
|
responses => #{
|
|
responses => #{
|
|
|
- 204 => <<"Kick out client successfully">>,
|
|
|
|
|
|
|
+ 204 => <<"Clean client authz cache successfully">>,
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -273,10 +274,11 @@ schema("/clients/:clientid/subscriptions") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => hoconsc:mk(
|
|
200 => hoconsc:mk(
|
|
|
hoconsc:array(hoconsc:ref(emqx_mgmt_api_subscriptions, subscription)), #{}
|
|
hoconsc:array(hoconsc:ref(emqx_mgmt_api_subscriptions, subscription)), #{}
|
|
|
- ),
|
|
|
|
|
- 404 => emqx_dashboard_swagger:error_codes(
|
|
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
)
|
|
)
|
|
|
|
|
+ %% returns [] if client not existed in cluster
|
|
|
|
|
+ %404 => emqx_dashboard_swagger:error_codes(
|
|
|
|
|
+ % ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
|
|
+ %)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -291,7 +293,7 @@ schema("/clients/:clientid/subscribe") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => hoconsc:ref(emqx_mgmt_api_subscriptions, subscription),
|
|
200 => hoconsc:ref(emqx_mgmt_api_subscriptions, subscription),
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -307,7 +309,7 @@ schema("/clients/:clientid/subscribe/bulk") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => hoconsc:array(hoconsc:ref(emqx_mgmt_api_subscriptions, subscription)),
|
|
200 => hoconsc:array(hoconsc:ref(emqx_mgmt_api_subscriptions, subscription)),
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -323,7 +325,7 @@ schema("/clients/:clientid/unsubscribe") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
204 => <<"Unsubscribe OK">>,
|
|
204 => <<"Unsubscribe OK">>,
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -339,7 +341,7 @@ schema("/clients/:clientid/unsubscribe/bulk") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
204 => <<"Unsubscribe OK">>,
|
|
204 => <<"Unsubscribe OK">>,
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -355,7 +357,7 @@ schema("/clients/:clientid/keepalive") ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
|
|
200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
|
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
404 => emqx_dashboard_swagger:error_codes(
|
|
|
- ['CLIENTID_NOT_FOUND'], <<"Client id not found">>
|
|
|
|
|
|
|
+ ['CLIENTID_NOT_FOUND'], <<"Client ID not found">>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -621,7 +623,7 @@ set_keepalive(put, #{bindings := #{clientid := ClientID}, body := Body}) ->
|
|
|
{ok, Interval} ->
|
|
{ok, Interval} ->
|
|
|
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
|
|
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
|
|
|
ok -> lookup(#{clientid => ClientID});
|
|
ok -> lookup(#{clientid => ClientID});
|
|
|
- {error, not_found} -> {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {error, not_found} -> {404, ?CLIENTID_NOT_FOUND};
|
|
|
{error, Reason} -> {400, #{code => 'PARAMS_ERROR', message => Reason}}
|
|
{error, Reason} -> {400, #{code => 'PARAMS_ERROR', message => Reason}}
|
|
|
end
|
|
end
|
|
|
end.
|
|
end.
|
|
@@ -669,7 +671,7 @@ list_clients(QString) ->
|
|
|
lookup(#{clientid := ClientID}) ->
|
|
lookup(#{clientid := ClientID}) ->
|
|
|
case emqx_mgmt:lookup_client({clientid, ClientID}, ?FORMAT_FUN) of
|
|
case emqx_mgmt:lookup_client({clientid, ClientID}, ?FORMAT_FUN) of
|
|
|
[] ->
|
|
[] ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
ClientInfo ->
|
|
ClientInfo ->
|
|
|
{200, hd(ClientInfo)}
|
|
{200, hd(ClientInfo)}
|
|
|
end.
|
|
end.
|
|
@@ -677,7 +679,7 @@ lookup(#{clientid := ClientID}) ->
|
|
|
kickout(#{clientid := ClientID}) ->
|
|
kickout(#{clientid := ClientID}) ->
|
|
|
case emqx_mgmt:kickout_client({ClientID, ?FORMAT_FUN}) of
|
|
case emqx_mgmt:kickout_client({ClientID, ?FORMAT_FUN}) of
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
_ ->
|
|
_ ->
|
|
|
{204}
|
|
{204}
|
|
|
end.
|
|
end.
|
|
@@ -685,7 +687,7 @@ kickout(#{clientid := ClientID}) ->
|
|
|
get_authz_cache(#{clientid := ClientID}) ->
|
|
get_authz_cache(#{clientid := ClientID}) ->
|
|
|
case emqx_mgmt:list_authz_cache(ClientID) of
|
|
case emqx_mgmt:list_authz_cache(ClientID) of
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
{error, Reason} ->
|
|
{error, Reason} ->
|
|
|
Message = list_to_binary(io_lib:format("~p", [Reason])),
|
|
Message = list_to_binary(io_lib:format("~p", [Reason])),
|
|
|
{500, #{code => <<"UNKNOW_ERROR">>, message => Message}};
|
|
{500, #{code => <<"UNKNOW_ERROR">>, message => Message}};
|
|
@@ -699,7 +701,7 @@ clean_authz_cache(#{clientid := ClientID}) ->
|
|
|
ok ->
|
|
ok ->
|
|
|
{204};
|
|
{204};
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
{error, Reason} ->
|
|
{error, Reason} ->
|
|
|
Message = list_to_binary(io_lib:format("~p", [Reason])),
|
|
Message = list_to_binary(io_lib:format("~p", [Reason])),
|
|
|
{500, #{code => <<"UNKNOW_ERROR">>, message => Message}}
|
|
{500, #{code => <<"UNKNOW_ERROR">>, message => Message}}
|
|
@@ -709,7 +711,7 @@ subscribe(#{clientid := ClientID, topic := Topic} = Sub) ->
|
|
|
Opts = maps:with([qos, nl, rap, rh], Sub),
|
|
Opts = maps:with([qos, nl, rap, rh], Sub),
|
|
|
case do_subscribe(ClientID, Topic, Opts) of
|
|
case do_subscribe(ClientID, Topic, Opts) of
|
|
|
{error, channel_not_found} ->
|
|
{error, channel_not_found} ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
{error, Reason} ->
|
|
{error, Reason} ->
|
|
|
Message = list_to_binary(io_lib:format("~p", [Reason])),
|
|
Message = list_to_binary(io_lib:format("~p", [Reason])),
|
|
|
{500, #{code => <<"UNKNOW_ERROR">>, message => Message}};
|
|
{500, #{code => <<"UNKNOW_ERROR">>, message => Message}};
|
|
@@ -723,7 +725,7 @@ subscribe_batch(#{clientid := ClientID, topics := Topics}) ->
|
|
|
%% has returned. So if one want to subscribe topics in this hook, it will fail.
|
|
%% has returned. So if one want to subscribe topics in this hook, it will fail.
|
|
|
case ets:lookup(emqx_channel, ClientID) of
|
|
case ets:lookup(emqx_channel, ClientID) of
|
|
|
[] ->
|
|
[] ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
_ ->
|
|
_ ->
|
|
|
ArgList = [
|
|
ArgList = [
|
|
|
[ClientID, Topic, maps:with([qos, nl, rap, rh], Sub)]
|
|
[ClientID, Topic, maps:with([qos, nl, rap, rh], Sub)]
|
|
@@ -735,7 +737,7 @@ subscribe_batch(#{clientid := ClientID, topics := Topics}) ->
|
|
|
unsubscribe(#{clientid := ClientID, topic := Topic}) ->
|
|
unsubscribe(#{clientid := ClientID, topic := Topic}) ->
|
|
|
case do_unsubscribe(ClientID, Topic) of
|
|
case do_unsubscribe(ClientID, Topic) of
|
|
|
{error, channel_not_found} ->
|
|
{error, channel_not_found} ->
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND};
|
|
|
|
|
|
|
+ {404, ?CLIENTID_NOT_FOUND};
|
|
|
{unsubscribe, [{Topic, #{}}]} ->
|
|
{unsubscribe, [{Topic, #{}}]} ->
|
|
|
{204}
|
|
{204}
|
|
|
end.
|
|
end.
|
|
@@ -745,8 +747,8 @@ unsubscribe_batch(#{clientid := ClientID, topics := Topics}) ->
|
|
|
{200, _} ->
|
|
{200, _} ->
|
|
|
_ = emqx_mgmt:unsubscribe_batch(ClientID, Topics),
|
|
_ = emqx_mgmt:unsubscribe_batch(ClientID, Topics),
|
|
|
{204};
|
|
{204};
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND} ->
|
|
|
|
|
- {404, ?CLIENT_ID_NOT_FOUND}
|
|
|
|
|
|
|
+ {404, NotFound} ->
|
|
|
|
|
+ {404, NotFound}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|