Skip to content

Commit c156a4b

Browse files
committed
Use prelaunch context instead of reading app env. variable
[Why] We use the application environment as some kind of "cache" for the configuration parameters and some system environment variables. However, because we don't use `sys.config`, the application environment could be reset to its default/empty state if we were to use Erlang releases. [How] For values that may come from the system environment, we use the prelaunch context instead.
1 parent 12123b5 commit c156a4b

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

deps/rabbit/src/rabbit.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ get_default_data_param(Param) ->
11751175
%% </ul>
11761176

11771177
data_dir() ->
1178-
{ok, DataDir} = application:get_env(rabbit, data_dir),
1178+
#{data_dir := DataDir} = rabbit_prelaunch:get_context(),
11791179
DataDir.
11801180

11811181
%%---------------------------------------------------------------------------

deps/rabbit/src/rabbit_feature_flags.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,9 @@ delete_enabled_feature_flags_list_file() ->
11641164
%% @returns the path to the file.
11651165

11661166
enabled_feature_flags_list_file() ->
1167-
case application:get_env(rabbit, feature_flags_file) of
1168-
{ok, Val} -> Val;
1169-
undefined -> throw(feature_flags_file_not_set)
1167+
case rabbit_prelaunch:get_context() of
1168+
#{feature_flags_file := File} -> File;
1169+
_ -> throw(feature_flags_file_not_set)
11701170
end.
11711171

11721172
copy_feature_states_after_reset(RemoteNode) ->

deps/rabbit/src/rabbit_ff_controller.erl

+4-2
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,10 @@ get_forced_feature_flag_names_from_env() ->
670670
%% @private
671671

672672
get_forced_feature_flag_names_from_config() ->
673-
Value = application:get_env(
674-
rabbit, forced_feature_flags_on_init, undefined),
673+
Value = maps:get(
674+
forced_feature_flags_on_init,
675+
rabbit_prelaunch:get_context(),
676+
undefined),
675677
case Value of
676678
undefined ->
677679
Value;

deps/rabbit/src/rabbit_plugins.erl

+9-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ensure(FileJustChanged) ->
3232
end.
3333

3434
ensure1(FileJustChanged0) ->
35-
{ok, OurFile0} = application:get_env(rabbit, enabled_plugins_file),
35+
OurFile0 = enabled_plugins_file(),
3636
FileJustChanged = filename:nativename(FileJustChanged0),
3737
OurFile = filename:nativename(OurFile0),
3838
case OurFile of
@@ -72,39 +72,23 @@ ensure1(FileJustChanged0) ->
7272

7373
-spec plugins_expand_dir() -> file:filename().
7474
plugins_expand_dir() ->
75-
case application:get_env(rabbit, plugins_expand_dir) of
76-
{ok, ExpandDir} ->
77-
ExpandDir;
78-
_ ->
79-
filename:join([rabbit:data_dir(), "plugins_expand_dir"])
80-
end.
75+
#{plugins_expand_dir := ExpandDir} = rabbit_prelaunch:get_context(),
76+
ExpandDir.
8177

8278
-spec plugins_dir() -> file:filename().
8379
plugins_dir() ->
84-
case application:get_env(rabbit, plugins_dir) of
85-
{ok, PluginsDistDir} ->
86-
PluginsDistDir;
87-
_ ->
88-
filename:join([rabbit:data_dir(), "plugins_dir_stub"])
89-
end.
80+
#{plugins_path := PluginsDistDir} = rabbit_prelaunch:get_context(),
81+
PluginsDistDir.
9082

9183
-spec enabled_plugins_file() -> file:filename().
9284
enabled_plugins_file() ->
93-
case application:get_env(rabbit, enabled_plugins_file) of
94-
{ok, Val} ->
95-
Val;
96-
_ ->
97-
filename:join([rabbit:data_dir(), "enabled_plugins"])
98-
end.
85+
#{enabled_plugins_file := File} = rabbit_prelaunch:get_context(),
86+
File.
9987

10088
-spec enabled_plugins() -> [atom()].
10189
enabled_plugins() ->
102-
case application:get_env(rabbit, enabled_plugins_file) of
103-
{ok, EnabledFile} ->
104-
read_enabled(EnabledFile);
105-
_ ->
106-
[]
107-
end.
90+
EnabledFile = enabled_plugins_file(),
91+
read_enabled(EnabledFile).
10892

10993
%% @doc Prepares the file system and installs all enabled plugins.
11094

0 commit comments

Comments
 (0)