Skip to content

Commit

Permalink
Merge pull request #12600 from zhongwencool/fix-schema-check
Browse files Browse the repository at this point in the history
Fix bridge v2 and connector schema check
  • Loading branch information
zhongwencool committed Feb 27, 2024
2 parents 9ae7ac0 + 54c542c commit d34a1e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 0 additions & 3 deletions apps/emqx_bridge/src/emqx_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@

-define(ROOT_KEY, bridges).

%% See `hocon_tconf`
-define(MAP_KEY_RE, <<"^[A-Za-z0-9]+[A-Za-z0-9-_]*$">>).

load() ->
Bridges = emqx:get_config([?ROOT_KEY], #{}),
emqx_utils:pforeach(
Expand Down
21 changes: 15 additions & 6 deletions apps/emqx_bridge/src/emqx_bridge_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1596,22 +1596,29 @@ 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
}
}
},
try
hocon_tconf:check_plain(
emqx_schema,
NewFakeGlobalConfig,
_ = hocon_tconf:check_plain(
emqx_connector_schema,
NewFakeConnectorConfig,
#{atom_key => false, required => false}
),
_ = hocon_tconf:check_plain(
emqx_bridge_v2_schema,
NewFakeBridgeV2Config,
#{atom_key => false, required => false}
)
of
Expand All @@ -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">> := _}) ->
Expand Down
4 changes: 3 additions & 1 deletion apps/emqx_resource/include/emqx_resource.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@
%% boolean
-define(START_AFTER_CREATED, true).

-define(TEST_ID_PREFIX, "_probe_:").
%% Keep this test_id_prefix is match "^[A-Za-z0-9]+[A-Za-z0-9-_]*$".
%% See `hocon_tconf`
-define(TEST_ID_PREFIX, "t_probe_").
-define(RES_METRICS, resource_metrics).

-define(RESOURCE_ALLOCATION_TAB, emqx_resource_allocations).
5 changes: 5 additions & 0 deletions apps/emqx_resource/src/emqx_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
]).
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d34a1e9

Please sign in to comment.