##// END OF EJS Templates
configuration: Allows to use format style "{ENV_NAME}" placeholders in the configuration.
marcink -
r2818:4e04a411 default
parent child Browse files
Show More
@@ -18,6 +18,7 b''
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 import os
21 22 import logging
22 23 import traceback
23 24 import collections
@@ -71,6 +72,15 b' def make_pyramid_app(global_config, **se'
71 72 cases when these fragments are assembled from another place.
72 73
73 74 """
75
76 # Allows to use format style "{ENV_NAME}" placeholders in the configuration. It
77 # will be replaced by the value of the environment variable "NAME" in this case.
78 environ = {
79 'ENV_{}'.format(key): value for key, value in os.environ.items()}
80
81 global_config = _substitute_values(global_config, environ)
82 settings = _substitute_values(settings, environ)
83
74 84 sanitize_settings_and_apply_defaults(settings)
75 85
76 86 config = Configurator(settings=settings)
@@ -438,3 +448,13 b' def _string_setting(settings, name, defa'
438 448 if lower:
439 449 value = value.lower()
440 450 settings[name] = value
451
452
453 def _substitute_values(mapping, substitutions):
454 result = {
455 # Note: Cannot use regular replacements, since they would clash
456 # with the implementation of ConfigParser. Using "format" instead.
457 key: value.format(**substitutions)
458 for key, value in mapping.items()
459 }
460 return result
General Comments 0
You need to be logged in to leave comments. Login now