fix(ftschema): ensure `translate` follow `emqx_config` behavior

So that atom keys won't unexpectedly get to converters / validators.
This commit is contained in:
Andrew Mayorov 2023-06-08 08:13:42 +03:00
parent ae97d516b8
commit e3c16be3c4
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
1 changed files with 4 additions and 12 deletions

View File

@ -288,12 +288,7 @@ validator(filename) ->
]; ];
validator(backend) -> validator(backend) ->
fun(Config) -> fun(Config) ->
Enabled = maps:filter( Enabled = maps:filter(fun(_, #{<<"enable">> := E}) -> E end, Config),
fun(_, Backend) ->
maps:get(enable, Backend, false) or maps:get(<<"enable">>, Backend, false)
end,
Config
),
case maps:to_list(Enabled) of case maps:to_list(Enabled) of
[{_Type, _BackendConfig}] -> [{_Type, _BackendConfig}] ->
ok; ok;
@ -334,12 +329,9 @@ ref(Ref) ->
translate(Conf) -> translate(Conf) ->
[Root] = roots(), [Root] = roots(),
maps:get( RootRaw = atom_to_binary(Root),
Root, ConfChecked = hocon_tconf:check_plain(?MODULE, #{RootRaw => Conf}, #{}, [Root]),
hocon_tconf:check_plain( emqx_utils_maps:unsafe_atom_key_map(maps:get(RootRaw, ConfChecked)).
?MODULE, #{atom_to_binary(Root) => Conf}, #{atom_key => true}, [Root]
)
).
-spec backend(emqx_config:config()) -> -spec backend(emqx_config:config()) ->
{_Type :: atom(), emqx_config:config()}. {_Type :: atom(), emqx_config:config()}.