|
@@ -25,15 +25,39 @@
|
|
|
action_type_to_bridge_v1_type/1,
|
|
action_type_to_bridge_v1_type/1,
|
|
|
bridge_v1_type_to_action_type/1,
|
|
bridge_v1_type_to_action_type/1,
|
|
|
is_action_type/1,
|
|
is_action_type/1,
|
|
|
- registered_schema_modules/0
|
|
|
|
|
|
|
+ registered_schema_modules/0,
|
|
|
|
|
+ connector_action_config_to_bridge_v1_config/3,
|
|
|
|
|
+ has_custom_connector_action_config_to_bridge_v1_config/1,
|
|
|
|
|
+ bridge_v1_config_to_connector_config/2,
|
|
|
|
|
+ has_custom_bridge_v1_config_to_connector_config/1,
|
|
|
|
|
+ bridge_v1_config_to_action_config/3,
|
|
|
|
|
+ has_custom_bridge_v1_config_to_action_config/1,
|
|
|
|
|
+ transform_bridge_v1_config_to_action_config/4
|
|
|
]).
|
|
]).
|
|
|
|
|
|
|
|
-callback bridge_v1_type_name() -> atom().
|
|
-callback bridge_v1_type_name() -> atom().
|
|
|
-callback action_type_name() -> atom().
|
|
-callback action_type_name() -> atom().
|
|
|
-callback connector_type_name() -> atom().
|
|
-callback connector_type_name() -> atom().
|
|
|
-callback schema_module() -> atom().
|
|
-callback schema_module() -> atom().
|
|
|
|
|
+%% Define this if the automatic config downgrade is not enough for the bridge.
|
|
|
|
|
+-callback connector_action_config_to_bridge_v1_config(
|
|
|
|
|
+ ConnectorConfig :: map(), ActionConfig :: map()
|
|
|
|
|
+) -> map().
|
|
|
|
|
+%% Define this if the automatic config upgrade is not enough for the connector.
|
|
|
|
|
+-callback bridge_v1_config_to_connector_config(BridgeV1Config :: map()) -> map().
|
|
|
|
|
+%% Define this if the automatic config upgrade is not enough for the bridge.
|
|
|
|
|
+%% If you want to make use of the automatic config upgrade, you can call
|
|
|
|
|
+%% emqx_action_info:transform_bridge_v1_config_to_action_config/4 in your
|
|
|
|
|
+%% implementation and do some adjustments on the result.
|
|
|
|
|
+-callback bridge_v1_config_to_action_config(BridgeV1Config :: map(), ConnectorName :: binary()) ->
|
|
|
|
|
+ map().
|
|
|
|
|
|
|
|
--optional_callbacks([bridge_v1_type_name/0]).
|
|
|
|
|
|
|
+-optional_callbacks([
|
|
|
|
|
+ bridge_v1_type_name/0,
|
|
|
|
|
+ connector_action_config_to_bridge_v1_config/2,
|
|
|
|
|
+ bridge_v1_config_to_connector_config/1,
|
|
|
|
|
+ bridge_v1_config_to_action_config/2
|
|
|
|
|
+]).
|
|
|
|
|
|
|
|
%% ====================================================================
|
|
%% ====================================================================
|
|
|
%% Hadcoded list of info modules for actions
|
|
%% Hadcoded list of info modules for actions
|
|
@@ -110,10 +134,49 @@ registered_schema_modules() ->
|
|
|
Schemas = maps:get(action_type_to_schema_module, InfoMap),
|
|
Schemas = maps:get(action_type_to_schema_module, InfoMap),
|
|
|
maps:to_list(Schemas).
|
|
maps:to_list(Schemas).
|
|
|
|
|
|
|
|
|
|
+has_custom_connector_action_config_to_bridge_v1_config(ActionOrBridgeType) ->
|
|
|
|
|
+ Module = get_action_info_module(ActionOrBridgeType),
|
|
|
|
|
+ erlang:function_exported(Module, connector_action_config_to_bridge_v1_config, 2).
|
|
|
|
|
+
|
|
|
|
|
+connector_action_config_to_bridge_v1_config(ActionOrBridgeType, ConnectorConfig, ActionConfig) ->
|
|
|
|
|
+ Module = get_action_info_module(ActionOrBridgeType),
|
|
|
|
|
+ %% should only be called if defined
|
|
|
|
|
+ Module:connector_action_config_to_bridge_v1_config(ConnectorConfig, ActionConfig).
|
|
|
|
|
+
|
|
|
|
|
+has_custom_bridge_v1_config_to_connector_config(ActionOrBridgeType) ->
|
|
|
|
|
+ Module = get_action_info_module(ActionOrBridgeType),
|
|
|
|
|
+ erlang:function_exported(Module, bridge_v1_config_to_connector_config, 1).
|
|
|
|
|
+
|
|
|
|
|
+bridge_v1_config_to_connector_config(ActionOrBridgeType, BridgeV1Config) ->
|
|
|
|
|
+ Module = get_action_info_module(ActionOrBridgeType),
|
|
|
|
|
+ %% should only be called if defined
|
|
|
|
|
+ Module:bridge_v1_config_to_connector_config(BridgeV1Config).
|
|
|
|
|
+
|
|
|
|
|
+has_custom_bridge_v1_config_to_action_config(ActionOrBridgeType) ->
|
|
|
|
|
+ Module = get_action_info_module(ActionOrBridgeType),
|
|
|
|
|
+ erlang:function_exported(Module, bridge_v1_config_to_action_config, 2).
|
|
|
|
|
+
|
|
|
|
|
+bridge_v1_config_to_action_config(ActionOrBridgeType, BridgeV1Config, ConnectorName) ->
|
|
|
|
|
+ Module = get_action_info_module(ActionOrBridgeType),
|
|
|
|
|
+ %% should only be called if defined
|
|
|
|
|
+ Module:bridge_v1_config_to_action_config(BridgeV1Config, ConnectorName).
|
|
|
|
|
+
|
|
|
|
|
+transform_bridge_v1_config_to_action_config(
|
|
|
|
|
+ BridgeV1Conf, ConnectorName, ConnectorConfSchemaMod, ConnectorConfSchemaName
|
|
|
|
|
+) ->
|
|
|
|
|
+ emqx_connector_schema:transform_bridge_v1_config_to_action_config(
|
|
|
|
|
+ BridgeV1Conf, ConnectorName, ConnectorConfSchemaMod, ConnectorConfSchemaName
|
|
|
|
|
+ ).
|
|
|
|
|
+
|
|
|
%% ====================================================================
|
|
%% ====================================================================
|
|
|
%% Internal functions for building the info map and accessing it
|
|
%% Internal functions for building the info map and accessing it
|
|
|
%% ====================================================================
|
|
%% ====================================================================
|
|
|
|
|
|
|
|
|
|
+get_action_info_module(ActionOrBridgeType) ->
|
|
|
|
|
+ InfoMap = info_map(),
|
|
|
|
|
+ ActionInfoModuleMap = maps:get(action_type_to_info_module, InfoMap),
|
|
|
|
|
+ maps:get(ActionOrBridgeType, ActionInfoModuleMap, undefined).
|
|
|
|
|
+
|
|
|
internal_emqx_action_persistent_term_info_key() ->
|
|
internal_emqx_action_persistent_term_info_key() ->
|
|
|
?FUNCTION_NAME.
|
|
?FUNCTION_NAME.
|
|
|
|
|
|
|
@@ -161,7 +224,8 @@ initial_info_map() ->
|
|
|
bridge_v1_type_to_action_type => #{},
|
|
bridge_v1_type_to_action_type => #{},
|
|
|
action_type_to_bridge_v1_type => #{},
|
|
action_type_to_bridge_v1_type => #{},
|
|
|
action_type_to_connector_type => #{},
|
|
action_type_to_connector_type => #{},
|
|
|
- action_type_to_schema_module => #{}
|
|
|
|
|
|
|
+ action_type_to_schema_module => #{},
|
|
|
|
|
+ action_type_to_info_module => #{}
|
|
|
}.
|
|
}.
|
|
|
|
|
|
|
|
get_info_map(Module) ->
|
|
get_info_map(Module) ->
|
|
@@ -195,5 +259,10 @@ get_info_map(Module) ->
|
|
|
},
|
|
},
|
|
|
action_type_to_schema_module => #{
|
|
action_type_to_schema_module => #{
|
|
|
ActionType => Module:schema_module()
|
|
ActionType => Module:schema_module()
|
|
|
|
|
+ },
|
|
|
|
|
+ action_type_to_info_module => #{
|
|
|
|
|
+ ActionType => Module,
|
|
|
|
|
+ %% Alias the bridge V1 type to the action type
|
|
|
|
|
+ BridgeV1Type => Module
|
|
|
}
|
|
}
|
|
|
}.
|
|
}.
|