From 49fdfef8c36d7aecfd80d2e9768d05f8d0fd6a5b Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Fri, 10 Nov 2023 07:07:09 +0100 Subject: [PATCH] fix: azure event hub names are defined in one place --- apps/emqx_bridge/src/emqx_action_info.erl | 44 ++++--------------- .../src/emqx_bridge_azure_event_hub.erl | 9 ++++ ...mqx_bridge_azure_event_hub_action_info.erl | 18 ++++++++ 3 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub_action_info.erl diff --git a/apps/emqx_bridge/src/emqx_action_info.erl b/apps/emqx_bridge/src/emqx_action_info.erl index b4b6ed88e..0c247ac6f 100644 --- a/apps/emqx_bridge/src/emqx_action_info.erl +++ b/apps/emqx_bridge/src/emqx_action_info.erl @@ -41,7 +41,10 @@ -if(?EMQX_RELEASE_EDITION == ee). hard_coded_action_info_modules_ee() -> - [emqx_bridge_kafka_action_info]. + [ + emqx_bridge_kafka_action_info, + emqx_bridge_azure_event_hub_action_info + ]. -else. hard_coded_action_info_modules_ee() -> []. @@ -63,52 +66,30 @@ action_type_to_connector_type(Type) -> ActionInfoMap = info_map(), ActionTypeToConnectorTypeMap = maps:get(action_type_to_connector_type, ActionInfoMap), case maps:get(Type, ActionTypeToConnectorTypeMap, undefined) of - undefined -> action_type_to_connector_type_old(Type); + undefined -> Type; ConnectorType -> ConnectorType end. -% action_type_to_connector_type_old(kafka) -> -% %% backward compatible -% kafka_producer; -% action_type_to_connector_type_old(kafka_producer) -> -% kafka_producer; -action_type_to_connector_type_old(azure_event_hub_producer) -> - azure_event_hub_producer. - bridge_v1_type_to_action_type(Bin) when is_binary(Bin) -> bridge_v1_type_to_action_type(binary_to_existing_atom(Bin)); bridge_v1_type_to_action_type(Type) -> ActionInfoMap = info_map(), BridgeV1TypeToActionType = maps:get(bridge_v1_type_to_action_type, ActionInfoMap), case maps:get(Type, BridgeV1TypeToActionType, undefined) of - undefined -> bridge_v1_type_to_action_type_old(Type); + undefined -> Type; ActionType -> ActionType end. -% bridge_v1_type_to_action_type_old(kafka) -> -% kafka_producer; -% bridge_v1_type_to_action_type_old(kafka_producer) -> -% kafka_producer; -bridge_v1_type_to_action_type_old(azure_event_hub_producer) -> - azure_event_hub_producer; -bridge_v1_type_to_action_type_old(Type) -> - Type. - action_type_to_bridge_v1_type(Bin) when is_binary(Bin) -> action_type_to_bridge_v1_type(binary_to_existing_atom(Bin)); action_type_to_bridge_v1_type(Type) -> ActionInfoMap = info_map(), ActionTypeToBridgeV1Type = maps:get(action_type_to_bridge_v1_type, ActionInfoMap), case maps:get(Type, ActionTypeToBridgeV1Type, undefined) of - undefined -> action_type_to_bridge_v1_type_old(Type); + undefined -> Type; BridgeV1Type -> BridgeV1Type end. -action_type_to_bridge_v1_type_old(azure_event_hub_producer) -> - azure_event_hub_producer; -action_type_to_bridge_v1_type_old(Type) -> - Type. - %% This function should return true for all inputs that are bridge V1 types for %% bridges that have been refactored to bridge V2s, and for all all bridge V2 %% types. For everything else the function should return false. @@ -118,19 +99,10 @@ is_action_type(Type) -> ActionInfoMap = info_map(), ActionTypes = maps:get(action_type_names, ActionInfoMap), case maps:get(Type, ActionTypes, undefined) of - undefined -> is_action_type_old(Type); + undefined -> false; _ -> true end. -% is_action_type_old(kafka_producer) -> -% true; -% is_action_type_old(kafka) -> -% true; -is_action_type_old(azure_event_hub_producer) -> - true; -is_action_type_old(_) -> - false. - registered_schema_modules() -> InfoMap = info_map(), Schemas = maps:get(action_type_to_schema_module, InfoMap), diff --git a/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub.erl b/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub.erl index 6ae550a7f..eb364bdff 100644 --- a/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub.erl +++ b/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub.erl @@ -114,6 +114,15 @@ fields(kafka_message) -> Fields0 = emqx_bridge_kafka:fields(kafka_message), Fields = proplists:delete(timestamp, Fields0), override_documentations(Fields); +fields(action) -> + {azure_event_hub_producer, + mk( + hoconsc:map(name, ref(emqx_bridge_azure_event_hub, actions)), + #{ + desc => <<"Azure Event Hub Actions Config">>, + required => false + } + )}; fields(actions) -> Fields = override( diff --git a/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub_action_info.erl b/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub_action_info.erl new file mode 100644 index 000000000..f7a09c6d1 --- /dev/null +++ b/apps/emqx_bridge_azure_event_hub/src/emqx_bridge_azure_event_hub_action_info.erl @@ -0,0 +1,18 @@ +-module(emqx_bridge_azure_event_hub_action_info). + +-behaviour(emqx_action_info). + +-export([ + bridge_v1_type_name/0, + action_type_name/0, + connector_type_name/0, + schema_module/0 +]). + +bridge_v1_type_name() -> azure_event_hub_producer. + +action_type_name() -> azure_event_hub_producer. + +connector_type_name() -> azure_event_hub_producer. + +schema_module() -> emqx_bridge_azure_event_hub.