|
@@ -59,10 +59,10 @@ req_schema() ->
|
|
|
Schema = [emqx_mgmt_api_configs:gen_schema(
|
|
Schema = [emqx_mgmt_api_configs:gen_schema(
|
|
|
emqx:get_raw_config([listeners, T, default], #{}))
|
|
emqx:get_raw_config([listeners, T, default], #{}))
|
|
|
|| T <- ?TYPES_ATOM],
|
|
|| T <- ?TYPES_ATOM],
|
|
|
- #{oneOf => Schema}.
|
|
|
|
|
|
|
+ #{'oneOf' => Schema}.
|
|
|
|
|
|
|
|
resp_schema() ->
|
|
resp_schema() ->
|
|
|
- #{oneOf := Schema} = req_schema(),
|
|
|
|
|
|
|
+ #{'oneOf' := Schema} = req_schema(),
|
|
|
AddMetadata = fun(Prop) ->
|
|
AddMetadata = fun(Prop) ->
|
|
|
Prop#{running => #{type => boolean},
|
|
Prop#{running => #{type => boolean},
|
|
|
id => #{type => string},
|
|
id => #{type => string},
|
|
@@ -70,7 +70,7 @@ resp_schema() ->
|
|
|
end,
|
|
end,
|
|
|
Schema1 = [S#{properties => AddMetadata(Prop)}
|
|
Schema1 = [S#{properties => AddMetadata(Prop)}
|
|
|
|| S = #{properties := Prop} <- Schema],
|
|
|| S = #{properties := Prop} <- Schema],
|
|
|
- #{oneOf => Schema1}.
|
|
|
|
|
|
|
+ #{'oneOf' => Schema1}.
|
|
|
|
|
|
|
|
api_list_listeners() ->
|
|
api_list_listeners() ->
|
|
|
Metadata = #{
|
|
Metadata = #{
|
|
@@ -78,7 +78,8 @@ api_list_listeners() ->
|
|
|
description => <<"List listeners from all nodes in the cluster">>,
|
|
description => <<"List listeners from all nodes in the cluster">>,
|
|
|
responses => #{
|
|
responses => #{
|
|
|
<<"200">> =>
|
|
<<"200">> =>
|
|
|
- emqx_mgmt_util:array_schema(resp_schema(), <<"List listeners successfully">>)}}},
|
|
|
|
|
|
|
+ emqx_mgmt_util:array_schema(resp_schema(),
|
|
|
|
|
+ <<"List listeners successfully">>)}}},
|
|
|
{"/listeners", Metadata, list_listeners}.
|
|
{"/listeners", Metadata, list_listeners}.
|
|
|
|
|
|
|
|
api_list_update_listeners_by_id() ->
|
|
api_list_update_listeners_by_id() ->
|
|
@@ -92,25 +93,28 @@ api_list_update_listeners_by_id() ->
|
|
|
<<"200">> =>
|
|
<<"200">> =>
|
|
|
emqx_mgmt_util:array_schema(resp_schema(), <<"List listeners successfully">>)}},
|
|
emqx_mgmt_util:array_schema(resp_schema(), <<"List listeners successfully">>)}},
|
|
|
put => #{
|
|
put => #{
|
|
|
- description => <<"Create or update a listener by a given Id to all nodes in the cluster">>,
|
|
|
|
|
|
|
+ description =>
|
|
|
|
|
+ <<"Create or update a listener by a given Id to all nodes in the cluster">>,
|
|
|
parameters => [param_path_id()],
|
|
parameters => [param_path_id()],
|
|
|
- requestBody => emqx_mgmt_util:schema(req_schema(), <<"Listener Config">>),
|
|
|
|
|
|
|
+ 'requestBody' => emqx_mgmt_util:schema(req_schema(), <<"Listener Config">>),
|
|
|
responses => #{
|
|
responses => #{
|
|
|
<<"400">> =>
|
|
<<"400">> =>
|
|
|
- emqx_mgmt_util:error_schema(?UPDATE_CONFIG_FAILED, ['BAD_LISTENER_ID', 'BAD_CONFIG_SCHEMA']),
|
|
|
|
|
|
|
+ emqx_mgmt_util:error_schema(?UPDATE_CONFIG_FAILED,
|
|
|
|
|
+ ['BAD_LISTENER_ID', 'BAD_CONFIG_SCHEMA']),
|
|
|
<<"404">> =>
|
|
<<"404">> =>
|
|
|
emqx_mgmt_util:error_schema(?LISTENER_NOT_FOUND, ['BAD_LISTENER_ID']),
|
|
emqx_mgmt_util:error_schema(?LISTENER_NOT_FOUND, ['BAD_LISTENER_ID']),
|
|
|
<<"500">> =>
|
|
<<"500">> =>
|
|
|
emqx_mgmt_util:error_schema(?OPERATION_FAILED, ['INTERNAL_ERROR']),
|
|
emqx_mgmt_util:error_schema(?OPERATION_FAILED, ['INTERNAL_ERROR']),
|
|
|
<<"200">> =>
|
|
<<"200">> =>
|
|
|
- emqx_mgmt_util:array_schema(resp_schema(), <<"Create or update listener successfully">>)}},
|
|
|
|
|
|
|
+ emqx_mgmt_util:array_schema(resp_schema(),
|
|
|
|
|
+ <<"Create or update listener successfully">>)}},
|
|
|
delete => #{
|
|
delete => #{
|
|
|
description => <<"Delete a listener by a given Id to all nodes in the cluster">>,
|
|
description => <<"Delete a listener by a given Id to all nodes in the cluster">>,
|
|
|
parameters => [param_path_id()],
|
|
parameters => [param_path_id()],
|
|
|
responses => #{
|
|
responses => #{
|
|
|
<<"404">> =>
|
|
<<"404">> =>
|
|
|
emqx_mgmt_util:error_schema(?LISTENER_NOT_FOUND, ['BAD_LISTENER_ID']),
|
|
emqx_mgmt_util:error_schema(?LISTENER_NOT_FOUND, ['BAD_LISTENER_ID']),
|
|
|
- <<"200">> =>
|
|
|
|
|
|
|
+ <<"204">> =>
|
|
|
emqx_mgmt_util:schema(<<"Delete listener successfully">>)}}
|
|
emqx_mgmt_util:schema(<<"Delete listener successfully">>)}}
|
|
|
},
|
|
},
|
|
|
{"/listeners/:id", Metadata, crud_listeners_by_id}.
|
|
{"/listeners/:id", Metadata, crud_listeners_by_id}.
|
|
@@ -143,10 +147,11 @@ api_get_update_listener_by_id_on_node() ->
|
|
|
put => #{
|
|
put => #{
|
|
|
description => <<"Create or update a listener by a given Id on a specific node">>,
|
|
description => <<"Create or update a listener by a given Id on a specific node">>,
|
|
|
parameters => [param_path_node(), param_path_id()],
|
|
parameters => [param_path_node(), param_path_id()],
|
|
|
- requestBody => emqx_mgmt_util:schema(req_schema(), <<"Listener Config">>),
|
|
|
|
|
|
|
+ 'requestBody' => emqx_mgmt_util:schema(req_schema(), <<"Listener Config">>),
|
|
|
responses => #{
|
|
responses => #{
|
|
|
<<"400">> =>
|
|
<<"400">> =>
|
|
|
- emqx_mgmt_util:error_schema(?UPDATE_CONFIG_FAILED, ['BAD_LISTENER_ID', 'BAD_CONFIG_SCHEMA']),
|
|
|
|
|
|
|
+ emqx_mgmt_util:error_schema(?UPDATE_CONFIG_FAILED,
|
|
|
|
|
+ ['BAD_LISTENER_ID', 'BAD_CONFIG_SCHEMA']),
|
|
|
<<"404">> =>
|
|
<<"404">> =>
|
|
|
emqx_mgmt_util:error_schema(?NODE_LISTENER_NOT_FOUND,
|
|
emqx_mgmt_util:error_schema(?NODE_LISTENER_NOT_FOUND,
|
|
|
['BAD_NODE_NAME', 'BAD_LISTENER_ID']),
|
|
['BAD_NODE_NAME', 'BAD_LISTENER_ID']),
|
|
@@ -160,7 +165,7 @@ api_get_update_listener_by_id_on_node() ->
|
|
|
responses => #{
|
|
responses => #{
|
|
|
<<"404">> =>
|
|
<<"404">> =>
|
|
|
emqx_mgmt_util:error_schema(?LISTENER_NOT_FOUND, ['BAD_LISTENER_ID']),
|
|
emqx_mgmt_util:error_schema(?LISTENER_NOT_FOUND, ['BAD_LISTENER_ID']),
|
|
|
- <<"200">> =>
|
|
|
|
|
|
|
+ <<"204">> =>
|
|
|
emqx_mgmt_util:schema(<<"Delete listener successfully">>)}}
|
|
emqx_mgmt_util:schema(<<"Delete listener successfully">>)}}
|
|
|
},
|
|
},
|
|
|
{"/nodes/:node/listeners/:id", Metadata, crud_listener_by_id_on_node}.
|
|
{"/nodes/:node/listeners/:id", Metadata, crud_listener_by_id_on_node}.
|
|
@@ -251,7 +256,7 @@ crud_listeners_by_id(put, #{bindings := #{id := Id}, body := Conf}) ->
|
|
|
crud_listeners_by_id(delete, #{bindings := #{id := Id}}) ->
|
|
crud_listeners_by_id(delete, #{bindings := #{id := Id}}) ->
|
|
|
Results = emqx_mgmt:remove_listener(Id),
|
|
Results = emqx_mgmt:remove_listener(Id),
|
|
|
case lists:filter(fun filter_errors/1, Results) of
|
|
case lists:filter(fun filter_errors/1, Results) of
|
|
|
- [] -> {200};
|
|
|
|
|
|
|
+ [] -> {204};
|
|
|
Errors -> {500, #{code => 'UNKNOW_ERROR', message => err_msg(Errors)}}
|
|
Errors -> {500, #{code => 'UNKNOW_ERROR', message => err_msg(Errors)}}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
@@ -291,7 +296,7 @@ crud_listener_by_id_on_node(put, #{bindings := #{id := Id, node := Node}, body :
|
|
|
end;
|
|
end;
|
|
|
crud_listener_by_id_on_node(delete, #{bindings := #{id := Id, node := Node}}) ->
|
|
crud_listener_by_id_on_node(delete, #{bindings := #{id := Id, node := Node}}) ->
|
|
|
case emqx_mgmt:remove_listener(atom(Node), Id) of
|
|
case emqx_mgmt:remove_listener(atom(Node), Id) of
|
|
|
- ok -> {200};
|
|
|
|
|
|
|
+ ok -> {204};
|
|
|
{error, Reason} -> {500, #{code => 'UNKNOW_ERROR', message => err_msg(Reason)}}
|
|
{error, Reason} -> {500, #{code => 'UNKNOW_ERROR', message => err_msg(Reason)}}
|
|
|
end.
|
|
end.
|
|
|
|
|
|