|
|
@@ -37,7 +37,7 @@
|
|
|
namespace/0
|
|
|
]).
|
|
|
|
|
|
-%% API callbacks
|
|
|
+%% API callbacks : actions
|
|
|
-export([
|
|
|
'/actions'/2,
|
|
|
'/actions/:id'/2,
|
|
|
@@ -49,6 +49,18 @@
|
|
|
'/actions_probe'/2,
|
|
|
'/action_types'/2
|
|
|
]).
|
|
|
+%% API callbacks : sources
|
|
|
+-export([
|
|
|
+ '/sources'/2,
|
|
|
+ '/sources/:id'/2,
|
|
|
+ '/sources/:id/metrics'/2,
|
|
|
+ '/sources/:id/metrics/reset'/2,
|
|
|
+ '/sources/:id/enable/:enable'/2,
|
|
|
+ '/sources/:id/:operation'/2,
|
|
|
+ '/nodes/:node/sources/:id/:operation'/2,
|
|
|
+ '/sources_probe'/2,
|
|
|
+ '/source_types'/2
|
|
|
+]).
|
|
|
|
|
|
%% BpAPI / RPC Targets
|
|
|
-export([
|
|
|
@@ -81,13 +93,16 @@
|
|
|
end
|
|
|
).
|
|
|
|
|
|
-namespace() -> "actions".
|
|
|
+namespace() -> "actions_and_sources".
|
|
|
|
|
|
api_spec() ->
|
|
|
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).
|
|
|
|
|
|
paths() ->
|
|
|
[
|
|
|
+ %%=============
|
|
|
+ %% Actions
|
|
|
+ %%=============
|
|
|
"/actions",
|
|
|
"/actions/:id",
|
|
|
"/actions/:id/enable/:enable",
|
|
|
@@ -98,7 +113,21 @@ paths() ->
|
|
|
"/actions/:id/metrics",
|
|
|
"/actions/:id/metrics/reset",
|
|
|
"/actions_probe",
|
|
|
- "/action_types"
|
|
|
+ "/action_types",
|
|
|
+ %%=============
|
|
|
+ %% Sources
|
|
|
+ %%=============
|
|
|
+ "/sources",
|
|
|
+ "/sources/:id",
|
|
|
+ "/sources/:id/enable/:enable",
|
|
|
+ "/sources/:id/:operation",
|
|
|
+ "/nodes/:node/sources/:id/:operation",
|
|
|
+ %% %% Caveat: metrics paths must come *after* `/:operation', otherwise minirest will
|
|
|
+ %% %% try to match the latter first, trying to interpret `metrics' as an operation...
|
|
|
+ "/sources/:id/metrics",
|
|
|
+ "/sources/:id/metrics/reset",
|
|
|
+ "/sources_probe"
|
|
|
+ %% "/source_types"
|
|
|
].
|
|
|
|
|
|
error_schema(Code, Message) ->
|
|
|
@@ -111,17 +140,28 @@ error_schema(Codes, Message, ExtraFields) when is_list(Message) ->
|
|
|
error_schema(Codes, Message, ExtraFields) when is_list(Codes) andalso is_binary(Message) ->
|
|
|
ExtraFields ++ emqx_dashboard_swagger:error_codes(Codes, Message).
|
|
|
|
|
|
-get_response_body_schema() ->
|
|
|
+actions_get_response_body_schema() ->
|
|
|
+ emqx_dashboard_swagger:schema_with_examples(
|
|
|
+ emqx_bridge_v2_schema:actions_get_response(),
|
|
|
+ bridge_info_examples(get, ?ROOT_KEY_ACTIONS)
|
|
|
+ ).
|
|
|
+
|
|
|
+sources_get_response_body_schema() ->
|
|
|
emqx_dashboard_swagger:schema_with_examples(
|
|
|
- emqx_bridge_v2_schema:get_response(),
|
|
|
- bridge_info_examples(get)
|
|
|
+ emqx_bridge_v2_schema:sources_get_response(),
|
|
|
+ bridge_info_examples(get, ?ROOT_KEY_SOURCES)
|
|
|
).
|
|
|
|
|
|
-bridge_info_examples(Method) ->
|
|
|
- emqx_bridge_v2_schema:examples(Method).
|
|
|
+bridge_info_examples(Method, ?ROOT_KEY_ACTIONS) ->
|
|
|
+ emqx_bridge_v2_schema:actions_examples(Method);
|
|
|
+bridge_info_examples(Method, ?ROOT_KEY_SOURCES) ->
|
|
|
+ emqx_bridge_v2_schema:sources_examples(Method).
|
|
|
|
|
|
-bridge_info_array_example(Method) ->
|
|
|
- lists:map(fun(#{value := Config}) -> Config end, maps:values(bridge_info_examples(Method))).
|
|
|
+bridge_info_array_example(Method, ConfRootKey) ->
|
|
|
+ lists:map(
|
|
|
+ fun(#{value := Config}) -> Config end,
|
|
|
+ maps:values(bridge_info_examples(Method, ConfRootKey))
|
|
|
+ ).
|
|
|
|
|
|
param_path_id() ->
|
|
|
{id,
|
|
|
@@ -195,6 +235,9 @@ param_path_enable() ->
|
|
|
}
|
|
|
)}.
|
|
|
|
|
|
+%%================================================================================
|
|
|
+%% Actions
|
|
|
+%%================================================================================
|
|
|
schema("/actions") ->
|
|
|
#{
|
|
|
'operationId' => '/actions',
|
|
|
@@ -204,8 +247,8 @@ schema("/actions") ->
|
|
|
description => ?DESC("desc_api1"),
|
|
|
responses => #{
|
|
|
200 => emqx_dashboard_swagger:schema_with_example(
|
|
|
- array(emqx_bridge_v2_schema:get_response()),
|
|
|
- bridge_info_array_example(get)
|
|
|
+ array(emqx_bridge_v2_schema:actions_get_response()),
|
|
|
+ bridge_info_array_example(get, ?ROOT_KEY_ACTIONS)
|
|
|
)
|
|
|
}
|
|
|
},
|
|
|
@@ -214,11 +257,11 @@ schema("/actions") ->
|
|
|
summary => <<"Create bridge">>,
|
|
|
description => ?DESC("desc_api2"),
|
|
|
'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
- emqx_bridge_v2_schema:post_request(),
|
|
|
- bridge_info_examples(post)
|
|
|
+ emqx_bridge_v2_schema:actions_post_request(),
|
|
|
+ bridge_info_examples(post, ?ROOT_KEY_ACTIONS)
|
|
|
),
|
|
|
responses => #{
|
|
|
- 201 => get_response_body_schema(),
|
|
|
+ 201 => actions_get_response_body_schema(),
|
|
|
400 => error_schema('ALREADY_EXISTS', "Bridge already exists")
|
|
|
}
|
|
|
}
|
|
|
@@ -232,7 +275,7 @@ schema("/actions/:id") ->
|
|
|
description => ?DESC("desc_api3"),
|
|
|
parameters => [param_path_id()],
|
|
|
responses => #{
|
|
|
- 200 => get_response_body_schema(),
|
|
|
+ 200 => actions_get_response_body_schema(),
|
|
|
404 => error_schema('NOT_FOUND', "Bridge not found")
|
|
|
}
|
|
|
},
|
|
|
@@ -242,11 +285,11 @@ schema("/actions/:id") ->
|
|
|
description => ?DESC("desc_api4"),
|
|
|
parameters => [param_path_id()],
|
|
|
'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
- emqx_bridge_v2_schema:put_request(),
|
|
|
- bridge_info_examples(put)
|
|
|
+ emqx_bridge_v2_schema:actions_put_request(),
|
|
|
+ bridge_info_examples(put, ?ROOT_KEY_ACTIONS)
|
|
|
),
|
|
|
responses => #{
|
|
|
- 200 => get_response_body_schema(),
|
|
|
+ 200 => actions_get_response_body_schema(),
|
|
|
404 => error_schema('NOT_FOUND', "Bridge not found"),
|
|
|
400 => error_schema('BAD_REQUEST', "Update bridge failed")
|
|
|
}
|
|
|
@@ -371,8 +414,8 @@ schema("/actions_probe") ->
|
|
|
desc => ?DESC("desc_api9"),
|
|
|
summary => <<"Test creating bridge">>,
|
|
|
'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
- emqx_bridge_v2_schema:post_request(),
|
|
|
- bridge_info_examples(post)
|
|
|
+ emqx_bridge_v2_schema:actions_post_request(),
|
|
|
+ bridge_info_examples(post, ?ROOT_KEY_ACTIONS)
|
|
|
),
|
|
|
responses => #{
|
|
|
204 => <<"Test bridge OK">>,
|
|
|
@@ -389,12 +432,223 @@ schema("/action_types") ->
|
|
|
summary => <<"List available action types">>,
|
|
|
responses => #{
|
|
|
200 => emqx_dashboard_swagger:schema_with_examples(
|
|
|
- array(emqx_bridge_v2_schema:types_sc()),
|
|
|
+ array(emqx_bridge_v2_schema:action_types_sc()),
|
|
|
#{
|
|
|
<<"types">> =>
|
|
|
#{
|
|
|
summary => <<"Action types">>,
|
|
|
- value => emqx_bridge_v2_schema:types()
|
|
|
+ value => emqx_bridge_v2_schema:action_types()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+%%================================================================================
|
|
|
+%% Sources
|
|
|
+%%================================================================================
|
|
|
+schema("/sources") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources',
|
|
|
+ get => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"List sources">>,
|
|
|
+ description => ?DESC("desc_api1"),
|
|
|
+ responses => #{
|
|
|
+ %% FIXME: examples
|
|
|
+ 200 => emqx_dashboard_swagger:schema_with_example(
|
|
|
+ array(emqx_bridge_v2_schema:sources_get_response()),
|
|
|
+ bridge_info_array_example(get, ?ROOT_KEY_SOURCES)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
+ post => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Create source">>,
|
|
|
+ description => ?DESC("desc_api2"),
|
|
|
+ %% FIXME: examples
|
|
|
+ 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
+ emqx_bridge_v2_schema:sources_post_request(),
|
|
|
+ bridge_info_examples(post, ?ROOT_KEY_SOURCES)
|
|
|
+ ),
|
|
|
+ responses => #{
|
|
|
+ 201 => sources_get_response_body_schema(),
|
|
|
+ 400 => error_schema('ALREADY_EXISTS', "Source already exists")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/sources/:id") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources/:id',
|
|
|
+ get => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Get source">>,
|
|
|
+ description => ?DESC("desc_api3"),
|
|
|
+ parameters => [param_path_id()],
|
|
|
+ responses => #{
|
|
|
+ 200 => sources_get_response_body_schema(),
|
|
|
+ 404 => error_schema('NOT_FOUND', "Source not found")
|
|
|
+ }
|
|
|
+ },
|
|
|
+ put => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Update source">>,
|
|
|
+ description => ?DESC("desc_api4"),
|
|
|
+ parameters => [param_path_id()],
|
|
|
+ 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
+ emqx_bridge_v2_schema:sources_put_request(),
|
|
|
+ bridge_info_examples(put, ?ROOT_KEY_SOURCES)
|
|
|
+ ),
|
|
|
+ responses => #{
|
|
|
+ 200 => sources_get_response_body_schema(),
|
|
|
+ 404 => error_schema('NOT_FOUND', "Source not found"),
|
|
|
+ 400 => error_schema('BAD_REQUEST', "Update source failed")
|
|
|
+ }
|
|
|
+ },
|
|
|
+ delete => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Delete source">>,
|
|
|
+ description => ?DESC("desc_api5"),
|
|
|
+ parameters => [param_path_id(), param_qs_delete_cascade()],
|
|
|
+ responses => #{
|
|
|
+ 204 => <<"Source deleted">>,
|
|
|
+ 400 => error_schema(
|
|
|
+ 'BAD_REQUEST',
|
|
|
+ "Cannot delete bridge while active rules are defined for this source",
|
|
|
+ [{rules, mk(array(string()), #{desc => "Dependent Rule IDs"})}]
|
|
|
+ ),
|
|
|
+ 404 => error_schema('NOT_FOUND', "Source not found"),
|
|
|
+ 503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/sources/:id/metrics") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources/:id/metrics',
|
|
|
+ get => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Get source metrics">>,
|
|
|
+ description => ?DESC("desc_bridge_metrics"),
|
|
|
+ parameters => [param_path_id()],
|
|
|
+ responses => #{
|
|
|
+ 200 => emqx_bridge_schema:metrics_fields(),
|
|
|
+ 404 => error_schema('NOT_FOUND', "Source not found")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/sources/:id/metrics/reset") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources/:id/metrics/reset',
|
|
|
+ put => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Reset source metrics">>,
|
|
|
+ description => ?DESC("desc_api6"),
|
|
|
+ parameters => [param_path_id()],
|
|
|
+ responses => #{
|
|
|
+ 204 => <<"Reset success">>,
|
|
|
+ 404 => error_schema('NOT_FOUND', "Source not found")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/sources/:id/enable/:enable") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources/:id/enable/:enable',
|
|
|
+ put =>
|
|
|
+ #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Enable or disable bridge">>,
|
|
|
+ desc => ?DESC("desc_enable_bridge"),
|
|
|
+ parameters => [param_path_id(), param_path_enable()],
|
|
|
+ responses =>
|
|
|
+ #{
|
|
|
+ 204 => <<"Success">>,
|
|
|
+ 404 => error_schema(
|
|
|
+ 'NOT_FOUND', "Bridge not found or invalid operation"
|
|
|
+ ),
|
|
|
+ 503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/sources/:id/:operation") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources/:id/:operation',
|
|
|
+ post => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Manually start a bridge">>,
|
|
|
+ description => ?DESC("desc_api7"),
|
|
|
+ parameters => [
|
|
|
+ param_path_id(),
|
|
|
+ param_path_operation_cluster()
|
|
|
+ ],
|
|
|
+ responses => #{
|
|
|
+ 204 => <<"Operation success">>,
|
|
|
+ 400 => error_schema(
|
|
|
+ 'BAD_REQUEST', "Problem with configuration of external service"
|
|
|
+ ),
|
|
|
+ 404 => error_schema('NOT_FOUND', "Bridge not found or invalid operation"),
|
|
|
+ 501 => error_schema('NOT_IMPLEMENTED', "Not Implemented"),
|
|
|
+ 503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/nodes/:node/sources/:id/:operation") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/nodes/:node/sources/:id/:operation',
|
|
|
+ post => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ summary => <<"Manually start a bridge on a given node">>,
|
|
|
+ description => ?DESC("desc_api8"),
|
|
|
+ parameters => [
|
|
|
+ param_path_node(),
|
|
|
+ param_path_id(),
|
|
|
+ param_path_operation_on_node()
|
|
|
+ ],
|
|
|
+ responses => #{
|
|
|
+ 204 => <<"Operation success">>,
|
|
|
+ 400 => error_schema(
|
|
|
+ 'BAD_REQUEST',
|
|
|
+ "Problem with configuration of external service or bridge not enabled"
|
|
|
+ ),
|
|
|
+ 404 => error_schema(
|
|
|
+ 'NOT_FOUND', "Bridge or node not found or invalid operation"
|
|
|
+ ),
|
|
|
+ 501 => error_schema('NOT_IMPLEMENTED', "Not Implemented"),
|
|
|
+ 503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/sources_probe") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/sources_probe',
|
|
|
+ post => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ desc => ?DESC("desc_api9"),
|
|
|
+ summary => <<"Test creating bridge">>,
|
|
|
+ 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
+ emqx_bridge_v2_schema:sources_post_request(),
|
|
|
+ bridge_info_examples(post, ?ROOT_KEY_SOURCES)
|
|
|
+ ),
|
|
|
+ responses => #{
|
|
|
+ 204 => <<"Test bridge OK">>,
|
|
|
+ 400 => error_schema(['TEST_FAILED'], "bridge test failed")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+schema("/source_types") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/source_types',
|
|
|
+ get => #{
|
|
|
+ tags => [<<"sources">>],
|
|
|
+ desc => ?DESC("desc_api10"),
|
|
|
+ summary => <<"List available source types">>,
|
|
|
+ responses => #{
|
|
|
+ 200 => emqx_dashboard_swagger:schema_with_examples(
|
|
|
+ array(emqx_bridge_v2_schema:action_types_sc()),
|
|
|
+ #{
|
|
|
+ <<"types">> =>
|
|
|
+ #{
|
|
|
+ summary => <<"Source types">>,
|
|
|
+ value => emqx_bridge_v2_schema:action_types()
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
@@ -402,6 +656,12 @@ schema("/action_types") ->
|
|
|
}
|
|
|
}.
|
|
|
|
|
|
+%%------------------------------------------------------------------------------
|
|
|
+%% Thin Handlers
|
|
|
+%%------------------------------------------------------------------------------
|
|
|
+%%================================================================================
|
|
|
+%% Actions
|
|
|
+%%================================================================================
|
|
|
'/actions'(post, #{body := #{<<"type">> := BridgeType, <<"name">> := BridgeName} = Conf0}) ->
|
|
|
handle_create(?ROOT_KEY_ACTIONS, BridgeType, BridgeName, Conf0);
|
|
|
'/actions'(get, _Params) ->
|
|
|
@@ -439,7 +699,48 @@ schema("/action_types") ->
|
|
|
handle_probe(?ROOT_KEY_ACTIONS, Request).
|
|
|
|
|
|
'/action_types'(get, _Request) ->
|
|
|
- ?OK(emqx_bridge_v2_schema:types()).
|
|
|
+ ?OK(emqx_bridge_v2_schema:action_types()).
|
|
|
+%%================================================================================
|
|
|
+%% Sources
|
|
|
+%%================================================================================
|
|
|
+'/sources'(post, #{body := #{<<"type">> := BridgeType, <<"name">> := BridgeName} = Conf0}) ->
|
|
|
+ handle_create(?ROOT_KEY_SOURCES, BridgeType, BridgeName, Conf0);
|
|
|
+'/sources'(get, _Params) ->
|
|
|
+ handle_list(?ROOT_KEY_SOURCES).
|
|
|
+
|
|
|
+'/sources/:id'(get, #{bindings := #{id := Id}}) ->
|
|
|
+ ?TRY_PARSE_ID(Id, lookup_from_all_nodes(?ROOT_KEY_SOURCES, BridgeType, BridgeName, 200));
|
|
|
+'/sources/:id'(put, #{bindings := #{id := Id}, body := Conf0}) ->
|
|
|
+ handle_update(?ROOT_KEY_SOURCES, Id, Conf0);
|
|
|
+'/sources/:id'(delete, #{bindings := #{id := Id}, query_string := Qs}) ->
|
|
|
+ handle_delete(?ROOT_KEY_SOURCES, Id, Qs).
|
|
|
+
|
|
|
+'/sources/:id/metrics'(get, #{bindings := #{id := Id}}) ->
|
|
|
+ ?TRY_PARSE_ID(Id, get_metrics_from_all_nodes(?ROOT_KEY_SOURCES, BridgeType, BridgeName)).
|
|
|
+
|
|
|
+'/sources/:id/metrics/reset'(put, #{bindings := #{id := Id}}) ->
|
|
|
+ handle_reset_metrics(?ROOT_KEY_SOURCES, Id).
|
|
|
+
|
|
|
+'/sources/:id/enable/:enable'(put, #{bindings := #{id := Id, enable := Enable}}) ->
|
|
|
+ handle_disable_enable(?ROOT_KEY_SOURCES, Id, Enable).
|
|
|
+
|
|
|
+'/sources/:id/:operation'(post, #{
|
|
|
+ bindings :=
|
|
|
+ #{id := Id, operation := Op}
|
|
|
+}) ->
|
|
|
+ handle_operation(?ROOT_KEY_SOURCES, Id, Op).
|
|
|
+
|
|
|
+'/nodes/:node/sources/:id/:operation'(post, #{
|
|
|
+ bindings :=
|
|
|
+ #{id := Id, operation := Op, node := Node}
|
|
|
+}) ->
|
|
|
+ handle_node_operation(?ROOT_KEY_SOURCES, Node, Id, Op).
|
|
|
+
|
|
|
+'/sources_probe'(post, Request) ->
|
|
|
+ handle_probe(?ROOT_KEY_SOURCES, Request).
|
|
|
+
|
|
|
+'/source_types'(get, _Request) ->
|
|
|
+ ?OK(emqx_bridge_v2_schema:source_types()).
|
|
|
|
|
|
%%------------------------------------------------------------------------------
|
|
|
%% Handlers
|
|
|
@@ -451,7 +752,7 @@ handle_list(ConfRootKey) ->
|
|
|
case is_ok(NodeReplies) of
|
|
|
{ok, NodeBridges} ->
|
|
|
AllBridges = [
|
|
|
- [format_resource(Data, Node) || Data <- Bridges]
|
|
|
+ [format_resource(ConfRootKey, Data, Node) || Data <- Bridges]
|
|
|
|| {Node, Bridges} <- lists:zip(Nodes, NodeBridges)
|
|
|
],
|
|
|
?OK(zip_bridges(AllBridges));
|
|
|
@@ -574,7 +875,12 @@ handle_node_operation(ConfRootKey, Node, Id, Op) ->
|
|
|
).
|
|
|
|
|
|
handle_probe(ConfRootKey, Request) ->
|
|
|
- RequestMeta = #{module => ?MODULE, method => post, path => "/actions_probe"},
|
|
|
+ Path =
|
|
|
+ case ConfRootKey of
|
|
|
+ ?ROOT_KEY_ACTIONS -> "/actions_probe";
|
|
|
+ ?ROOT_KEY_SOURCES -> "/sources_probe"
|
|
|
+ end,
|
|
|
+ RequestMeta = #{module => ?MODULE, method => post, path => Path},
|
|
|
case emqx_dashboard_swagger:filter_check_request_and_translate_body(Request, RequestMeta) of
|
|
|
{ok, #{body := #{<<"type">> := Type} = Params}} ->
|
|
|
Params1 = maybe_deobfuscate_bridge_probe(Params),
|
|
|
@@ -664,8 +970,8 @@ get_metrics_from_all_nodes(ConfRootKey, Type, Name) ->
|
|
|
?INTERNAL_ERROR(Reason)
|
|
|
end.
|
|
|
|
|
|
-operation_func(all, start) -> v2_start_bridge_to_all_nodes_v6;
|
|
|
-operation_func(_Node, start) -> v2_start_bridge_to_node_v6;
|
|
|
+operation_func(all, start) -> v2_start_bridge_on_all_nodes_v6;
|
|
|
+operation_func(_Node, start) -> v2_start_bridge_on_node_v6;
|
|
|
operation_func(all, lookup) -> v2_lookup_from_all_nodes_v6;
|
|
|
operation_func(all, list) -> v2_list_bridges_on_nodes_v6;
|
|
|
operation_func(all, get_metrics) -> v2_get_metrics_from_all_nodes_v6.
|
|
|
@@ -825,7 +1131,7 @@ aggregate_status(AllStatus) ->
|
|
|
%% RPC Target
|
|
|
lookup_from_local_node(BridgeType, BridgeName) ->
|
|
|
case emqx_bridge_v2:lookup(BridgeType, BridgeName) of
|
|
|
- {ok, Res} -> {ok, format_resource(Res, node())};
|
|
|
+ {ok, Res} -> {ok, format_resource(?ROOT_KEY_ACTIONS, Res, node())};
|
|
|
Error -> Error
|
|
|
end.
|
|
|
|
|
|
@@ -833,7 +1139,7 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|
|
-spec lookup_from_local_node_v6(emqx_bridge_v2:root_cfg_key(), _, _) -> _.
|
|
|
lookup_from_local_node_v6(ConfRootKey, BridgeType, BridgeName) ->
|
|
|
case emqx_bridge_v2:lookup(ConfRootKey, BridgeType, BridgeName) of
|
|
|
- {ok, Res} -> {ok, format_resource(Res, node())};
|
|
|
+ {ok, Res} -> {ok, format_resource(ConfRootKey, Res, node())};
|
|
|
Error -> Error
|
|
|
end.
|
|
|
|
|
|
@@ -847,6 +1153,7 @@ get_metrics_from_local_node_v6(ConfRootKey, Type, Name) ->
|
|
|
|
|
|
%% resource
|
|
|
format_resource(
|
|
|
+ ConfRootKey,
|
|
|
#{
|
|
|
type := Type,
|
|
|
name := Name,
|
|
|
@@ -857,7 +1164,7 @@ format_resource(
|
|
|
},
|
|
|
Node
|
|
|
) ->
|
|
|
- RawConf = fill_defaults(Type, RawConf0),
|
|
|
+ RawConf = fill_defaults(ConfRootKey, Type, RawConf0),
|
|
|
redact(
|
|
|
maps:merge(
|
|
|
RawConf#{
|
|
|
@@ -988,17 +1295,18 @@ aggregate_metrics(
|
|
|
M17 + N17
|
|
|
).
|
|
|
|
|
|
-fill_defaults(Type, RawConf) ->
|
|
|
- PackedConf = pack_bridge_conf(Type, RawConf),
|
|
|
+fill_defaults(ConfRootKey, Type, RawConf) ->
|
|
|
+ PackedConf = pack_bridge_conf(ConfRootKey, Type, RawConf),
|
|
|
FullConf = emqx_config:fill_defaults(emqx_bridge_v2_schema, PackedConf, #{}),
|
|
|
- unpack_bridge_conf(Type, FullConf).
|
|
|
+ unpack_bridge_conf(ConfRootKey, Type, FullConf).
|
|
|
|
|
|
-pack_bridge_conf(Type, RawConf) ->
|
|
|
- #{<<"actions">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
|
|
+pack_bridge_conf(ConfRootKey, Type, RawConf) ->
|
|
|
+ #{bin(ConfRootKey) => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
|
|
|
|
|
-unpack_bridge_conf(Type, PackedConf) ->
|
|
|
+unpack_bridge_conf(ConfRootKey, Type, PackedConf) ->
|
|
|
+ ConfRootKeyBin = bin(ConfRootKey),
|
|
|
TypeBin = bin(Type),
|
|
|
- #{<<"actions">> := Bridges} = PackedConf,
|
|
|
+ #{ConfRootKeyBin := Bridges} = PackedConf,
|
|
|
#{<<"foo">> := RawConf} = maps:get(TypeBin, Bridges),
|
|
|
RawConf.
|
|
|
|