Show More
@@ -1,198 +1,200 b'' | |||||
1 | # Copyright (C) 2010-2023 RhodeCode GmbH |
|
1 | # Copyright (C) 2010-2023 RhodeCode GmbH | |
2 | # |
|
2 | # | |
3 | # This program is free software: you can redistribute it and/or modify |
|
3 | # This program is free software: you can redistribute it and/or modify | |
4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
4 | # it under the terms of the GNU Affero General Public License, version 3 | |
5 | # (only), as published by the Free Software Foundation. |
|
5 | # (only), as published by the Free Software Foundation. | |
6 | # |
|
6 | # | |
7 | # This program is distributed in the hope that it will be useful, |
|
7 | # This program is distributed in the hope that it will be useful, | |
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | # GNU General Public License for more details. |
|
10 | # GNU General Public License for more details. | |
11 | # |
|
11 | # | |
12 | # You should have received a copy of the GNU Affero General Public License |
|
12 | # You should have received a copy of the GNU Affero General Public License | |
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | # |
|
14 | # | |
15 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 | import os |
|
19 | import os | |
20 | import tempfile |
|
20 | import tempfile | |
21 | import logging |
|
21 | import logging | |
22 |
|
22 | |||
23 | from pyramid.settings import asbool |
|
23 | from pyramid.settings import asbool | |
24 |
|
24 | |||
25 | from rhodecode.config.settings_maker import SettingsMaker |
|
25 | from rhodecode.config.settings_maker import SettingsMaker | |
26 | from rhodecode.config import utils as config_utils |
|
26 | from rhodecode.config import utils as config_utils | |
27 |
|
27 | |||
28 | log = logging.getLogger(__name__) |
|
28 | log = logging.getLogger(__name__) | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | def sanitize_settings_and_apply_defaults(global_config, settings): |
|
31 | def sanitize_settings_and_apply_defaults(global_config, settings): | |
32 | """ |
|
32 | """ | |
33 | Applies settings defaults and does all type conversion. |
|
33 | Applies settings defaults and does all type conversion. | |
34 |
|
34 | |||
35 | We would move all settings parsing and preparation into this place, so that |
|
35 | We would move all settings parsing and preparation into this place, so that | |
36 | we have only one place left which deals with this part. The remaining parts |
|
36 | we have only one place left which deals with this part. The remaining parts | |
37 | of the application would start to rely fully on well-prepared settings. |
|
37 | of the application would start to rely fully on well-prepared settings. | |
38 |
|
38 | |||
39 | This piece would later be split up per topic to avoid a big fat monster |
|
39 | This piece would later be split up per topic to avoid a big fat monster | |
40 | function. |
|
40 | function. | |
41 | """ |
|
41 | """ | |
42 | jn = os.path.join |
|
42 | jn = os.path.join | |
43 |
|
43 | |||
44 | global_settings_maker = SettingsMaker(global_config) |
|
44 | global_settings_maker = SettingsMaker(global_config) | |
45 | global_settings_maker.make_setting('debug', default=False, parser='bool') |
|
45 | global_settings_maker.make_setting('debug', default=False, parser='bool') | |
46 | debug_enabled = asbool(global_config.get('debug')) |
|
46 | debug_enabled = asbool(global_config.get('debug')) | |
47 |
|
47 | |||
48 | settings_maker = SettingsMaker(settings) |
|
48 | settings_maker = SettingsMaker(settings) | |
49 |
|
49 | |||
50 | settings_maker.make_setting( |
|
50 | settings_maker.make_setting( | |
51 | 'logging.autoconfigure', |
|
51 | 'logging.autoconfigure', | |
52 | default=False, |
|
52 | default=False, | |
53 | parser='bool') |
|
53 | parser='bool') | |
54 |
|
54 | |||
55 | logging_conf = jn(os.path.dirname(global_config.get('__file__')), 'logging.ini') |
|
55 | logging_conf = jn(os.path.dirname(global_config.get('__file__')), 'logging.ini') | |
56 | settings_maker.enable_logging(logging_conf, level='INFO' if debug_enabled else 'DEBUG') |
|
56 | settings_maker.enable_logging(logging_conf, level='INFO' if debug_enabled else 'DEBUG') | |
57 |
|
57 | |||
58 | # Default includes, possible to change as a user |
|
58 | # Default includes, possible to change as a user | |
59 | pyramid_includes = settings_maker.make_setting('pyramid.includes', [], parser='list:newline') |
|
59 | pyramid_includes = settings_maker.make_setting('pyramid.includes', [], parser='list:newline') | |
60 | log.debug( |
|
60 | log.debug( | |
61 | "Using the following pyramid.includes: %s", |
|
61 | "Using the following pyramid.includes: %s", | |
62 | pyramid_includes) |
|
62 | pyramid_includes) | |
63 |
|
63 | |||
64 | settings_maker.make_setting('rhodecode.edition', 'Community Edition') |
|
64 | settings_maker.make_setting('rhodecode.edition', 'Community Edition') | |
65 | settings_maker.make_setting('rhodecode.edition_id', 'CE') |
|
65 | settings_maker.make_setting('rhodecode.edition_id', 'CE') | |
66 |
|
66 | |||
67 | if 'mako.default_filters' not in settings: |
|
67 | if 'mako.default_filters' not in settings: | |
68 | # set custom default filters if we don't have it defined |
|
68 | # set custom default filters if we don't have it defined | |
69 | settings['mako.imports'] = 'from rhodecode.lib.base import h_filter' |
|
69 | settings['mako.imports'] = 'from rhodecode.lib.base import h_filter' | |
70 | settings['mako.default_filters'] = 'h_filter' |
|
70 | settings['mako.default_filters'] = 'h_filter' | |
71 |
|
71 | |||
72 | if 'mako.directories' not in settings: |
|
72 | if 'mako.directories' not in settings: | |
73 | mako_directories = settings.setdefault('mako.directories', [ |
|
73 | mako_directories = settings.setdefault('mako.directories', [ | |
74 | # Base templates of the original application |
|
74 | # Base templates of the original application | |
75 | 'rhodecode:templates', |
|
75 | 'rhodecode:templates', | |
76 | ]) |
|
76 | ]) | |
77 | log.debug( |
|
77 | log.debug( | |
78 | "Using the following Mako template directories: %s", |
|
78 | "Using the following Mako template directories: %s", | |
79 | mako_directories) |
|
79 | mako_directories) | |
80 |
|
80 | |||
81 | # NOTE(marcink): fix redis requirement for schema of connection since 3.X |
|
81 | # NOTE(marcink): fix redis requirement for schema of connection since 3.X | |
82 | if 'beaker.session.type' in settings and settings['beaker.session.type'] == 'ext:redis': |
|
82 | if 'beaker.session.type' in settings and settings['beaker.session.type'] == 'ext:redis': | |
83 | raw_url = settings['beaker.session.url'] |
|
83 | raw_url = settings['beaker.session.url'] | |
84 | if not raw_url.startswith(('redis://', 'rediss://', 'unix://')): |
|
84 | if not raw_url.startswith(('redis://', 'rediss://', 'unix://')): | |
85 | settings['beaker.session.url'] = 'redis://' + raw_url |
|
85 | settings['beaker.session.url'] = 'redis://' + raw_url | |
86 |
|
86 | |||
87 | settings_maker.make_setting('__file__', global_config.get('__file__')) |
|
87 | settings_maker.make_setting('__file__', global_config.get('__file__')) | |
88 |
|
88 | |||
89 | # TODO: johbo: Re-think this, usually the call to config.include |
|
89 | # TODO: johbo: Re-think this, usually the call to config.include | |
90 | # should allow to pass in a prefix. |
|
90 | # should allow to pass in a prefix. | |
91 | settings_maker.make_setting('rhodecode.api.url', '/_admin/api') |
|
91 | settings_maker.make_setting('rhodecode.api.url', '/_admin/api') | |
92 |
|
92 | |||
93 | # Sanitize generic settings. |
|
93 | # Sanitize generic settings. | |
94 | settings_maker.make_setting('default_encoding', 'UTF-8', parser='list') |
|
94 | settings_maker.make_setting('default_encoding', 'UTF-8', parser='list') | |
95 | settings_maker.make_setting('is_test', False, parser='bool') |
|
95 | settings_maker.make_setting('is_test', False, parser='bool') | |
96 | settings_maker.make_setting('gzip_responses', False, parser='bool') |
|
96 | settings_maker.make_setting('gzip_responses', False, parser='bool') | |
|
97 | settings_maker.make_setting('startup.import_repos', 'false', parser='bool') | |||
97 |
|
98 | |||
98 | # statsd |
|
99 | # statsd | |
99 | settings_maker.make_setting('statsd.enabled', False, parser='bool') |
|
100 | settings_maker.make_setting('statsd.enabled', False, parser='bool') | |
100 | settings_maker.make_setting('statsd.statsd_host', 'statsd-exporter', parser='string') |
|
101 | settings_maker.make_setting('statsd.statsd_host', 'statsd-exporter', parser='string') | |
101 | settings_maker.make_setting('statsd.statsd_port', 9125, parser='int') |
|
102 | settings_maker.make_setting('statsd.statsd_port', 9125, parser='int') | |
102 | settings_maker.make_setting('statsd.statsd_prefix', '') |
|
103 | settings_maker.make_setting('statsd.statsd_prefix', '') | |
103 | settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') |
|
104 | settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') | |
104 |
|
105 | |||
105 | settings_maker.make_setting('vcs.svn.compatible_version', '') |
|
106 | settings_maker.make_setting('vcs.svn.compatible_version', '') | |
|
107 | settings_maker.make_setting('vcs.svn.proxy.enabled', True, parser='bool') | |||
|
108 | settings_maker.make_setting('vcs.svn.proxy.host', 'http://svn:8090', parser='string') | |||
106 | settings_maker.make_setting('vcs.hooks.protocol', 'http') |
|
109 | settings_maker.make_setting('vcs.hooks.protocol', 'http') | |
107 | settings_maker.make_setting('vcs.hooks.host', '*') |
|
110 | settings_maker.make_setting('vcs.hooks.host', '*') | |
108 | settings_maker.make_setting('vcs.scm_app_implementation', 'http') |
|
111 | settings_maker.make_setting('vcs.scm_app_implementation', 'http') | |
109 | settings_maker.make_setting('vcs.server', '') |
|
112 | settings_maker.make_setting('vcs.server', '') | |
110 | settings_maker.make_setting('vcs.server.protocol', 'http') |
|
113 | settings_maker.make_setting('vcs.server.protocol', 'http') | |
111 | settings_maker.make_setting('vcs.server.enable', 'true', parser='bool') |
|
114 | settings_maker.make_setting('vcs.server.enable', 'true', parser='bool') | |
112 | settings_maker.make_setting('startup.import_repos', 'false', parser='bool') |
|
|||
113 | settings_maker.make_setting('vcs.hooks.direct_calls', 'false', parser='bool') |
|
115 | settings_maker.make_setting('vcs.hooks.direct_calls', 'false', parser='bool') | |
114 | settings_maker.make_setting('vcs.start_server', 'false', parser='bool') |
|
116 | settings_maker.make_setting('vcs.start_server', 'false', parser='bool') | |
115 | settings_maker.make_setting('vcs.backends', 'hg, git, svn', parser='list') |
|
117 | settings_maker.make_setting('vcs.backends', 'hg, git, svn', parser='list') | |
116 | settings_maker.make_setting('vcs.connection_timeout', 3600, parser='int') |
|
118 | settings_maker.make_setting('vcs.connection_timeout', 3600, parser='int') | |
117 |
|
119 | |||
118 | settings_maker.make_setting('vcs.methods.cache', True, parser='bool') |
|
120 | settings_maker.make_setting('vcs.methods.cache', True, parser='bool') | |
119 |
|
121 | |||
120 | # Support legacy values of vcs.scm_app_implementation. Legacy |
|
122 | # Support legacy values of vcs.scm_app_implementation. Legacy | |
121 | # configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or |
|
123 | # configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or | |
122 | # disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'. |
|
124 | # disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'. | |
123 | scm_app_impl = settings['vcs.scm_app_implementation'] |
|
125 | scm_app_impl = settings['vcs.scm_app_implementation'] | |
124 | if scm_app_impl in ['rhodecode.lib.middleware.utils.scm_app_http', 'vcsserver.scm_app']: |
|
126 | if scm_app_impl in ['rhodecode.lib.middleware.utils.scm_app_http', 'vcsserver.scm_app']: | |
125 | settings['vcs.scm_app_implementation'] = 'http' |
|
127 | settings['vcs.scm_app_implementation'] = 'http' | |
126 |
|
128 | |||
127 | settings_maker.make_setting('appenlight', False, parser='bool') |
|
129 | settings_maker.make_setting('appenlight', False, parser='bool') | |
128 |
|
130 | |||
129 | temp_store = tempfile.gettempdir() |
|
131 | temp_store = tempfile.gettempdir() | |
130 | tmp_cache_dir = jn(temp_store, 'rc_cache') |
|
132 | tmp_cache_dir = jn(temp_store, 'rc_cache') | |
131 |
|
133 | |||
132 | # save default, cache dir, and use it for all backends later. |
|
134 | # save default, cache dir, and use it for all backends later. | |
133 | default_cache_dir = settings_maker.make_setting( |
|
135 | default_cache_dir = settings_maker.make_setting( | |
134 | 'cache_dir', |
|
136 | 'cache_dir', | |
135 | default=tmp_cache_dir, default_when_empty=True, |
|
137 | default=tmp_cache_dir, default_when_empty=True, | |
136 | parser='dir:ensured') |
|
138 | parser='dir:ensured') | |
137 |
|
139 | |||
138 | # exception store cache |
|
140 | # exception store cache | |
139 | settings_maker.make_setting( |
|
141 | settings_maker.make_setting( | |
140 | 'exception_tracker.store_path', |
|
142 | 'exception_tracker.store_path', | |
141 | default=jn(default_cache_dir, 'exc_store'), default_when_empty=True, |
|
143 | default=jn(default_cache_dir, 'exc_store'), default_when_empty=True, | |
142 | parser='dir:ensured' |
|
144 | parser='dir:ensured' | |
143 | ) |
|
145 | ) | |
144 |
|
146 | |||
145 | settings_maker.make_setting( |
|
147 | settings_maker.make_setting( | |
146 | 'celerybeat-schedule.path', |
|
148 | 'celerybeat-schedule.path', | |
147 | default=jn(default_cache_dir, 'celerybeat_schedule', 'celerybeat-schedule.db'), default_when_empty=True, |
|
149 | default=jn(default_cache_dir, 'celerybeat_schedule', 'celerybeat-schedule.db'), default_when_empty=True, | |
148 | parser='file:ensured' |
|
150 | parser='file:ensured' | |
149 | ) |
|
151 | ) | |
150 |
|
152 | |||
151 | settings_maker.make_setting('exception_tracker.send_email', False, parser='bool') |
|
153 | settings_maker.make_setting('exception_tracker.send_email', False, parser='bool') | |
152 | settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True) |
|
154 | settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True) | |
153 |
|
155 | |||
154 | # sessions, ensure file since no-value is memory |
|
156 | # sessions, ensure file since no-value is memory | |
155 | settings_maker.make_setting('beaker.session.type', 'file') |
|
157 | settings_maker.make_setting('beaker.session.type', 'file') | |
156 | settings_maker.make_setting('beaker.session.data_dir', jn(default_cache_dir, 'session_data')) |
|
158 | settings_maker.make_setting('beaker.session.data_dir', jn(default_cache_dir, 'session_data')) | |
157 |
|
159 | |||
158 | # cache_general |
|
160 | # cache_general | |
159 | settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace') |
|
161 | settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace') | |
160 | settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int') |
|
162 | settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int') | |
161 | settings_maker.make_setting('rc_cache.cache_general.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_general.db')) |
|
163 | settings_maker.make_setting('rc_cache.cache_general.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_general.db')) | |
162 |
|
164 | |||
163 | # cache_perms |
|
165 | # cache_perms | |
164 | settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace') |
|
166 | settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace') | |
165 | settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int') |
|
167 | settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int') | |
166 | settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_perms_db')) |
|
168 | settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_perms_db')) | |
167 |
|
169 | |||
168 | # cache_repo |
|
170 | # cache_repo | |
169 | settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace') |
|
171 | settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace') | |
170 | settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int') |
|
172 | settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int') | |
171 | settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_repo_db')) |
|
173 | settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_repo_db')) | |
172 |
|
174 | |||
173 | # cache_license |
|
175 | # cache_license | |
174 | settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace') |
|
176 | settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace') | |
175 | settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int') |
|
177 | settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int') | |
176 | settings_maker.make_setting('rc_cache.cache_license.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_license_db')) |
|
178 | settings_maker.make_setting('rc_cache.cache_license.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_license_db')) | |
177 |
|
179 | |||
178 | # cache_repo_longterm memory, 96H |
|
180 | # cache_repo_longterm memory, 96H | |
179 | settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru') |
|
181 | settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru') | |
180 | settings_maker.make_setting('rc_cache.cache_repo_longterm.expiration_time', 345600, parser='int') |
|
182 | settings_maker.make_setting('rc_cache.cache_repo_longterm.expiration_time', 345600, parser='int') | |
181 | settings_maker.make_setting('rc_cache.cache_repo_longterm.max_size', 10000, parser='int') |
|
183 | settings_maker.make_setting('rc_cache.cache_repo_longterm.max_size', 10000, parser='int') | |
182 |
|
184 | |||
183 | # sql_cache_short |
|
185 | # sql_cache_short | |
184 | settings_maker.make_setting('rc_cache.sql_cache_short.backend', 'dogpile.cache.rc.memory_lru') |
|
186 | settings_maker.make_setting('rc_cache.sql_cache_short.backend', 'dogpile.cache.rc.memory_lru') | |
185 | settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int') |
|
187 | settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int') | |
186 | settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int') |
|
188 | settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int') | |
187 |
|
189 | |||
188 | # archive_cache |
|
190 | # archive_cache | |
189 | settings_maker.make_setting('archive_cache.store_dir', jn(default_cache_dir, 'archive_cache'), default_when_empty=True,) |
|
191 | settings_maker.make_setting('archive_cache.store_dir', jn(default_cache_dir, 'archive_cache'), default_when_empty=True,) | |
190 | settings_maker.make_setting('archive_cache.cache_size_gb', 10, parser='float') |
|
192 | settings_maker.make_setting('archive_cache.cache_size_gb', 10, parser='float') | |
191 | settings_maker.make_setting('archive_cache.cache_shards', 10, parser='int') |
|
193 | settings_maker.make_setting('archive_cache.cache_shards', 10, parser='int') | |
192 |
|
194 | |||
193 | settings_maker.env_expand() |
|
195 | settings_maker.env_expand() | |
194 |
|
196 | |||
195 | # configure instance id |
|
197 | # configure instance id | |
196 | config_utils.set_instance_id(settings) |
|
198 | config_utils.set_instance_id(settings) | |
197 |
|
199 | |||
198 | return settings |
|
200 | return settings |
General Comments 0
You need to be logged in to leave comments.
Login now