Overwrite configuration with development configuration

schut edited this page Jan 11, 2013 · 2 revisions


I want to overwrite some settings in boss.config with development settings. I'm used to at least environments a development and a production. But in addition an system integration and an acceptance environment are common in my environments as well.


First look for 'boss_env' in the operating system environment, if not found fallback to the boss_env environment. Use the result read 'boss_{environment}.config' and overwrite boss.config settings with the settings found in this file.

Warning: I'm not sure which boss configuration environment parameters can be overwritten. I use it to overwrite my application specific environment parameters.


-define(CONFIG_BASENAME, "boss").

init() ->
	ConfigFile = ?CONFIG_BASENAME ++ "_" ++ env() ++ ".config",
	case file:consult(ConfigFile) of
		{ok, [Config]}  -> config(Config);
		{error, enoent} -> ok			% no configuration overrides present

env() ->
	case os:getenv("boss_env") of
		false -> atom_to_list(boss_env:boss_env());
		Env   -> Env

config(Config) ->
	true = lists:all(fun app_config/1, Config),

app_config({App, Config}) ->
	lists:all(fun({Par, Val}) -> app_config_set_env(App, Par, Val) end, Config).

app_config_set_env(App, Par, Val) ->
	application:set_env(App, Par, Val),