Show More
@@ -34,6 +34,8 b' def _sanitize_settings_and_apply_default' | |||
|
34 | 34 | default_store = os.path.join(os.path.dirname(settings['__file__']), 'upload_store') |
|
35 | 35 | settings_maker.make_setting(config_keys.store_path, default_store) |
|
36 | 36 | |
|
37 | settings_maker.env_expand() | |
|
38 | ||
|
37 | 39 | |
|
38 | 40 | def includeme(config): |
|
39 | 41 | from rhodecode.apps.file_store.views import FileStoreView |
@@ -48,6 +48,8 b' def _sanitize_settings_and_apply_default' | |||
|
48 | 48 | settings_maker.make_setting(config_keys.ssh_git_bin, '~/.rccontrol/vcsserver-1/profile/bin/git') |
|
49 | 49 | settings_maker.make_setting(config_keys.ssh_svn_bin, '~/.rccontrol/vcsserver-1/profile/bin/svnserve') |
|
50 | 50 | |
|
51 | settings_maker.env_expand() | |
|
52 | ||
|
51 | 53 | |
|
52 | 54 | def includeme(config): |
|
53 | 55 | settings = config.registry.settings |
@@ -48,6 +48,8 b' def _sanitize_settings_and_apply_default' | |||
|
48 | 48 | settings_maker.make_setting(config_keys.reload_command, '') |
|
49 | 49 | settings_maker.make_setting(config_keys.template, '') |
|
50 | 50 | |
|
51 | settings_maker.env_expand() | |
|
52 | ||
|
51 | 53 | # Convert negative timeout values to zero. |
|
52 | 54 | if settings[config_keys.reload_timeout] < 0: |
|
53 | 55 | settings[config_keys.reload_timeout] = 0 |
@@ -525,6 +525,13 b' def sanitize_settings_and_apply_defaults' | |||
|
525 | 525 | settings_maker.make_setting('is_test', False, parser='bool') |
|
526 | 526 | settings_maker.make_setting('gzip_responses', False, parser='bool') |
|
527 | 527 | |
|
528 | # statsd | |
|
529 | settings_maker.make_setting('statsd.enabled', False, parser='bool') | |
|
530 | settings_maker.make_setting('statsd.statsd_host', '0.0.0.0') | |
|
531 | settings_maker.make_setting('statsd.statsd_port', 8125, parser='int') | |
|
532 | settings_maker.make_setting('statsd.statsd_prefix', '') | |
|
533 | settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') | |
|
534 | ||
|
528 | 535 | settings_maker.make_setting('vcs.svn.compatible_version', '') |
|
529 | 536 | settings_maker.make_setting('vcs.hooks.protocol', 'http') |
|
530 | 537 | settings_maker.make_setting('vcs.hooks.host', '127.0.0.1') |
@@ -549,17 +556,6 b' def sanitize_settings_and_apply_defaults' | |||
|
549 | 556 | |
|
550 | 557 | settings_maker.make_setting('appenlight', False, parser='bool') |
|
551 | 558 | |
|
552 | _sanitize_cache_settings(settings) | |
|
553 | ||
|
554 | # configure instance id | |
|
555 | config_utils.set_instance_id(settings) | |
|
556 | ||
|
557 | return settings | |
|
558 | ||
|
559 | ||
|
560 | def _sanitize_cache_settings(settings): | |
|
561 | settings_maker = SettingsMaker(settings) | |
|
562 | ||
|
563 | 559 | temp_store = tempfile.gettempdir() |
|
564 | 560 | default_cache_dir = os.path.join(temp_store, 'rc_cache') |
|
565 | 561 | |
@@ -609,3 +605,10 b' def _sanitize_cache_settings(settings):' | |||
|
609 | 605 | settings_maker.make_setting('rc_cache.sql_cache_short.backend', 'dogpile.cache.rc.memory_lru') |
|
610 | 606 | settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int') |
|
611 | 607 | settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int') |
|
608 | ||
|
609 | settings_maker.env_expand() | |
|
610 | ||
|
611 | # configure instance id | |
|
612 | config_utils.set_instance_id(settings) | |
|
613 | ||
|
614 | return settings |
@@ -27,6 +27,8 b' import tempfile' | |||
|
27 | 27 | import logging.config |
|
28 | 28 | log = logging.getLogger(__name__) |
|
29 | 29 | |
|
30 | set_keys = {} | |
|
31 | ||
|
30 | 32 | |
|
31 | 33 | def str2bool(_str): |
|
32 | 34 | """ |
@@ -119,6 +121,27 b' class SettingsMaker(object):' | |||
|
119 | 121 | def _key_transformator(cls, key): |
|
120 | 122 | return "{}_{}".format('RC'.upper(), key.upper().replace('.', '_').replace('-', '_')) |
|
121 | 123 | |
|
124 | def maybe_env_key(self, key): | |
|
125 | # now maybe we have this KEY in env, search and use the value with higher priority. | |
|
126 | transformed_key = self._key_transformator(key) | |
|
127 | envvar_value = os.environ.get(transformed_key) | |
|
128 | if envvar_value: | |
|
129 | log.debug('using `%s` key instead of `%s` key for config', transformed_key, key) | |
|
130 | ||
|
131 | return envvar_value | |
|
132 | ||
|
133 | def env_expand(self): | |
|
134 | replaced = {} | |
|
135 | for k, v in self.settings.items(): | |
|
136 | if k not in set_keys: | |
|
137 | envvar_value = self.maybe_env_key(k) | |
|
138 | if envvar_value: | |
|
139 | replaced[k] = envvar_value | |
|
140 | set_keys[k] = envvar_value | |
|
141 | ||
|
142 | # replace ALL keys updated | |
|
143 | self.settings.update(replaced) | |
|
144 | ||
|
122 | 145 | def enable_logging(self, logging_conf=None, level='INFO', formatter='generic'): |
|
123 | 146 | """ |
|
124 | 147 | Helper to enable debug on running instance |
@@ -133,7 +156,8 b' class SettingsMaker(object):' | |||
|
133 | 156 | logging_conf = self.settings.get('logging.logging_conf_file') or '' |
|
134 | 157 | |
|
135 | 158 | if not os.path.isfile(logging_conf): |
|
136 |
log.error('Unable to setup logging based on %s, |
|
|
159 | log.error('Unable to setup logging based on %s, ' | |
|
160 | 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf) | |
|
137 | 161 | return |
|
138 | 162 | |
|
139 | 163 | with open(logging_conf, 'rb') as f: |
@@ -151,7 +175,6 b' class SettingsMaker(object):' | |||
|
151 | 175 | os.remove(f.name) |
|
152 | 176 | |
|
153 | 177 | def make_setting(self, key, default, lower=False, default_when_empty=False, parser=None): |
|
154 | ||
|
155 | 178 | input_val = self.settings.get(key, default) |
|
156 | 179 | |
|
157 | 180 | if default_when_empty and not input_val: |
@@ -172,11 +195,10 b' class SettingsMaker(object):' | |||
|
172 | 195 | None: lambda i: i |
|
173 | 196 | }[parser] |
|
174 | 197 | |
|
175 | # now maybe we have this KEY in env, search and use the value with higher priority. | |
|
176 | transformed_key = self._key_transformator(key) | |
|
177 | envvar_value = os.environ.get(transformed_key) | |
|
198 | envvar_value = self.maybe_env_key(key) | |
|
178 | 199 | if envvar_value: |
|
179 | log.debug('using `%s` key instead of `%s` key for config', transformed_key, key) | |
|
180 | 200 | input_val = envvar_value |
|
201 | set_keys[key] = input_val | |
|
202 | ||
|
181 | 203 | self.settings[key] = parser_func(input_val) |
|
182 | 204 | return self.settings[key] |
General Comments 0
You need to be logged in to leave comments.
Login now