Parcourir la source

fix: check connector and bridge_v2 with the right schema

zhongwencool il y a 2 ans
Parent
commit
c67f2130f2

+ 14 - 5
apps/emqx_bridge/src/emqx_bridge_v2.erl

@@ -1596,12 +1596,14 @@ split_and_validate_bridge_v1_config(BridgeV1Type, BridgeName, RawConf, PreviousR
             Output
         ),
     %% Validate the connector config and the bridge_v2 config
-    NewFakeGlobalConfig = #{
+    NewFakeConnectorConfig = #{
         <<"connectors">> => #{
             bin(ConnectorType) => #{
                 bin(ConnectorName) => NewConnectorRawConf
             }
-        },
+        }
+    },
+    NewFakeBridgeV2Config = #{
         ConfRootKey => #{
             bin(BridgeV2Type) => #{
                 bin(BridgeName) => NewBridgeV2RawConf
@@ -1610,8 +1612,13 @@ split_and_validate_bridge_v1_config(BridgeV1Type, BridgeName, RawConf, PreviousR
     },
     try
         hocon_tconf:check_plain(
-            emqx_schema,
-            NewFakeGlobalConfig,
+            emqx_connector_schema,
+            NewFakeConnectorConfig,
+            #{atom_key => false, required => false}
+        ),
+        hocon_tconf:check_plain(
+            emqx_bridge_v2_schema,
+            NewFakeBridgeV2Config,
             #{atom_key => false, required => false}
         )
     of
@@ -1627,8 +1634,10 @@ split_and_validate_bridge_v1_config(BridgeV1Type, BridgeName, RawConf, PreviousR
             }
     catch
         %% validation errors
+        throw:{_Module, [Reason1 | _]} ->
+            throw(Reason1);
         throw:Reason1 ->
-            {error, Reason1}
+            throw(Reason1)
     end.
 
 get_conf_root_key(#{<<"actions">> := _}) ->

+ 1 - 1
apps/emqx_resource/include/emqx_resource.hrl

@@ -154,7 +154,7 @@
 %% boolean
 -define(START_AFTER_CREATED, true).
 
--define(TEST_ID_PREFIX, "_probe_:").
+-define(TEST_ID_PREFIX, "probe__").
 -define(RES_METRICS, resource_metrics).
 
 -define(RESOURCE_ALLOCATION_TAB, emqx_resource_allocations).

+ 5 - 0
apps/emqx_resource/src/emqx_resource.erl

@@ -84,6 +84,7 @@
     get_allocated_resources/1,
     get_allocated_resources_list/1,
     forget_allocated_resources/1,
+    deallocate_resource/2,
     %% Get channel config from resource
     call_get_channel_config/3
 ]).
@@ -650,6 +651,10 @@ forget_allocated_resources(InstanceId) ->
     true = ets:delete(?RESOURCE_ALLOCATION_TAB, InstanceId),
     ok.
 
+deallocate_resource(InstanceId, Key) ->
+    true = ets:match_delete(?RESOURCE_ALLOCATION_TAB, {InstanceId, Key, '_'}),
+    ok.
+
 -spec create_metrics(resource_id()) -> ok.
 create_metrics(ResId) ->
     emqx_metrics_worker:create_metrics(