From b587ebac0c95adb939da0969e67d21a9cf6f4b9f Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Wed, 13 Mar 2024 11:22:32 -0300 Subject: [PATCH] fix(bridges): fix default value for `enable` when attempting operations Fixes https://emqx.atlassian.net/browse/EMQX-11999 Although the frontend doesn't send `enable` when creating a bridge/action/connector, the default value in the schema is `true`, so when attempting to fetch it from the raw config we should adhere to that default. --- apps/emqx_bridge/src/emqx_bridge_api.erl | 2 +- apps/emqx_bridge/src/emqx_bridge_v2_api.erl | 2 +- apps/emqx_connector/src/emqx_connector_api.erl | 2 +- changes/ce/fix-12696.en.md | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changes/ce/fix-12696.en.md diff --git a/apps/emqx_bridge/src/emqx_bridge_api.erl b/apps/emqx_bridge/src/emqx_bridge_api.erl index 69b17a8433..5a862c492f 100644 --- a/apps/emqx_bridge/src/emqx_bridge_api.erl +++ b/apps/emqx_bridge/src/emqx_bridge_api.erl @@ -764,7 +764,7 @@ is_bridge_enabled_v1(BridgeType, BridgeName) -> %% we read from the translated config because the defaults are populated here. try emqx:get_config([bridges, BridgeType, binary_to_existing_atom(BridgeName)]) of ConfMap -> - maps:get(enable, ConfMap, false) + maps:get(enable, ConfMap, true) catch error:{config_not_found, _} -> throw(not_found); diff --git a/apps/emqx_bridge/src/emqx_bridge_v2_api.erl b/apps/emqx_bridge/src/emqx_bridge_v2_api.erl index 92c0b43a02..b54bd21e53 100644 --- a/apps/emqx_bridge/src/emqx_bridge_v2_api.erl +++ b/apps/emqx_bridge/src/emqx_bridge_v2_api.erl @@ -990,7 +990,7 @@ call_operation_if_enabled(NodeOrAll, OperFunc, [Nodes, ConfRootKey, BridgeType, is_enabled_bridge(ConfRootKey, BridgeType, BridgeName) -> try emqx_bridge_v2:lookup(ConfRootKey, BridgeType, binary_to_existing_atom(BridgeName)) of {ok, #{raw_config := ConfMap}} -> - maps:get(<<"enable">>, ConfMap, false); + maps:get(<<"enable">>, ConfMap, true); {error, not_found} -> throw(not_found) catch diff --git a/apps/emqx_connector/src/emqx_connector_api.erl b/apps/emqx_connector/src/emqx_connector_api.erl index e3aa6abf5e..97f68b7ef7 100644 --- a/apps/emqx_connector/src/emqx_connector_api.erl +++ b/apps/emqx_connector/src/emqx_connector_api.erl @@ -532,7 +532,7 @@ call_operation_if_enabled(NodeOrAll, OperFunc, [Nodes, BridgeType, BridgeName]) is_enabled_connector(ConnectorType, ConnectorName) -> try emqx:get_config([connectors, ConnectorType, binary_to_existing_atom(ConnectorName)]) of ConfMap -> - maps:get(enable, ConfMap, false) + maps:get(enable, ConfMap, true) catch error:{config_not_found, _} -> throw(not_found); diff --git a/changes/ce/fix-12696.en.md b/changes/ce/fix-12696.en.md new file mode 100644 index 0000000000..0adffcf998 --- /dev/null +++ b/changes/ce/fix-12696.en.md @@ -0,0 +1 @@ +Fixed an issue where attempting to reconnect an action or source could lead to the wrong error message being returned in the HTTP API.