fix(http_bridge_schema): use correct `resource_opts` subfields for connector and action
This commit is contained in:
parent
593283df93
commit
30719d286a
|
@ -69,13 +69,23 @@ connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) ->
|
||||||
bridge_v1_config_to_connector_config(BridgeV1Conf) ->
|
bridge_v1_config_to_connector_config(BridgeV1Conf) ->
|
||||||
%% To statisfy the emqx_bridge_api_SUITE:t_http_crud_apis/1
|
%% To statisfy the emqx_bridge_api_SUITE:t_http_crud_apis/1
|
||||||
ok = validate_webhook_url(maps:get(<<"url">>, BridgeV1Conf, undefined)),
|
ok = validate_webhook_url(maps:get(<<"url">>, BridgeV1Conf, undefined)),
|
||||||
maps:without(?REMOVED_KEYS ++ ?ACTION_KEYS ++ ?PARAMETER_KEYS, BridgeV1Conf).
|
ConnectorConfig0 = maps:without(?REMOVED_KEYS ++ ?ACTION_KEYS ++ ?PARAMETER_KEYS, BridgeV1Conf),
|
||||||
|
emqx_utils_maps:update_if_present(
|
||||||
|
<<"resource_opts">>,
|
||||||
|
fun emqx_connector_schema:project_to_connector_resource_opts/1,
|
||||||
|
ConnectorConfig0
|
||||||
|
).
|
||||||
|
|
||||||
bridge_v1_config_to_action_config(BridgeV1Conf, ConnectorName) ->
|
bridge_v1_config_to_action_config(BridgeV1Conf, ConnectorName) ->
|
||||||
Parameters = maps:with(?PARAMETER_KEYS, BridgeV1Conf),
|
Parameters = maps:with(?PARAMETER_KEYS, BridgeV1Conf),
|
||||||
Parameters1 = Parameters#{<<"path">> => <<>>, <<"headers">> => #{}},
|
Parameters1 = Parameters#{<<"path">> => <<>>, <<"headers">> => #{}},
|
||||||
CommonKeys = [<<"enable">>, <<"description">>],
|
CommonKeys = [<<"enable">>, <<"description">>],
|
||||||
ActionConfig = maps:with(?ACTION_KEYS ++ CommonKeys, BridgeV1Conf),
|
ActionConfig0 = maps:with(?ACTION_KEYS ++ CommonKeys, BridgeV1Conf),
|
||||||
|
ActionConfig = emqx_utils_maps:update_if_present(
|
||||||
|
<<"resource_opts">>,
|
||||||
|
fun emqx_bridge_v2_schema:project_to_actions_resource_opts/1,
|
||||||
|
ActionConfig0
|
||||||
|
),
|
||||||
ActionConfig#{<<"parameters">> => Parameters1, <<"connector">> => ConnectorName}.
|
ActionConfig#{<<"parameters">> => Parameters1, <<"connector">> => ConnectorName}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -48,7 +48,15 @@ fields("get") ->
|
||||||
%%--- v1 bridges config file
|
%%--- v1 bridges config file
|
||||||
%% see: emqx_bridge_schema:fields(bridges)
|
%% see: emqx_bridge_schema:fields(bridges)
|
||||||
fields("config") ->
|
fields("config") ->
|
||||||
basic_config() ++ request_config();
|
basic_config() ++
|
||||||
|
request_config() ++
|
||||||
|
emqx_connector_schema:resource_opts_ref(?MODULE, "v1_resource_opts");
|
||||||
|
fields("v1_resource_opts") ->
|
||||||
|
UnsupportedOpts = [enable_batch, batch_size, batch_time],
|
||||||
|
lists:filter(
|
||||||
|
fun({K, _V}) -> not lists:member(K, UnsupportedOpts) end,
|
||||||
|
emqx_resource_schema:fields("creation_opts")
|
||||||
|
);
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% v2: configuration
|
%% v2: configuration
|
||||||
fields(action) ->
|
fields(action) ->
|
||||||
|
@ -89,7 +97,13 @@ fields("http_action") ->
|
||||||
required => true,
|
required => true,
|
||||||
desc => ?DESC("config_parameters_opts")
|
desc => ?DESC("config_parameters_opts")
|
||||||
})}
|
})}
|
||||||
] ++ http_resource_opts();
|
] ++ emqx_connector_schema:resource_opts_ref(?MODULE, action_resource_opts);
|
||||||
|
fields(action_resource_opts) ->
|
||||||
|
UnsupportedOpts = [batch_size, batch_time],
|
||||||
|
lists:filter(
|
||||||
|
fun({K, _V}) -> not lists:member(K, UnsupportedOpts) end,
|
||||||
|
emqx_bridge_v2_schema:resource_opts_fields()
|
||||||
|
);
|
||||||
fields("parameters_opts") ->
|
fields("parameters_opts") ->
|
||||||
[
|
[
|
||||||
{path,
|
{path,
|
||||||
|
@ -129,20 +143,20 @@ fields("config_connector") ->
|
||||||
}
|
}
|
||||||
)},
|
)},
|
||||||
{description, emqx_schema:description_schema()}
|
{description, emqx_schema:description_schema()}
|
||||||
] ++ connector_url_headers() ++ connector_opts();
|
] ++ connector_url_headers() ++
|
||||||
%%--------------------------------------------------------------------
|
connector_opts() ++
|
||||||
%% v1/v2
|
emqx_connector_schema:resource_opts_ref(?MODULE, connector_resource_opts);
|
||||||
fields("resource_opts") ->
|
fields(connector_resource_opts) ->
|
||||||
UnsupportedOpts = [enable_batch, batch_size, batch_time],
|
emqx_connector_schema:resource_opts_fields().
|
||||||
lists:filter(
|
|
||||||
fun({K, _V}) -> not lists:member(K, UnsupportedOpts) end,
|
|
||||||
emqx_resource_schema:fields("creation_opts")
|
|
||||||
).
|
|
||||||
|
|
||||||
desc("config") ->
|
desc("config") ->
|
||||||
?DESC("desc_config");
|
?DESC("desc_config");
|
||||||
desc("resource_opts") ->
|
desc("v1_resource_opts") ->
|
||||||
?DESC(emqx_resource_schema, "creation_opts");
|
?DESC(emqx_resource_schema, "creation_opts");
|
||||||
|
desc(connector_resource_opts) ->
|
||||||
|
?DESC(emqx_resource_schema, "resource_opts");
|
||||||
|
desc(action_resource_opts) ->
|
||||||
|
?DESC(emqx_resource_schema, "resource_opts");
|
||||||
desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" ->
|
desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" ->
|
||||||
["Configuration for WebHook using `", string:to_upper(Method), "` method."];
|
["Configuration for WebHook using `", string:to_upper(Method), "` method."];
|
||||||
desc("config_connector") ->
|
desc("config_connector") ->
|
||||||
|
@ -304,23 +318,10 @@ request_timeout_field() ->
|
||||||
}
|
}
|
||||||
)}.
|
)}.
|
||||||
|
|
||||||
http_resource_opts() ->
|
|
||||||
[
|
|
||||||
{resource_opts,
|
|
||||||
mk(
|
|
||||||
ref(?MODULE, "resource_opts"),
|
|
||||||
#{
|
|
||||||
required => false,
|
|
||||||
default => #{},
|
|
||||||
desc => ?DESC(emqx_resource_schema, <<"resource_opts">>)
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
].
|
|
||||||
|
|
||||||
connector_opts() ->
|
connector_opts() ->
|
||||||
mark_request_field_deperecated(
|
mark_request_field_deperecated(
|
||||||
proplists:delete(max_retries, emqx_bridge_http_connector:fields(config))
|
proplists:delete(max_retries, emqx_bridge_http_connector:fields(config))
|
||||||
) ++ http_resource_opts().
|
).
|
||||||
|
|
||||||
mark_request_field_deperecated(Fields) ->
|
mark_request_field_deperecated(Fields) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
|
|
Loading…
Reference in New Issue