Merge pull request #6881 from zmstone/refactor-upgrade-hocon-0.23.0
refactor: upgrade to hocon 0.23.0
This commit is contained in:
commit
d6f7ffec3c
|
@ -19,7 +19,7 @@
|
|||
, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.0"}}}
|
||||
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.11.3"}}}
|
||||
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.0"}}}
|
||||
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.2"}}}
|
||||
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.23.0"}}}
|
||||
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}
|
||||
, {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}
|
||||
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
|
||||
|
|
|
@ -155,8 +155,8 @@ do_check_config(Type, Config, Module) ->
|
|||
fun(C) ->
|
||||
Key = list_to_binary(?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME),
|
||||
AtomKey = list_to_atom(?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME),
|
||||
R = hocon_schema:check_plain(Module, #{Key => C},
|
||||
#{atom_key => true}),
|
||||
R = hocon_tconf:check_plain(Module, #{Key => C},
|
||||
#{atom_key => true}),
|
||||
maps:get(AtomKey, R)
|
||||
end
|
||||
end,
|
||||
|
|
|
@ -236,7 +236,7 @@ get_raw(KeyPath, Default) -> do_get(?RAW_CONF, KeyPath, Default).
|
|||
put_raw(Config) ->
|
||||
maps:fold(fun(RootName, RootV, _) ->
|
||||
?MODULE:put_raw([RootName], RootV)
|
||||
end, ok, hocon_schema:get_value([], Config)).
|
||||
end, ok, hocon_maps:ensure_plain(Config)).
|
||||
|
||||
-spec put_raw(emqx_map_lib:config_key_path(), term()) -> ok.
|
||||
put_raw(KeyPath, Config) -> do_put(?RAW_CONF, KeyPath, Config).
|
||||
|
@ -299,7 +299,7 @@ merge_envs(SchemaMod, RawConf) ->
|
|||
format => map,
|
||||
apply_override_envs => true
|
||||
},
|
||||
hocon_schema:merge_env_overrides(SchemaMod, RawConf, all, Opts).
|
||||
hocon_tconf:merge_env_overrides(SchemaMod, RawConf, all, Opts).
|
||||
|
||||
-spec check_config(module(), raw_config()) -> {AppEnvs, CheckedConf}
|
||||
when AppEnvs :: app_envs(), CheckedConf :: config().
|
||||
|
@ -313,7 +313,7 @@ check_config(SchemaMod, RawConf, Opts0) ->
|
|||
},
|
||||
Opts = maps:merge(Opts0, Opts1),
|
||||
{AppEnvs, CheckedConf} =
|
||||
hocon_schema:map_translate(SchemaMod, RawConf, Opts),
|
||||
hocon_tconf:map_translate(SchemaMod, RawConf, Opts),
|
||||
{AppEnvs, emqx_map_lib:unsafe_atom_key_map(CheckedConf)}.
|
||||
|
||||
-spec fill_defaults(raw_config()) -> map().
|
||||
|
@ -330,7 +330,7 @@ fill_defaults(RawConf) ->
|
|||
|
||||
-spec fill_defaults(module(), raw_config()) -> map().
|
||||
fill_defaults(SchemaMod, RawConf) ->
|
||||
hocon_schema:check_plain(SchemaMod, RawConf,
|
||||
hocon_tconf:check_plain(SchemaMod, RawConf,
|
||||
#{nullable => true, only_fill_defaults => true},
|
||||
root_names_from_conf(RawConf)).
|
||||
|
||||
|
|
|
@ -1166,7 +1166,7 @@ base_listener() ->
|
|||
%% utils
|
||||
-spec(conf_get(string() | [string()], hocon:config()) -> term()).
|
||||
conf_get(Key, Conf) ->
|
||||
V = hocon_schema:get_value(Key, Conf),
|
||||
V = hocon_maps:get(Key, Conf),
|
||||
case is_binary(V) of
|
||||
true ->
|
||||
binary_to_list(V);
|
||||
|
@ -1175,7 +1175,7 @@ conf_get(Key, Conf) ->
|
|||
end.
|
||||
|
||||
conf_get(Key, Conf, Default) ->
|
||||
V = hocon_schema:get_value(Key, Conf, Default),
|
||||
V = hocon_maps:get(Key, Conf, Default),
|
||||
case is_binary(V) of
|
||||
true ->
|
||||
binary_to_list(V);
|
||||
|
|
|
@ -59,8 +59,8 @@ enable(_) -> undefined.
|
|||
|
||||
check_config(C) ->
|
||||
#{config := R} =
|
||||
hocon_schema:check_plain(?MODULE, #{<<"config">> => C},
|
||||
#{atom_key => true}),
|
||||
hocon_tconf:check_plain(?MODULE, #{<<"config">> => C},
|
||||
#{atom_key => true}),
|
||||
R.
|
||||
|
||||
create(_AuthenticatorID, _Config) ->
|
||||
|
|
|
@ -199,7 +199,7 @@ read_schema_configs(Schema, ConfigFile) ->
|
|||
|
||||
generate_config(SchemaModule, ConfigFile) when is_atom(SchemaModule) ->
|
||||
{ok, Conf0} = hocon:load(ConfigFile, #{format => richmap}),
|
||||
hocon_schema:generate(SchemaModule, Conf0).
|
||||
hocon_tconf:generate(SchemaModule, Conf0).
|
||||
|
||||
-spec(stop_apps(list()) -> ok).
|
||||
stop_apps(Apps) ->
|
||||
|
|
|
@ -138,7 +138,7 @@ mustache_vars() ->
|
|||
generate_config() ->
|
||||
ConfFile = render_config_file(),
|
||||
{ok, Conf} = hocon:load(ConfFile, #{format => richmap}),
|
||||
hocon_schema:generate(emqx_schema, Conf).
|
||||
hocon_tconf:generate(emqx_schema, Conf).
|
||||
|
||||
set_app_env({App, Lists}) ->
|
||||
lists:foreach(fun({authz_file, _Var}) ->
|
||||
|
|
|
@ -81,15 +81,15 @@ validate(Schema, Data0) ->
|
|||
, keyfile => <<"keyfile">>
|
||||
},
|
||||
#{ssl_opts := Checked} =
|
||||
hocon_schema:check_plain(Sc, #{<<"ssl_opts">> => Data},
|
||||
#{atom_key => true}),
|
||||
hocon_tconf:check_plain(Sc, #{<<"ssl_opts">> => Data},
|
||||
#{atom_key => true}),
|
||||
Checked.
|
||||
|
||||
ciperhs_schema_test() ->
|
||||
Sc = emqx_schema:ciphers_schema(undefined),
|
||||
WSc = #{roots => [{ciphers, Sc}]},
|
||||
?assertThrow({_, [{validation_error, _}]},
|
||||
hocon_schema:check_plain(WSc, #{<<"ciphers">> => <<"foo,bar">>})).
|
||||
hocon_tconf:check_plain(WSc, #{<<"ciphers">> => <<"foo,bar">>})).
|
||||
|
||||
bad_tls_version_test() ->
|
||||
Sc = emqx_schema:server_ssl_opts_schema(#{}, false),
|
||||
|
|
|
@ -59,8 +59,8 @@ do_check_config(#{<<"mechanism">> := Mec} = Config, Opts) ->
|
|||
false ->
|
||||
throw({unknown_handler, Key});
|
||||
{_, ProviderModule} ->
|
||||
hocon_schema:check_plain(ProviderModule, #{?CONF_NS_BINARY => Config},
|
||||
Opts#{atom_key => true})
|
||||
hocon_tconf:check_plain(ProviderModule, #{?CONF_NS_BINARY => Config},
|
||||
Opts#{atom_key => true})
|
||||
end.
|
||||
|
||||
atom(Bin) ->
|
||||
|
|
|
@ -332,4 +332,4 @@ to_bin(L) when is_list(L) ->
|
|||
list_to_binary(L).
|
||||
|
||||
get_conf_val(Name, Conf) ->
|
||||
hocon_schema:get_value(?CONF_NS ++ "." ++ Name, Conf).
|
||||
hocon_maps:get(?CONF_NS ++ "." ++ Name, Conf).
|
||||
|
|
|
@ -62,7 +62,7 @@ t_check_schema(_Config) ->
|
|||
}
|
||||
},
|
||||
|
||||
hocon_schema:check_plain(emqx_authn_mnesia, ?CONF(ConfigOk)),
|
||||
hocon_tconf:check_plain(emqx_authn_mnesia, ?CONF(ConfigOk)),
|
||||
|
||||
ConfigNotOk = #{
|
||||
<<"mechanism">> => <<"password-based">>,
|
||||
|
@ -76,7 +76,7 @@ t_check_schema(_Config) ->
|
|||
?assertException(
|
||||
throw,
|
||||
{emqx_authn_mnesia, _},
|
||||
hocon_schema:check_plain(emqx_authn_mnesia, ?CONF(ConfigNotOk))).
|
||||
hocon_tconf:check_plain(emqx_authn_mnesia, ?CONF(ConfigNotOk))).
|
||||
|
||||
t_create(_) ->
|
||||
Config0 = config(),
|
||||
|
|
|
@ -320,7 +320,7 @@ do_authorize(Client, PubSub, Topic,
|
|||
check_sources(RawSources) ->
|
||||
Schema = #{roots => emqx_authz_schema:fields("authorization"), fields => #{}},
|
||||
Conf = #{<<"sources">> => RawSources},
|
||||
#{sources := Sources} = hocon_schema:check_plain(Schema, Conf, #{atom_key => true}),
|
||||
#{sources := Sources} = hocon_tconf:check_plain(Schema, Conf, #{atom_key => true}),
|
||||
Sources.
|
||||
|
||||
take(Type) -> take(Type, lookup()).
|
||||
|
|
|
@ -415,7 +415,7 @@ get_raw_sources() ->
|
|||
Schema = #{roots => emqx_authz_schema:fields("authorization"), fields => #{}},
|
||||
Conf = #{<<"sources">> => RawSources},
|
||||
Options = #{only_fill_defaults => true},
|
||||
#{<<"sources">> := Sources} = hocon_schema:check_plain(Schema, Conf, Options),
|
||||
#{<<"sources">> := Sources} = hocon_tconf:check_plain(Schema, Conf, Options),
|
||||
merge_default_headers(Sources).
|
||||
|
||||
merge_default_headers(Sources) ->
|
||||
|
|
|
@ -211,9 +211,9 @@ check_ssl_opts(Conf)
|
|||
when Conf =:= #{} ->
|
||||
true;
|
||||
check_ssl_opts(Conf) ->
|
||||
case emqx_authz_http:parse_url(hocon_schema:get_value("config.url", Conf)) of
|
||||
case emqx_authz_http:parse_url(hocon_maps:get("config.url", Conf)) of
|
||||
#{scheme := https} ->
|
||||
case hocon_schema:get_value("config.ssl.enable", Conf) of
|
||||
case hocon_maps:get("config.ssl.enable", Conf) of
|
||||
true -> ok;
|
||||
false -> false
|
||||
end;
|
||||
|
@ -225,8 +225,8 @@ check_headers(Conf)
|
|||
when Conf =:= #{} ->
|
||||
true;
|
||||
check_headers(Conf) ->
|
||||
Method = to_bin(hocon_schema:get_value("config.method", Conf)),
|
||||
Headers = hocon_schema:get_value("config.headers", Conf),
|
||||
Method = to_bin(hocon_maps:get("config.method", Conf)),
|
||||
Headers = hocon_maps:get("config.headers", Conf),
|
||||
Method =:= <<"post">> orelse (not lists:member(<<"content-type">>, Headers)).
|
||||
|
||||
union_array(Item) when is_list(Item) ->
|
||||
|
|
|
@ -757,10 +757,10 @@ sort_log_levels(Levels) ->
|
|||
%% utils
|
||||
-spec(conf_get(string() | [string()], hocon:config()) -> term()).
|
||||
conf_get(Key, Conf) ->
|
||||
ensure_list(hocon_schema:get_value(Key, Conf)).
|
||||
ensure_list(hocon_maps:get(Key, Conf)).
|
||||
|
||||
conf_get(Key, Conf, Default) ->
|
||||
ensure_list(hocon_schema:get_value(Key, Conf, Default)).
|
||||
ensure_list(hocon_maps:get(Key, Conf, Default)).
|
||||
|
||||
filter(Opts) ->
|
||||
[{K, V} || {K, V} <- Opts, V =/= undefined].
|
||||
|
|
|
@ -313,8 +313,8 @@ check_ssl_opts(Conf) ->
|
|||
check_ssl_opts("base_url", Conf).
|
||||
|
||||
check_ssl_opts(URLFrom, Conf) ->
|
||||
#{scheme := Scheme} = hocon_schema:get_value(URLFrom, Conf),
|
||||
SSL= hocon_schema:get_value("ssl", Conf),
|
||||
#{scheme := Scheme} = hocon_maps:get(URLFrom, Conf),
|
||||
SSL= hocon_maps:get("ssl", Conf),
|
||||
case {Scheme, maps:get(enable, SSL, false)} of
|
||||
{http, false} -> true;
|
||||
{https, true} -> true;
|
||||
|
|
|
@ -147,10 +147,10 @@ translate_req(Request, #{module := Module, path := Path, method := Method}, Chec
|
|||
end.
|
||||
|
||||
check_and_translate(Schema, Map, Opts) ->
|
||||
hocon_schema:check_plain(Schema, Map, Opts).
|
||||
hocon_tconf:check_plain(Schema, Map, Opts).
|
||||
|
||||
check_only(Schema, Map, Opts) ->
|
||||
_ = hocon_schema:check_plain(Schema, Map, Opts),
|
||||
_ = hocon_tconf:check_plain(Schema, Map, Opts),
|
||||
Map.
|
||||
|
||||
support_check_schema(#{check_schema := true, translate_body := true}) ->
|
||||
|
@ -199,12 +199,12 @@ check_parameter([{Name, Type} | Spec], Bindings, QueryStr, Module, BindingsAcc,
|
|||
case hocon_schema:field_schema(Type, in) of
|
||||
path ->
|
||||
Option = #{atom_key => true},
|
||||
NewBindings = hocon_schema:check_plain(Schema, Bindings, Option),
|
||||
NewBindings = hocon_tconf:check_plain(Schema, Bindings, Option),
|
||||
NewBindingsAcc = maps:merge(BindingsAcc, NewBindings),
|
||||
check_parameter(Spec, Bindings, QueryStr, Module, NewBindingsAcc, QueryStrAcc);
|
||||
query ->
|
||||
Option = #{},
|
||||
NewQueryStr = hocon_schema:check_plain(Schema, QueryStr, Option),
|
||||
NewQueryStr = hocon_tconf:check_plain(Schema, QueryStr, Option),
|
||||
NewQueryStrAcc = maps:merge(QueryStrAcc, NewQueryStr),
|
||||
check_parameter(Spec, Bindings, QueryStr, Module,BindingsAcc, NewQueryStrAcc)
|
||||
end.
|
||||
|
|
|
@ -322,7 +322,7 @@ do_read_plugin({file, InfoFile}) ->
|
|||
[_, NameVsn | _] = lists:reverse(filename:split(InfoFile)),
|
||||
case hocon:load(InfoFile, #{format => richmap}) of
|
||||
{ok, RichMap} ->
|
||||
Info = check_plugin(hocon_util:richmap_to_map(RichMap), NameVsn, InfoFile),
|
||||
Info = check_plugin(hocon_maps:ensure_plain(RichMap), NameVsn, InfoFile),
|
||||
maps:merge(Info, plugin_status(NameVsn));
|
||||
{error, Reason} ->
|
||||
throw(#{error => "bad_info_file",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
[ {emqx, {path, "../emqx"}},
|
||||
%% FIXME: tag this as v3.1.3
|
||||
{prometheus, {git, "https://github.com/emqx/prometheus.erl", {ref, "9994c76adca40d91a2545102230ccce2423fd8a7"}}},
|
||||
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.2"}}},
|
||||
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.23.0"}}},
|
||||
{minirest, {git, "https://github.com/emqx/minirest", {tag, "1.2.10"}}}
|
||||
]}.
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
-define(SAFE_CALL(_EXP_),
|
||||
?SAFE_CALL(_EXP_, _ = do_nothing)).
|
||||
?SAFE_CALL(_EXP_, ok)).
|
||||
|
||||
-define(SAFE_CALL(_EXP_, _EXP_ON_FAIL_),
|
||||
fun() ->
|
||||
|
|
|
@ -295,18 +295,20 @@ call_jsonify(Mod, Config) ->
|
|||
-spec check_config(resource_type(), raw_resource_config()) ->
|
||||
{ok, resource_config()} | {error, term()}.
|
||||
check_config(ResourceType, RawConfig) when is_binary(RawConfig) ->
|
||||
case hocon:binary(RawConfig, #{format => richmap}) of
|
||||
case hocon:binary(RawConfig, #{format => map}) of
|
||||
{ok, MapConfig} ->
|
||||
case ?SAFE_CALL(hocon_schema:check(ResourceType, MapConfig, ?HOCON_CHECK_OPTS)) of
|
||||
{error, Reason} -> {error, Reason};
|
||||
Config -> {ok, hocon_schema:richmap_to_map(Config)}
|
||||
end;
|
||||
Error -> Error
|
||||
check_config(ResourceType, MapConfig);
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
end;
|
||||
check_config(ResourceType, RawConfigTerm) ->
|
||||
case ?SAFE_CALL(hocon_schema:check_plain(ResourceType, RawConfigTerm, ?HOCON_CHECK_OPTS)) of
|
||||
{error, Reason} -> {error, Reason};
|
||||
Config -> {ok, Config}
|
||||
%% hocon_tconf map and check APIs throw exception on bad configs
|
||||
try hocon_tconf:check_plain(ResourceType, RawConfigTerm, ?HOCON_CHECK_OPTS) of
|
||||
Config ->
|
||||
{ok, Config}
|
||||
catch
|
||||
throw : Reason ->
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
-spec check_and_create(instance_id(), resource_type(), raw_resource_config()) ->
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
-spec check_params(map(), tag()) -> {ok, map()} | {error, term()}.
|
||||
check_params(Params, Tag) ->
|
||||
BTag = atom_to_binary(Tag),
|
||||
try hocon_schema:check_plain(?MODULE, #{BTag => Params},
|
||||
try hocon_tconf:check_plain(?MODULE, #{BTag => Params},
|
||||
#{atom_key => true, nullable => true}, [BTag]) of
|
||||
#{Tag := Checked} -> {ok, Checked}
|
||||
catch
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -59,7 +59,7 @@ defmodule EMQXUmbrella.MixProject do
|
|||
# in conflict by emqtt and hocon
|
||||
{:getopt, "1.0.2", override: true},
|
||||
{:snabbkaffe, github: "kafka4beam/snabbkaffe", tag: "0.16.0", override: true},
|
||||
{:hocon, github: "emqx/hocon", tag: "0.22.2", override: true},
|
||||
{:hocon, github: "emqx/hocon", tag: "0.23.0", override: true},
|
||||
{:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.4.1", override: true},
|
||||
{:esasl, github: "emqx/esasl", tag: "0.2.0"},
|
||||
{:jose, github: "potatosalad/erlang-jose", tag: "1.11.2"},
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
, {system_monitor, {git, "https://github.com/k32/system_monitor", {tag, "2.2.1"}}}
|
||||
, {getopt, "1.0.2"}
|
||||
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
|
||||
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.2"}}}
|
||||
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.23.0"}}}
|
||||
, {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.4.1"}}}
|
||||
, {esasl, {git, "https://github.com/emqx/esasl", {tag, "0.2.0"}}}
|
||||
, {jose, {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.11.2"}}}
|
||||
|
|
Loading…
Reference in New Issue