diff --git a/rhodecode/apps/file_store/__init__.py b/rhodecode/apps/file_store/__init__.py --- a/rhodecode/apps/file_store/__init__.py +++ b/rhodecode/apps/file_store/__init__.py @@ -34,6 +34,8 @@ def _sanitize_settings_and_apply_default default_store = os.path.join(os.path.dirname(settings['__file__']), 'upload_store') settings_maker.make_setting(config_keys.store_path, default_store) + settings_maker.env_expand() + def includeme(config): from rhodecode.apps.file_store.views import FileStoreView diff --git a/rhodecode/apps/ssh_support/__init__.py b/rhodecode/apps/ssh_support/__init__.py --- a/rhodecode/apps/ssh_support/__init__.py +++ b/rhodecode/apps/ssh_support/__init__.py @@ -48,6 +48,8 @@ def _sanitize_settings_and_apply_default settings_maker.make_setting(config_keys.ssh_git_bin, '~/.rccontrol/vcsserver-1/profile/bin/git') settings_maker.make_setting(config_keys.ssh_svn_bin, '~/.rccontrol/vcsserver-1/profile/bin/svnserve') + settings_maker.env_expand() + def includeme(config): settings = config.registry.settings diff --git a/rhodecode/apps/svn_support/__init__.py b/rhodecode/apps/svn_support/__init__.py --- a/rhodecode/apps/svn_support/__init__.py +++ b/rhodecode/apps/svn_support/__init__.py @@ -48,6 +48,8 @@ def _sanitize_settings_and_apply_default settings_maker.make_setting(config_keys.reload_command, '') settings_maker.make_setting(config_keys.template, '') + settings_maker.env_expand() + # Convert negative timeout values to zero. if settings[config_keys.reload_timeout] < 0: settings[config_keys.reload_timeout] = 0 diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -525,6 +525,13 @@ def sanitize_settings_and_apply_defaults settings_maker.make_setting('is_test', False, parser='bool') settings_maker.make_setting('gzip_responses', False, parser='bool') + # statsd + settings_maker.make_setting('statsd.enabled', False, parser='bool') + settings_maker.make_setting('statsd.statsd_host', '0.0.0.0') + settings_maker.make_setting('statsd.statsd_port', 8125, parser='int') + settings_maker.make_setting('statsd.statsd_prefix', '') + settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') + settings_maker.make_setting('vcs.svn.compatible_version', '') settings_maker.make_setting('vcs.hooks.protocol', 'http') settings_maker.make_setting('vcs.hooks.host', '127.0.0.1') @@ -549,17 +556,6 @@ def sanitize_settings_and_apply_defaults settings_maker.make_setting('appenlight', False, parser='bool') - _sanitize_cache_settings(settings) - - # configure instance id - config_utils.set_instance_id(settings) - - return settings - - -def _sanitize_cache_settings(settings): - settings_maker = SettingsMaker(settings) - temp_store = tempfile.gettempdir() default_cache_dir = os.path.join(temp_store, 'rc_cache') @@ -609,3 +605,10 @@ def _sanitize_cache_settings(settings): settings_maker.make_setting('rc_cache.sql_cache_short.backend', 'dogpile.cache.rc.memory_lru') settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int') settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int') + + settings_maker.env_expand() + + # configure instance id + config_utils.set_instance_id(settings) + + return settings diff --git a/rhodecode/config/settings_maker.py b/rhodecode/config/settings_maker.py --- a/rhodecode/config/settings_maker.py +++ b/rhodecode/config/settings_maker.py @@ -27,6 +27,8 @@ import tempfile import logging.config log = logging.getLogger(__name__) +set_keys = {} + def str2bool(_str): """ @@ -119,6 +121,27 @@ class SettingsMaker(object): def _key_transformator(cls, key): return "{}_{}".format('RC'.upper(), key.upper().replace('.', '_').replace('-', '_')) + def maybe_env_key(self, key): + # now maybe we have this KEY in env, search and use the value with higher priority. + transformed_key = self._key_transformator(key) + envvar_value = os.environ.get(transformed_key) + if envvar_value: + log.debug('using `%s` key instead of `%s` key for config', transformed_key, key) + + return envvar_value + + def env_expand(self): + replaced = {} + for k, v in self.settings.items(): + if k not in set_keys: + envvar_value = self.maybe_env_key(k) + if envvar_value: + replaced[k] = envvar_value + set_keys[k] = envvar_value + + # replace ALL keys updated + self.settings.update(replaced) + def enable_logging(self, logging_conf=None, level='INFO', formatter='generic'): """ Helper to enable debug on running instance @@ -133,7 +156,8 @@ class SettingsMaker(object): logging_conf = self.settings.get('logging.logging_conf_file') or '' if not os.path.isfile(logging_conf): - log.error('Unable to setup logging based on %s, file does not exist...', logging_conf) + log.error('Unable to setup logging based on %s, ' + 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf) return with open(logging_conf, 'rb') as f: @@ -151,7 +175,6 @@ class SettingsMaker(object): os.remove(f.name) def make_setting(self, key, default, lower=False, default_when_empty=False, parser=None): - input_val = self.settings.get(key, default) if default_when_empty and not input_val: @@ -172,11 +195,10 @@ class SettingsMaker(object): None: lambda i: i }[parser] - # now maybe we have this KEY in env, search and use the value with higher priority. - transformed_key = self._key_transformator(key) - envvar_value = os.environ.get(transformed_key) + envvar_value = self.maybe_env_key(key) if envvar_value: - log.debug('using `%s` key instead of `%s` key for config', transformed_key, key) input_val = envvar_value + set_keys[key] = input_val + self.settings[key] = parser_func(input_val) return self.settings[key]