Merge pull request #8323 from zmstone/0626-fix-environment-variable-override
0626 fix authn environment variable override
This commit is contained in:
commit
9cdcf8d342
|
@ -144,7 +144,7 @@ get_root([RootName | _]) ->
|
||||||
%% @doc For the given path, get raw root value enclosed in a single-key map.
|
%% @doc For the given path, get raw root value enclosed in a single-key map.
|
||||||
%% key is ensured to be binary.
|
%% key is ensured to be binary.
|
||||||
get_root_raw([RootName | _]) ->
|
get_root_raw([RootName | _]) ->
|
||||||
#{bin(RootName) => do_get(?RAW_CONF, [RootName], #{})}.
|
#{bin(RootName) => do_get_raw([RootName], #{})}.
|
||||||
|
|
||||||
%% @doc Get a config value for the given path.
|
%% @doc Get a config value for the given path.
|
||||||
%% The path should at least include root config name.
|
%% The path should at least include root config name.
|
||||||
|
@ -173,7 +173,7 @@ find(KeyPath) ->
|
||||||
{ok, term()} | {not_found, emqx_map_lib:config_key_path(), term()}.
|
{ok, term()} | {not_found, emqx_map_lib:config_key_path(), term()}.
|
||||||
find_raw([]) ->
|
find_raw([]) ->
|
||||||
Ref = make_ref(),
|
Ref = make_ref(),
|
||||||
case do_get(?RAW_CONF, [], Ref) of
|
case do_get_raw([], Ref) of
|
||||||
Ref -> {not_found, []};
|
Ref -> {not_found, []};
|
||||||
Res -> {ok, Res}
|
Res -> {ok, Res}
|
||||||
end;
|
end;
|
||||||
|
@ -281,10 +281,10 @@ get_default_value([RootName | _] = KeyPath) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_raw(emqx_map_lib:config_key_path()) -> term().
|
-spec get_raw(emqx_map_lib:config_key_path()) -> term().
|
||||||
get_raw(KeyPath) -> hocon_tconf:remove_env_meta(do_get(?RAW_CONF, KeyPath)).
|
get_raw(KeyPath) -> do_get_raw(KeyPath).
|
||||||
|
|
||||||
-spec get_raw(emqx_map_lib:config_key_path(), term()) -> term().
|
-spec get_raw(emqx_map_lib:config_key_path(), term()) -> term().
|
||||||
get_raw(KeyPath, Default) -> hocon_tconf:remove_env_meta(do_get(?RAW_CONF, KeyPath, Default)).
|
get_raw(KeyPath, Default) -> do_get_raw(KeyPath, Default).
|
||||||
|
|
||||||
-spec put_raw(map()) -> ok.
|
-spec put_raw(map()) -> ok.
|
||||||
put_raw(Config) ->
|
put_raw(Config) ->
|
||||||
|
@ -398,11 +398,11 @@ include_dirs() ->
|
||||||
[filename:join(emqx:data_dir(), "configs")].
|
[filename:join(emqx:data_dir(), "configs")].
|
||||||
|
|
||||||
merge_envs(SchemaMod, RawConf) ->
|
merge_envs(SchemaMod, RawConf) ->
|
||||||
%% TODO: evil, remove, required should be declared in schema
|
|
||||||
Opts = #{
|
Opts = #{
|
||||||
required => false,
|
required => false,
|
||||||
format => map,
|
format => map,
|
||||||
apply_override_envs => true
|
apply_override_envs => true,
|
||||||
|
check_lazy => true
|
||||||
},
|
},
|
||||||
hocon_tconf:merge_env_overrides(SchemaMod, RawConf, all, Opts).
|
hocon_tconf:merge_env_overrides(SchemaMod, RawConf, all, Opts).
|
||||||
|
|
||||||
|
@ -571,6 +571,12 @@ load_hocon_file(FileName, LoadType) ->
|
||||||
#{}
|
#{}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
do_get_raw(Path) ->
|
||||||
|
hocon_tconf:remove_env_meta(do_get(?RAW_CONF, Path)).
|
||||||
|
|
||||||
|
do_get_raw(Path, Default) ->
|
||||||
|
hocon_tconf:remove_env_meta(do_get(?RAW_CONF, Path, Default)).
|
||||||
|
|
||||||
do_get(Type, KeyPath) ->
|
do_get(Type, KeyPath) ->
|
||||||
Ref = make_ref(),
|
Ref = make_ref(),
|
||||||
Res = do_get(Type, KeyPath, Ref),
|
Res = do_get(Type, KeyPath, Ref),
|
||||||
|
|
|
@ -2216,29 +2216,29 @@ str(B) when is_binary(B) ->
|
||||||
str(S) when is_list(S) ->
|
str(S) when is_list(S) ->
|
||||||
S.
|
S.
|
||||||
|
|
||||||
authentication(Type) ->
|
authentication(Which) ->
|
||||||
Desc =
|
Desc =
|
||||||
case Type of
|
case Which of
|
||||||
global -> ?DESC(global_authentication);
|
global -> ?DESC(global_authentication);
|
||||||
listener -> ?DESC(listener_authentication)
|
listener -> ?DESC(listener_authentication)
|
||||||
end,
|
end,
|
||||||
%% authentication schema is lazy to make it more 'plugable'
|
%% The runtime module injection
|
||||||
%% the type checks are done in emqx_auth application when it boots.
|
|
||||||
%% and in emqx_authentication_config module for runtime changes.
|
|
||||||
Default = hoconsc:lazy(hoconsc:union([hoconsc:array(typerefl:map())])),
|
|
||||||
%% as the type is lazy, the runtime module injection
|
|
||||||
%% from EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY
|
%% from EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY
|
||||||
%% is for now only affecting document generation.
|
%% is for now only affecting document generation.
|
||||||
%% maybe in the future, we can find a more straightforward way to support
|
%% maybe in the future, we can find a more straightforward way to support
|
||||||
%% * document generation (at compile time)
|
%% * document generation (at compile time)
|
||||||
%% * type checks before boot (in bin/emqx config generation)
|
%% * type checks before boot (in bin/emqx config generation)
|
||||||
%% * type checks at runtime (when changing configs via management API)
|
%% * type checks at runtime (when changing configs via management API)
|
||||||
|
Type0 =
|
||||||
|
case persistent_term:get(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, undefined) of
|
||||||
|
undefined -> hoconsc:array(typerefl:map());
|
||||||
|
Module -> Module:root_type()
|
||||||
|
end,
|
||||||
|
%% It is a lazy type because when handing runtime update requests
|
||||||
|
%% the config is not checked by emqx_schema, but by the injected schema
|
||||||
|
Type = hoconsc:lazy(Type0),
|
||||||
#{
|
#{
|
||||||
type =>
|
type => Type,
|
||||||
case persistent_term:get(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, undefined) of
|
|
||||||
undefined -> Default;
|
|
||||||
Module -> hoconsc:lazy(Module:root_type())
|
|
||||||
end,
|
|
||||||
desc => Desc
|
desc => Desc
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue