fix(emqx_bridge_mongodb): use correct config when calling downgrade_type

Also limit result in mongodb ..._to_bridge_v1_config to not include more fields
than what's in the schema (most notably `description`).
This commit is contained in:
Stefan Strigler 2023-12-11 14:08:45 +01:00
parent 5d7ae4b980
commit 6143b3a2be
3 changed files with 13 additions and 10 deletions

View File

@ -913,7 +913,7 @@ format_resource(
redact( redact(
maps:merge( maps:merge(
RawConfFull#{ RawConfFull#{
type => downgrade_type(Type, RawConf), type => downgrade_type(Type, emqx_bridge_lib:get_conf(Type, BridgeName)),
name => maps:get(<<"name">>, RawConf, BridgeName), name => maps:get(<<"name">>, RawConf, BridgeName),
node => Node node => Node
}, },

View File

@ -18,7 +18,8 @@
-export([ -export([
maybe_withdraw_rule_action/3, maybe_withdraw_rule_action/3,
upgrade_type/1, upgrade_type/1,
downgrade_type/2 downgrade_type/2,
get_conf/2
]). ]).
%% @doc A bridge can be used as a rule action. %% @doc A bridge can be used as a rule action.

View File

@ -26,19 +26,21 @@
-define(SCHEMA_MODULE, emqx_bridge_mongodb). -define(SCHEMA_MODULE, emqx_bridge_mongodb).
connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig) -> connector_action_config_to_bridge_v1_config(
fix_v1_type( #{<<"parameters">> := #{<<"mongo_type">> := MongoType}} = ConnectorConfig,
maps:merge( ActionConfig
) ->
MergedConfig =
emqx_utils_maps:deep_merge(
maps:without( maps:without(
[<<"connector">>], [<<"connector">>],
emqx_utils_maps:unindent(<<"parameters">>, ActionConfig) emqx_utils_maps:unindent(<<"parameters">>, ActionConfig)
), ),
emqx_utils_maps:unindent(<<"parameters">>, ConnectorConfig) emqx_utils_maps:unindent(<<"parameters">>, ConnectorConfig)
) ),
). BridgeV1Type = v1_type(MongoType),
BridgeV1Keys = schema_keys(BridgeV1Type),
fix_v1_type(#{<<"mongo_type">> := MongoType} = Conf) -> maps:with(BridgeV1Keys, MergedConfig).
Conf#{<<"type">> => v1_type(MongoType)}.
bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) -> bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName) ->
ActionTopLevelKeys = schema_keys(mongodb_action), ActionTopLevelKeys = schema_keys(mongodb_action),