Show More
@@ -1,632 +1,637 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 sys |
|
20 | import sys | |
21 | import collections |
|
21 | import collections | |
22 | import tempfile |
|
22 | import tempfile | |
23 | import time |
|
23 | import time | |
24 | import logging.config |
|
24 | import logging.config | |
25 |
|
25 | |||
26 | from paste.gzipper import make_gzip_middleware |
|
26 | from paste.gzipper import make_gzip_middleware | |
27 | import pyramid.events |
|
27 | import pyramid.events | |
28 | from pyramid.wsgi import wsgiapp |
|
28 | from pyramid.wsgi import wsgiapp | |
29 | from pyramid.authorization import ACLAuthorizationPolicy |
|
29 | from pyramid.authorization import ACLAuthorizationPolicy | |
30 | from pyramid.config import Configurator |
|
30 | from pyramid.config import Configurator | |
31 | from pyramid.settings import asbool, aslist |
|
31 | from pyramid.settings import asbool, aslist | |
32 | from pyramid.httpexceptions import ( |
|
32 | from pyramid.httpexceptions import ( | |
33 | HTTPException, HTTPError, HTTPInternalServerError, HTTPFound, HTTPNotFound) |
|
33 | HTTPException, HTTPError, HTTPInternalServerError, HTTPFound, HTTPNotFound) | |
34 | from pyramid.renderers import render_to_response |
|
34 | from pyramid.renderers import render_to_response | |
35 |
|
35 | |||
36 | from rhodecode.model import meta |
|
36 | from rhodecode.model import meta | |
37 | from rhodecode.config import patches |
|
37 | from rhodecode.config import patches | |
38 | from rhodecode.config import utils as config_utils |
|
38 | from rhodecode.config import utils as config_utils | |
39 | from rhodecode.config.settings_maker import SettingsMaker |
|
39 | from rhodecode.config.settings_maker import SettingsMaker | |
40 | from rhodecode.config.environment import load_pyramid_environment |
|
40 | from rhodecode.config.environment import load_pyramid_environment | |
41 |
|
41 | |||
42 | import rhodecode.events |
|
42 | import rhodecode.events | |
43 | from rhodecode.lib.middleware.vcs import VCSMiddleware |
|
43 | from rhodecode.lib.middleware.vcs import VCSMiddleware | |
44 | from rhodecode.lib.request import Request |
|
44 | from rhodecode.lib.request import Request | |
45 | from rhodecode.lib.vcs import VCSCommunicationError |
|
45 | from rhodecode.lib.vcs import VCSCommunicationError | |
46 | from rhodecode.lib.exceptions import VCSServerUnavailable |
|
46 | from rhodecode.lib.exceptions import VCSServerUnavailable | |
47 | from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled |
|
47 | from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled | |
48 | from rhodecode.lib.middleware.https_fixup import HttpsFixup |
|
48 | from rhodecode.lib.middleware.https_fixup import HttpsFixup | |
49 | from rhodecode.lib.plugins.utils import register_rhodecode_plugin |
|
49 | from rhodecode.lib.plugins.utils import register_rhodecode_plugin | |
50 | from rhodecode.lib.utils2 import AttributeDict |
|
50 | from rhodecode.lib.utils2 import AttributeDict | |
51 | from rhodecode.lib.exc_tracking import store_exception, format_exc |
|
51 | from rhodecode.lib.exc_tracking import store_exception, format_exc | |
52 | from rhodecode.subscribers import ( |
|
52 | from rhodecode.subscribers import ( | |
53 | scan_repositories_if_enabled, write_js_routes_if_enabled, |
|
53 | scan_repositories_if_enabled, write_js_routes_if_enabled, | |
54 | write_metadata_if_needed, write_usage_data) |
|
54 | write_metadata_if_needed, write_usage_data) | |
55 | from rhodecode.lib.statsd_client import StatsdClient |
|
55 | from rhodecode.lib.statsd_client import StatsdClient | |
56 |
|
56 | |||
57 | log = logging.getLogger(__name__) |
|
57 | log = logging.getLogger(__name__) | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | def is_http_error(response): |
|
60 | def is_http_error(response): | |
61 | # error which should have traceback |
|
61 | # error which should have traceback | |
62 | return response.status_code > 499 |
|
62 | return response.status_code > 499 | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | def should_load_all(): |
|
65 | def should_load_all(): | |
66 | """ |
|
66 | """ | |
67 | Returns if all application components should be loaded. In some cases it's |
|
67 | Returns if all application components should be loaded. In some cases it's | |
68 | desired to skip apps loading for faster shell script execution |
|
68 | desired to skip apps loading for faster shell script execution | |
69 | """ |
|
69 | """ | |
70 | ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER') |
|
70 | ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER') | |
71 | if ssh_cmd: |
|
71 | if ssh_cmd: | |
72 | return False |
|
72 | return False | |
73 |
|
73 | |||
74 | return True |
|
74 | return True | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | def make_pyramid_app(global_config, **settings): |
|
77 | def make_pyramid_app(global_config, **settings): | |
78 | """ |
|
78 | """ | |
79 | Constructs the WSGI application based on Pyramid. |
|
79 | Constructs the WSGI application based on Pyramid. | |
80 |
|
80 | |||
81 | Specials: |
|
81 | Specials: | |
82 |
|
82 | |||
83 | * The application can also be integrated like a plugin via the call to |
|
83 | * The application can also be integrated like a plugin via the call to | |
84 | `includeme`. This is accompanied with the other utility functions which |
|
84 | `includeme`. This is accompanied with the other utility functions which | |
85 | are called. Changing this should be done with great care to not break |
|
85 | are called. Changing this should be done with great care to not break | |
86 | cases when these fragments are assembled from another place. |
|
86 | cases when these fragments are assembled from another place. | |
87 |
|
87 | |||
88 | """ |
|
88 | """ | |
89 | start_time = time.time() |
|
89 | start_time = time.time() | |
90 | log.info('Pyramid app config starting') |
|
90 | log.info('Pyramid app config starting') | |
91 |
|
91 | |||
92 | sanitize_settings_and_apply_defaults(global_config, settings) |
|
92 | sanitize_settings_and_apply_defaults(global_config, settings) | |
93 |
|
93 | |||
94 | # init and bootstrap StatsdClient |
|
94 | # init and bootstrap StatsdClient | |
95 | StatsdClient.setup(settings) |
|
95 | StatsdClient.setup(settings) | |
96 |
|
96 | |||
97 | config = Configurator(settings=settings) |
|
97 | config = Configurator(settings=settings) | |
98 | # Init our statsd at very start |
|
98 | # Init our statsd at very start | |
99 | config.registry.statsd = StatsdClient.statsd |
|
99 | config.registry.statsd = StatsdClient.statsd | |
100 |
|
100 | |||
101 | # Apply compatibility patches |
|
101 | # Apply compatibility patches | |
102 | patches.inspect_getargspec() |
|
102 | patches.inspect_getargspec() | |
103 |
|
103 | |||
104 | load_pyramid_environment(global_config, settings) |
|
104 | load_pyramid_environment(global_config, settings) | |
105 |
|
105 | |||
106 | # Static file view comes first |
|
106 | # Static file view comes first | |
107 | includeme_first(config) |
|
107 | includeme_first(config) | |
108 |
|
108 | |||
109 | includeme(config) |
|
109 | includeme(config) | |
110 |
|
110 | |||
111 | pyramid_app = config.make_wsgi_app() |
|
111 | pyramid_app = config.make_wsgi_app() | |
112 | pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config) |
|
112 | pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config) | |
113 | pyramid_app.config = config |
|
113 | pyramid_app.config = config | |
114 |
|
114 | |||
115 | celery_settings = get_celery_config(settings) |
|
115 | celery_settings = get_celery_config(settings) | |
116 | config.configure_celery(celery_settings) |
|
116 | config.configure_celery(celery_settings) | |
117 |
|
117 | |||
118 | # creating the app uses a connection - return it after we are done |
|
118 | # creating the app uses a connection - return it after we are done | |
119 | meta.Session.remove() |
|
119 | meta.Session.remove() | |
120 |
|
120 | |||
121 | total_time = time.time() - start_time |
|
121 | total_time = time.time() - start_time | |
122 | log.info('Pyramid app created and configured in %.2fs', total_time) |
|
122 | log.info('Pyramid app created and configured in %.2fs', total_time) | |
123 | return pyramid_app |
|
123 | return pyramid_app | |
124 |
|
124 | |||
125 |
|
125 | |||
126 | def get_celery_config(settings): |
|
126 | def get_celery_config(settings): | |
127 | """ |
|
127 | """ | |
128 | Converts basic ini configuration into celery 4.X options |
|
128 | Converts basic ini configuration into celery 4.X options | |
129 | """ |
|
129 | """ | |
130 |
|
130 | |||
131 | def key_converter(key_name): |
|
131 | def key_converter(key_name): | |
132 | pref = 'celery.' |
|
132 | pref = 'celery.' | |
133 | if key_name.startswith(pref): |
|
133 | if key_name.startswith(pref): | |
134 | return key_name[len(pref):].replace('.', '_').lower() |
|
134 | return key_name[len(pref):].replace('.', '_').lower() | |
135 |
|
135 | |||
136 | def type_converter(parsed_key, value): |
|
136 | def type_converter(parsed_key, value): | |
137 | # cast to int |
|
137 | # cast to int | |
138 | if value.isdigit(): |
|
138 | if value.isdigit(): | |
139 | return int(value) |
|
139 | return int(value) | |
140 |
|
140 | |||
141 | # cast to bool |
|
141 | # cast to bool | |
142 | if value.lower() in ['true', 'false', 'True', 'False']: |
|
142 | if value.lower() in ['true', 'false', 'True', 'False']: | |
143 | return value.lower() == 'true' |
|
143 | return value.lower() == 'true' | |
144 | return value |
|
144 | return value | |
145 |
|
145 | |||
146 | celery_config = {} |
|
146 | celery_config = {} | |
147 | for k, v in settings.items(): |
|
147 | for k, v in settings.items(): | |
148 | pref = 'celery.' |
|
148 | pref = 'celery.' | |
149 | if k.startswith(pref): |
|
149 | if k.startswith(pref): | |
150 | celery_config[key_converter(k)] = type_converter(key_converter(k), v) |
|
150 | celery_config[key_converter(k)] = type_converter(key_converter(k), v) | |
151 |
|
151 | |||
152 | # TODO:rethink if we want to support celerybeat based file config, probably NOT |
|
152 | # TODO:rethink if we want to support celerybeat based file config, probably NOT | |
153 | # beat_config = {} |
|
153 | # beat_config = {} | |
154 | # for section in parser.sections(): |
|
154 | # for section in parser.sections(): | |
155 | # if section.startswith('celerybeat:'): |
|
155 | # if section.startswith('celerybeat:'): | |
156 | # name = section.split(':', 1)[1] |
|
156 | # name = section.split(':', 1)[1] | |
157 | # beat_config[name] = get_beat_config(parser, section) |
|
157 | # beat_config[name] = get_beat_config(parser, section) | |
158 |
|
158 | |||
159 | # final compose of settings |
|
159 | # final compose of settings | |
160 | celery_settings = {} |
|
160 | celery_settings = {} | |
161 |
|
161 | |||
162 | if celery_config: |
|
162 | if celery_config: | |
163 | celery_settings.update(celery_config) |
|
163 | celery_settings.update(celery_config) | |
164 | # if beat_config: |
|
164 | # if beat_config: | |
165 | # celery_settings.update({'beat_schedule': beat_config}) |
|
165 | # celery_settings.update({'beat_schedule': beat_config}) | |
166 |
|
166 | |||
167 | return celery_settings |
|
167 | return celery_settings | |
168 |
|
168 | |||
169 |
|
169 | |||
170 | def not_found_view(request): |
|
170 | def not_found_view(request): | |
171 | """ |
|
171 | """ | |
172 | This creates the view which should be registered as not-found-view to |
|
172 | This creates the view which should be registered as not-found-view to | |
173 | pyramid. |
|
173 | pyramid. | |
174 | """ |
|
174 | """ | |
175 |
|
175 | |||
176 | if not getattr(request, 'vcs_call', None): |
|
176 | if not getattr(request, 'vcs_call', None): | |
177 | # handle like regular case with our error_handler |
|
177 | # handle like regular case with our error_handler | |
178 | return error_handler(HTTPNotFound(), request) |
|
178 | return error_handler(HTTPNotFound(), request) | |
179 |
|
179 | |||
180 | # handle not found view as a vcs call |
|
180 | # handle not found view as a vcs call | |
181 | settings = request.registry.settings |
|
181 | settings = request.registry.settings | |
182 | ae_client = getattr(request, 'ae_client', None) |
|
182 | ae_client = getattr(request, 'ae_client', None) | |
183 | vcs_app = VCSMiddleware( |
|
183 | vcs_app = VCSMiddleware( | |
184 | HTTPNotFound(), request.registry, settings, |
|
184 | HTTPNotFound(), request.registry, settings, | |
185 | appenlight_client=ae_client) |
|
185 | appenlight_client=ae_client) | |
186 |
|
186 | |||
187 | return wsgiapp(vcs_app)(None, request) |
|
187 | return wsgiapp(vcs_app)(None, request) | |
188 |
|
188 | |||
189 |
|
189 | |||
190 | def error_handler(exception, request): |
|
190 | def error_handler(exception, request): | |
191 | import rhodecode |
|
191 | import rhodecode | |
192 | from rhodecode.lib import helpers |
|
192 | from rhodecode.lib import helpers | |
193 |
|
193 | |||
194 | rhodecode_title = rhodecode.CONFIG.get('rhodecode_title') or 'RhodeCode' |
|
194 | rhodecode_title = rhodecode.CONFIG.get('rhodecode_title') or 'RhodeCode' | |
195 |
|
195 | |||
196 | base_response = HTTPInternalServerError() |
|
196 | base_response = HTTPInternalServerError() | |
197 | # prefer original exception for the response since it may have headers set |
|
197 | # prefer original exception for the response since it may have headers set | |
198 | if isinstance(exception, HTTPException): |
|
198 | if isinstance(exception, HTTPException): | |
199 | base_response = exception |
|
199 | base_response = exception | |
200 | elif isinstance(exception, VCSCommunicationError): |
|
200 | elif isinstance(exception, VCSCommunicationError): | |
201 | base_response = VCSServerUnavailable() |
|
201 | base_response = VCSServerUnavailable() | |
202 |
|
202 | |||
203 | if is_http_error(base_response): |
|
203 | if is_http_error(base_response): | |
204 | traceback_info = format_exc(request.exc_info) |
|
204 | traceback_info = format_exc(request.exc_info) | |
205 | log.error( |
|
205 | log.error( | |
206 | 'error occurred handling this request for path: %s, \n%s', |
|
206 | 'error occurred handling this request for path: %s, \n%s', | |
207 | request.path, traceback_info) |
|
207 | request.path, traceback_info) | |
208 |
|
208 | |||
209 | error_explanation = base_response.explanation or str(base_response) |
|
209 | error_explanation = base_response.explanation or str(base_response) | |
210 | if base_response.status_code == 404: |
|
210 | if base_response.status_code == 404: | |
211 | error_explanation += " Optionally you don't have permission to access this page." |
|
211 | error_explanation += " Optionally you don't have permission to access this page." | |
212 | c = AttributeDict() |
|
212 | c = AttributeDict() | |
213 | c.error_message = base_response.status |
|
213 | c.error_message = base_response.status | |
214 | c.error_explanation = error_explanation |
|
214 | c.error_explanation = error_explanation | |
215 | c.visual = AttributeDict() |
|
215 | c.visual = AttributeDict() | |
216 |
|
216 | |||
217 | c.visual.rhodecode_support_url = ( |
|
217 | c.visual.rhodecode_support_url = ( | |
218 | request.registry.settings.get('rhodecode_support_url') or |
|
218 | request.registry.settings.get('rhodecode_support_url') or | |
219 | request.route_url('rhodecode_support') |
|
219 | request.route_url('rhodecode_support') | |
220 | ) |
|
220 | ) | |
221 | c.redirect_time = 0 |
|
221 | c.redirect_time = 0 | |
222 | c.rhodecode_name = rhodecode_title |
|
222 | c.rhodecode_name = rhodecode_title | |
223 | if not c.rhodecode_name: |
|
223 | if not c.rhodecode_name: | |
224 | c.rhodecode_name = 'Rhodecode' |
|
224 | c.rhodecode_name = 'Rhodecode' | |
225 |
|
225 | |||
226 | c.causes = [] |
|
226 | c.causes = [] | |
227 | if is_http_error(base_response): |
|
227 | if is_http_error(base_response): | |
228 | c.causes.append('Server is overloaded.') |
|
228 | c.causes.append('Server is overloaded.') | |
229 | c.causes.append('Server database connection is lost.') |
|
229 | c.causes.append('Server database connection is lost.') | |
230 | c.causes.append('Server expected unhandled error.') |
|
230 | c.causes.append('Server expected unhandled error.') | |
231 |
|
231 | |||
232 | if hasattr(base_response, 'causes'): |
|
232 | if hasattr(base_response, 'causes'): | |
233 | c.causes = base_response.causes |
|
233 | c.causes = base_response.causes | |
234 |
|
234 | |||
235 | c.messages = helpers.flash.pop_messages(request=request) |
|
235 | c.messages = helpers.flash.pop_messages(request=request) | |
236 | exc_info = sys.exc_info() |
|
236 | exc_info = sys.exc_info() | |
237 | c.exception_id = id(exc_info) |
|
237 | c.exception_id = id(exc_info) | |
238 | c.show_exception_id = isinstance(base_response, VCSServerUnavailable) \ |
|
238 | c.show_exception_id = isinstance(base_response, VCSServerUnavailable) \ | |
239 | or base_response.status_code > 499 |
|
239 | or base_response.status_code > 499 | |
240 | c.exception_id_url = request.route_url( |
|
240 | c.exception_id_url = request.route_url( | |
241 | 'admin_settings_exception_tracker_show', exception_id=c.exception_id) |
|
241 | 'admin_settings_exception_tracker_show', exception_id=c.exception_id) | |
242 |
|
242 | |||
243 | debug_mode = rhodecode.ConfigGet().get_bool('debug') |
|
243 | debug_mode = rhodecode.ConfigGet().get_bool('debug') | |
244 | if c.show_exception_id: |
|
244 | if c.show_exception_id: | |
245 | store_exception(c.exception_id, exc_info) |
|
245 | store_exception(c.exception_id, exc_info) | |
246 | c.exception_debug = debug_mode |
|
246 | c.exception_debug = debug_mode | |
247 | c.exception_config_ini = rhodecode.CONFIG.get('__file__') |
|
247 | c.exception_config_ini = rhodecode.CONFIG.get('__file__') | |
248 |
|
248 | |||
249 | if debug_mode: |
|
249 | if debug_mode: | |
250 | try: |
|
250 | try: | |
251 | from rich.traceback import install |
|
251 | from rich.traceback import install | |
252 | install(show_locals=True) |
|
252 | install(show_locals=True) | |
253 | log.debug('Installing rich tracebacks...') |
|
253 | log.debug('Installing rich tracebacks...') | |
254 | except ImportError: |
|
254 | except ImportError: | |
255 | pass |
|
255 | pass | |
256 |
|
256 | |||
257 | response = render_to_response( |
|
257 | response = render_to_response( | |
258 | '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request, |
|
258 | '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request, | |
259 | response=base_response) |
|
259 | response=base_response) | |
260 |
|
260 | |||
261 | response.headers["X-RC-Exception-Id"] = str(c.exception_id) |
|
261 | response.headers["X-RC-Exception-Id"] = str(c.exception_id) | |
262 |
|
262 | |||
263 | statsd = request.registry.statsd |
|
263 | statsd = request.registry.statsd | |
264 | if statsd and base_response.status_code > 499: |
|
264 | if statsd and base_response.status_code > 499: | |
265 | exc_type = f"{exception.__class__.__module__}.{exception.__class__.__name__}" |
|
265 | exc_type = f"{exception.__class__.__module__}.{exception.__class__.__name__}" | |
266 | statsd.incr('rhodecode_exception_total', |
|
266 | statsd.incr('rhodecode_exception_total', | |
267 | tags=["exc_source:web", |
|
267 | tags=["exc_source:web", | |
268 | f"http_code:{base_response.status_code}", |
|
268 | f"http_code:{base_response.status_code}", | |
269 | f"type:{exc_type}"]) |
|
269 | f"type:{exc_type}"]) | |
270 |
|
270 | |||
271 | return response |
|
271 | return response | |
272 |
|
272 | |||
273 |
|
273 | |||
274 | def includeme_first(config): |
|
274 | def includeme_first(config): | |
275 | # redirect automatic browser favicon.ico requests to correct place |
|
275 | # redirect automatic browser favicon.ico requests to correct place | |
276 | def favicon_redirect(context, request): |
|
276 | def favicon_redirect(context, request): | |
277 | return HTTPFound( |
|
277 | return HTTPFound( | |
278 | request.static_path('rhodecode:public/images/favicon.ico')) |
|
278 | request.static_path('rhodecode:public/images/favicon.ico')) | |
279 |
|
279 | |||
280 | config.add_view(favicon_redirect, route_name='favicon') |
|
280 | config.add_view(favicon_redirect, route_name='favicon') | |
281 | config.add_route('favicon', '/favicon.ico') |
|
281 | config.add_route('favicon', '/favicon.ico') | |
282 |
|
282 | |||
283 | def robots_redirect(context, request): |
|
283 | def robots_redirect(context, request): | |
284 | return HTTPFound( |
|
284 | return HTTPFound( | |
285 | request.static_path('rhodecode:public/robots.txt')) |
|
285 | request.static_path('rhodecode:public/robots.txt')) | |
286 |
|
286 | |||
287 | config.add_view(robots_redirect, route_name='robots') |
|
287 | config.add_view(robots_redirect, route_name='robots') | |
288 | config.add_route('robots', '/robots.txt') |
|
288 | config.add_route('robots', '/robots.txt') | |
289 |
|
289 | |||
290 | config.add_static_view( |
|
290 | config.add_static_view( | |
291 | '_static/deform', 'deform:static') |
|
291 | '_static/deform', 'deform:static') | |
292 | config.add_static_view( |
|
292 | config.add_static_view( | |
293 | '_static/rhodecode', path='rhodecode:public', cache_max_age=3600 * 24) |
|
293 | '_static/rhodecode', path='rhodecode:public', cache_max_age=3600 * 24) | |
294 |
|
294 | |||
295 |
|
295 | |||
296 | ce_auth_resources = [ |
|
296 | ce_auth_resources = [ | |
297 | 'rhodecode.authentication.plugins.auth_crowd', |
|
297 | 'rhodecode.authentication.plugins.auth_crowd', | |
298 | 'rhodecode.authentication.plugins.auth_headers', |
|
298 | 'rhodecode.authentication.plugins.auth_headers', | |
299 | 'rhodecode.authentication.plugins.auth_jasig_cas', |
|
299 | 'rhodecode.authentication.plugins.auth_jasig_cas', | |
300 | 'rhodecode.authentication.plugins.auth_ldap', |
|
300 | 'rhodecode.authentication.plugins.auth_ldap', | |
301 | 'rhodecode.authentication.plugins.auth_pam', |
|
301 | 'rhodecode.authentication.plugins.auth_pam', | |
302 | 'rhodecode.authentication.plugins.auth_rhodecode', |
|
302 | 'rhodecode.authentication.plugins.auth_rhodecode', | |
303 | 'rhodecode.authentication.plugins.auth_token', |
|
303 | 'rhodecode.authentication.plugins.auth_token', | |
304 | ] |
|
304 | ] | |
305 |
|
305 | |||
306 |
|
306 | |||
307 | def includeme(config, auth_resources=None): |
|
307 | def includeme(config, auth_resources=None): | |
308 | from rhodecode.lib.celerylib.loader import configure_celery |
|
308 | from rhodecode.lib.celerylib.loader import configure_celery | |
309 | log.debug('Initializing main includeme from %s', os.path.basename(__file__)) |
|
309 | log.debug('Initializing main includeme from %s', os.path.basename(__file__)) | |
310 | settings = config.registry.settings |
|
310 | settings = config.registry.settings | |
311 | config.set_request_factory(Request) |
|
311 | config.set_request_factory(Request) | |
312 |
|
312 | |||
313 | # plugin information |
|
313 | # plugin information | |
314 | config.registry.rhodecode_plugins = collections.OrderedDict() |
|
314 | config.registry.rhodecode_plugins = collections.OrderedDict() | |
315 |
|
315 | |||
316 | config.add_directive( |
|
316 | config.add_directive( | |
317 | 'register_rhodecode_plugin', register_rhodecode_plugin) |
|
317 | 'register_rhodecode_plugin', register_rhodecode_plugin) | |
318 |
|
318 | |||
319 | config.add_directive('configure_celery', configure_celery) |
|
319 | config.add_directive('configure_celery', configure_celery) | |
320 |
|
320 | |||
321 | if settings.get('appenlight', False): |
|
321 | if settings.get('appenlight', False): | |
322 | config.include('appenlight_client.ext.pyramid_tween') |
|
322 | config.include('appenlight_client.ext.pyramid_tween') | |
323 |
|
323 | |||
324 | load_all = should_load_all() |
|
324 | load_all = should_load_all() | |
325 |
|
325 | |||
326 | # Includes which are required. The application would fail without them. |
|
326 | # Includes which are required. The application would fail without them. | |
327 | config.include('pyramid_mako') |
|
327 | config.include('pyramid_mako') | |
328 | config.include('rhodecode.lib.rc_beaker') |
|
328 | config.include('rhodecode.lib.rc_beaker') | |
329 | config.include('rhodecode.lib.rc_cache') |
|
329 | config.include('rhodecode.lib.rc_cache') | |
330 | config.include('rhodecode.lib.rc_cache.archive_cache') |
|
330 | config.include('rhodecode.lib.rc_cache.archive_cache') | |
331 |
|
331 | |||
332 | config.include('rhodecode.apps._base.navigation') |
|
332 | config.include('rhodecode.apps._base.navigation') | |
333 | config.include('rhodecode.apps._base.subscribers') |
|
333 | config.include('rhodecode.apps._base.subscribers') | |
334 | config.include('rhodecode.tweens') |
|
334 | config.include('rhodecode.tweens') | |
335 | config.include('rhodecode.authentication') |
|
335 | config.include('rhodecode.authentication') | |
336 |
|
336 | |||
337 | if load_all: |
|
337 | if load_all: | |
338 |
|
338 | |||
339 | # load CE authentication plugins |
|
339 | # load CE authentication plugins | |
340 |
|
340 | |||
341 | if auth_resources: |
|
341 | if auth_resources: | |
342 | ce_auth_resources.extend(auth_resources) |
|
342 | ce_auth_resources.extend(auth_resources) | |
343 |
|
343 | |||
344 | for resource in ce_auth_resources: |
|
344 | for resource in ce_auth_resources: | |
345 | config.include(resource) |
|
345 | config.include(resource) | |
346 |
|
346 | |||
347 | # Auto discover authentication plugins and include their configuration. |
|
347 | # Auto discover authentication plugins and include their configuration. | |
348 | if asbool(settings.get('auth_plugin.import_legacy_plugins', 'true')): |
|
348 | if asbool(settings.get('auth_plugin.import_legacy_plugins', 'true')): | |
349 | from rhodecode.authentication import discover_legacy_plugins |
|
349 | from rhodecode.authentication import discover_legacy_plugins | |
350 | discover_legacy_plugins(config) |
|
350 | discover_legacy_plugins(config) | |
351 |
|
351 | |||
352 | # apps |
|
352 | # apps | |
353 | if load_all: |
|
353 | if load_all: | |
354 | log.debug('Starting config.include() calls') |
|
354 | log.debug('Starting config.include() calls') | |
355 | config.include('rhodecode.api.includeme') |
|
355 | config.include('rhodecode.api.includeme') | |
356 | config.include('rhodecode.apps._base.includeme') |
|
356 | config.include('rhodecode.apps._base.includeme') | |
357 | config.include('rhodecode.apps._base.navigation.includeme') |
|
357 | config.include('rhodecode.apps._base.navigation.includeme') | |
358 | config.include('rhodecode.apps._base.subscribers.includeme') |
|
358 | config.include('rhodecode.apps._base.subscribers.includeme') | |
359 | config.include('rhodecode.apps.hovercards.includeme') |
|
359 | config.include('rhodecode.apps.hovercards.includeme') | |
360 | config.include('rhodecode.apps.ops.includeme') |
|
360 | config.include('rhodecode.apps.ops.includeme') | |
361 | config.include('rhodecode.apps.channelstream.includeme') |
|
361 | config.include('rhodecode.apps.channelstream.includeme') | |
362 | config.include('rhodecode.apps.file_store.includeme') |
|
362 | config.include('rhodecode.apps.file_store.includeme') | |
363 | config.include('rhodecode.apps.admin.includeme') |
|
363 | config.include('rhodecode.apps.admin.includeme') | |
364 | config.include('rhodecode.apps.login.includeme') |
|
364 | config.include('rhodecode.apps.login.includeme') | |
365 | config.include('rhodecode.apps.home.includeme') |
|
365 | config.include('rhodecode.apps.home.includeme') | |
366 | config.include('rhodecode.apps.journal.includeme') |
|
366 | config.include('rhodecode.apps.journal.includeme') | |
367 |
|
367 | |||
368 | config.include('rhodecode.apps.repository.includeme') |
|
368 | config.include('rhodecode.apps.repository.includeme') | |
369 | config.include('rhodecode.apps.repo_group.includeme') |
|
369 | config.include('rhodecode.apps.repo_group.includeme') | |
370 | config.include('rhodecode.apps.user_group.includeme') |
|
370 | config.include('rhodecode.apps.user_group.includeme') | |
371 | config.include('rhodecode.apps.search.includeme') |
|
371 | config.include('rhodecode.apps.search.includeme') | |
372 | config.include('rhodecode.apps.user_profile.includeme') |
|
372 | config.include('rhodecode.apps.user_profile.includeme') | |
373 | config.include('rhodecode.apps.user_group_profile.includeme') |
|
373 | config.include('rhodecode.apps.user_group_profile.includeme') | |
374 | config.include('rhodecode.apps.my_account.includeme') |
|
374 | config.include('rhodecode.apps.my_account.includeme') | |
375 | config.include('rhodecode.apps.gist.includeme') |
|
375 | config.include('rhodecode.apps.gist.includeme') | |
376 |
|
376 | |||
377 | config.include('rhodecode.apps.svn_support.includeme') |
|
377 | config.include('rhodecode.apps.svn_support.includeme') | |
378 | config.include('rhodecode.apps.ssh_support.includeme') |
|
378 | config.include('rhodecode.apps.ssh_support.includeme') | |
379 | config.include('rhodecode.apps.debug_style') |
|
379 | config.include('rhodecode.apps.debug_style') | |
380 |
|
380 | |||
381 | if load_all: |
|
381 | if load_all: | |
382 | config.include('rhodecode.integrations.includeme') |
|
382 | config.include('rhodecode.integrations.includeme') | |
383 | config.include('rhodecode.integrations.routes.includeme') |
|
383 | config.include('rhodecode.integrations.routes.includeme') | |
384 |
|
384 | |||
385 | config.add_route('rhodecode_support', 'https://rhodecode.com/help/', static=True) |
|
385 | config.add_route('rhodecode_support', 'https://rhodecode.com/help/', static=True) | |
386 | settings['default_locale_name'] = settings.get('lang', 'en') |
|
386 | settings['default_locale_name'] = settings.get('lang', 'en') | |
387 | config.add_translation_dirs('rhodecode:i18n/') |
|
387 | config.add_translation_dirs('rhodecode:i18n/') | |
388 |
|
388 | |||
389 | # Add subscribers. |
|
389 | # Add subscribers. | |
390 | if load_all: |
|
390 | if load_all: | |
391 | log.debug('Adding subscribers....') |
|
391 | log.debug('Adding subscribers....') | |
392 | config.add_subscriber(scan_repositories_if_enabled, |
|
392 | config.add_subscriber(scan_repositories_if_enabled, | |
393 | pyramid.events.ApplicationCreated) |
|
393 | pyramid.events.ApplicationCreated) | |
394 | config.add_subscriber(write_metadata_if_needed, |
|
394 | config.add_subscriber(write_metadata_if_needed, | |
395 | pyramid.events.ApplicationCreated) |
|
395 | pyramid.events.ApplicationCreated) | |
396 | config.add_subscriber(write_usage_data, |
|
396 | config.add_subscriber(write_usage_data, | |
397 | pyramid.events.ApplicationCreated) |
|
397 | pyramid.events.ApplicationCreated) | |
398 | config.add_subscriber(write_js_routes_if_enabled, |
|
398 | config.add_subscriber(write_js_routes_if_enabled, | |
399 | pyramid.events.ApplicationCreated) |
|
399 | pyramid.events.ApplicationCreated) | |
400 |
|
400 | |||
401 |
|
401 | |||
402 | # Set the default renderer for HTML templates to mako. |
|
402 | # Set the default renderer for HTML templates to mako. | |
403 | config.add_mako_renderer('.html') |
|
403 | config.add_mako_renderer('.html') | |
404 |
|
404 | |||
405 | config.add_renderer( |
|
405 | config.add_renderer( | |
406 | name='json_ext', |
|
406 | name='json_ext', | |
407 | factory='rhodecode.lib.ext_json_renderer.pyramid_ext_json') |
|
407 | factory='rhodecode.lib.ext_json_renderer.pyramid_ext_json') | |
408 |
|
408 | |||
409 | config.add_renderer( |
|
409 | config.add_renderer( | |
410 | name='string_html', |
|
410 | name='string_html', | |
411 | factory='rhodecode.lib.string_renderer.html') |
|
411 | factory='rhodecode.lib.string_renderer.html') | |
412 |
|
412 | |||
413 | # include RhodeCode plugins |
|
413 | # include RhodeCode plugins | |
414 | includes = aslist(settings.get('rhodecode.includes', [])) |
|
414 | includes = aslist(settings.get('rhodecode.includes', [])) | |
415 | log.debug('processing rhodecode.includes data...') |
|
415 | log.debug('processing rhodecode.includes data...') | |
416 | for inc in includes: |
|
416 | for inc in includes: | |
417 | config.include(inc) |
|
417 | config.include(inc) | |
418 |
|
418 | |||
419 | # custom not found view, if our pyramid app doesn't know how to handle |
|
419 | # custom not found view, if our pyramid app doesn't know how to handle | |
420 | # the request pass it to potential VCS handling ap |
|
420 | # the request pass it to potential VCS handling ap | |
421 | config.add_notfound_view(not_found_view) |
|
421 | config.add_notfound_view(not_found_view) | |
422 | if not settings.get('debugtoolbar.enabled', False): |
|
422 | if not settings.get('debugtoolbar.enabled', False): | |
423 | # disabled debugtoolbar handle all exceptions via the error_handlers |
|
423 | # disabled debugtoolbar handle all exceptions via the error_handlers | |
424 | config.add_view(error_handler, context=Exception) |
|
424 | config.add_view(error_handler, context=Exception) | |
425 |
|
425 | |||
426 | # all errors including 403/404/50X |
|
426 | # all errors including 403/404/50X | |
427 | config.add_view(error_handler, context=HTTPError) |
|
427 | config.add_view(error_handler, context=HTTPError) | |
428 |
|
428 | |||
429 |
|
429 | |||
430 | def wrap_app_in_wsgi_middlewares(pyramid_app, config): |
|
430 | def wrap_app_in_wsgi_middlewares(pyramid_app, config): | |
431 | """ |
|
431 | """ | |
432 | Apply outer WSGI middlewares around the application. |
|
432 | Apply outer WSGI middlewares around the application. | |
433 | """ |
|
433 | """ | |
434 | registry = config.registry |
|
434 | registry = config.registry | |
435 | settings = registry.settings |
|
435 | settings = registry.settings | |
436 |
|
436 | |||
437 | # enable https redirects based on HTTP_X_URL_SCHEME set by proxy |
|
437 | # enable https redirects based on HTTP_X_URL_SCHEME set by proxy | |
438 | pyramid_app = HttpsFixup(pyramid_app, settings) |
|
438 | pyramid_app = HttpsFixup(pyramid_app, settings) | |
439 |
|
439 | |||
440 | pyramid_app, _ae_client = wrap_in_appenlight_if_enabled( |
|
440 | pyramid_app, _ae_client = wrap_in_appenlight_if_enabled( | |
441 | pyramid_app, settings) |
|
441 | pyramid_app, settings) | |
442 | registry.ae_client = _ae_client |
|
442 | registry.ae_client = _ae_client | |
443 |
|
443 | |||
444 | if settings['gzip_responses']: |
|
444 | if settings['gzip_responses']: | |
445 | pyramid_app = make_gzip_middleware( |
|
445 | pyramid_app = make_gzip_middleware( | |
446 | pyramid_app, settings, compress_level=1) |
|
446 | pyramid_app, settings, compress_level=1) | |
447 |
|
447 | |||
448 | # this should be the outer most middleware in the wsgi stack since |
|
448 | # this should be the outer most middleware in the wsgi stack since | |
449 | # middleware like Routes make database calls |
|
449 | # middleware like Routes make database calls | |
450 | def pyramid_app_with_cleanup(environ, start_response): |
|
450 | def pyramid_app_with_cleanup(environ, start_response): | |
451 | start = time.time() |
|
451 | start = time.time() | |
452 | try: |
|
452 | try: | |
453 | return pyramid_app(environ, start_response) |
|
453 | return pyramid_app(environ, start_response) | |
454 | finally: |
|
454 | finally: | |
455 | # Dispose current database session and rollback uncommitted |
|
455 | # Dispose current database session and rollback uncommitted | |
456 | # transactions. |
|
456 | # transactions. | |
457 | meta.Session.remove() |
|
457 | meta.Session.remove() | |
458 |
|
458 | |||
459 | # In a single threaded mode server, on non sqlite db we should have |
|
459 | # In a single threaded mode server, on non sqlite db we should have | |
460 | # '0 Current Checked out connections' at the end of a request, |
|
460 | # '0 Current Checked out connections' at the end of a request, | |
461 | # if not, then something, somewhere is leaving a connection open |
|
461 | # if not, then something, somewhere is leaving a connection open | |
462 | pool = meta.get_engine().pool |
|
462 | pool = meta.get_engine().pool | |
463 | log.debug('sa pool status: %s', pool.status()) |
|
463 | log.debug('sa pool status: %s', pool.status()) | |
464 | total = time.time() - start |
|
464 | total = time.time() - start | |
465 | log.debug('Request processing finalized: %.4fs', total) |
|
465 | log.debug('Request processing finalized: %.4fs', total) | |
466 |
|
466 | |||
467 | return pyramid_app_with_cleanup |
|
467 | return pyramid_app_with_cleanup | |
468 |
|
468 | |||
469 |
|
469 | |||
470 | def sanitize_settings_and_apply_defaults(global_config, settings): |
|
470 | def sanitize_settings_and_apply_defaults(global_config, settings): | |
471 | """ |
|
471 | """ | |
472 | Applies settings defaults and does all type conversion. |
|
472 | Applies settings defaults and does all type conversion. | |
473 |
|
473 | |||
474 | We would move all settings parsing and preparation into this place, so that |
|
474 | We would move all settings parsing and preparation into this place, so that | |
475 | we have only one place left which deals with this part. The remaining parts |
|
475 | we have only one place left which deals with this part. The remaining parts | |
476 | of the application would start to rely fully on well prepared settings. |
|
476 | of the application would start to rely fully on well prepared settings. | |
477 |
|
477 | |||
478 | This piece would later be split up per topic to avoid a big fat monster |
|
478 | This piece would later be split up per topic to avoid a big fat monster | |
479 | function. |
|
479 | function. | |
480 | """ |
|
480 | """ | |
|
481 | jn = os.path.join | |||
481 |
|
482 | |||
482 | global_settings_maker = SettingsMaker(global_config) |
|
483 | global_settings_maker = SettingsMaker(global_config) | |
483 | global_settings_maker.make_setting('debug', default=False, parser='bool') |
|
484 | global_settings_maker.make_setting('debug', default=False, parser='bool') | |
484 | debug_enabled = asbool(global_config.get('debug')) |
|
485 | debug_enabled = asbool(global_config.get('debug')) | |
485 |
|
486 | |||
486 | settings_maker = SettingsMaker(settings) |
|
487 | settings_maker = SettingsMaker(settings) | |
487 |
|
488 | |||
488 | settings_maker.make_setting( |
|
489 | settings_maker.make_setting( | |
489 | 'logging.autoconfigure', |
|
490 | 'logging.autoconfigure', | |
490 | default=False, |
|
491 | default=False, | |
491 | parser='bool') |
|
492 | parser='bool') | |
492 |
|
493 | |||
493 |
logging_conf = |
|
494 | logging_conf = jn(os.path.dirname(global_config.get('__file__')), 'logging.ini') | |
494 | settings_maker.enable_logging(logging_conf, level='INFO' if debug_enabled else 'DEBUG') |
|
495 | settings_maker.enable_logging(logging_conf, level='INFO' if debug_enabled else 'DEBUG') | |
495 |
|
496 | |||
496 | # Default includes, possible to change as a user |
|
497 | # Default includes, possible to change as a user | |
497 | pyramid_includes = settings_maker.make_setting('pyramid.includes', [], parser='list:newline') |
|
498 | pyramid_includes = settings_maker.make_setting('pyramid.includes', [], parser='list:newline') | |
498 | log.debug( |
|
499 | log.debug( | |
499 | "Using the following pyramid.includes: %s", |
|
500 | "Using the following pyramid.includes: %s", | |
500 | pyramid_includes) |
|
501 | pyramid_includes) | |
501 |
|
502 | |||
502 | settings_maker.make_setting('rhodecode.edition', 'Community Edition') |
|
503 | settings_maker.make_setting('rhodecode.edition', 'Community Edition') | |
503 | settings_maker.make_setting('rhodecode.edition_id', 'CE') |
|
504 | settings_maker.make_setting('rhodecode.edition_id', 'CE') | |
504 |
|
505 | |||
505 | if 'mako.default_filters' not in settings: |
|
506 | if 'mako.default_filters' not in settings: | |
506 | # set custom default filters if we don't have it defined |
|
507 | # set custom default filters if we don't have it defined | |
507 | settings['mako.imports'] = 'from rhodecode.lib.base import h_filter' |
|
508 | settings['mako.imports'] = 'from rhodecode.lib.base import h_filter' | |
508 | settings['mako.default_filters'] = 'h_filter' |
|
509 | settings['mako.default_filters'] = 'h_filter' | |
509 |
|
510 | |||
510 | if 'mako.directories' not in settings: |
|
511 | if 'mako.directories' not in settings: | |
511 | mako_directories = settings.setdefault('mako.directories', [ |
|
512 | mako_directories = settings.setdefault('mako.directories', [ | |
512 | # Base templates of the original application |
|
513 | # Base templates of the original application | |
513 | 'rhodecode:templates', |
|
514 | 'rhodecode:templates', | |
514 | ]) |
|
515 | ]) | |
515 | log.debug( |
|
516 | log.debug( | |
516 | "Using the following Mako template directories: %s", |
|
517 | "Using the following Mako template directories: %s", | |
517 | mako_directories) |
|
518 | mako_directories) | |
518 |
|
519 | |||
519 | # NOTE(marcink): fix redis requirement for schema of connection since 3.X |
|
520 | # NOTE(marcink): fix redis requirement for schema of connection since 3.X | |
520 | if 'beaker.session.type' in settings and settings['beaker.session.type'] == 'ext:redis': |
|
521 | if 'beaker.session.type' in settings and settings['beaker.session.type'] == 'ext:redis': | |
521 | raw_url = settings['beaker.session.url'] |
|
522 | raw_url = settings['beaker.session.url'] | |
522 | if not raw_url.startswith(('redis://', 'rediss://', 'unix://')): |
|
523 | if not raw_url.startswith(('redis://', 'rediss://', 'unix://')): | |
523 | settings['beaker.session.url'] = 'redis://' + raw_url |
|
524 | settings['beaker.session.url'] = 'redis://' + raw_url | |
524 |
|
525 | |||
525 | settings_maker.make_setting('__file__', global_config.get('__file__')) |
|
526 | settings_maker.make_setting('__file__', global_config.get('__file__')) | |
526 |
|
527 | |||
527 | # TODO: johbo: Re-think this, usually the call to config.include |
|
528 | # TODO: johbo: Re-think this, usually the call to config.include | |
528 | # should allow to pass in a prefix. |
|
529 | # should allow to pass in a prefix. | |
529 | settings_maker.make_setting('rhodecode.api.url', '/_admin/api') |
|
530 | settings_maker.make_setting('rhodecode.api.url', '/_admin/api') | |
530 |
|
531 | |||
531 | # Sanitize generic settings. |
|
532 | # Sanitize generic settings. | |
532 | settings_maker.make_setting('default_encoding', 'UTF-8', parser='list') |
|
533 | settings_maker.make_setting('default_encoding', 'UTF-8', parser='list') | |
533 | settings_maker.make_setting('is_test', False, parser='bool') |
|
534 | settings_maker.make_setting('is_test', False, parser='bool') | |
534 | settings_maker.make_setting('gzip_responses', False, parser='bool') |
|
535 | settings_maker.make_setting('gzip_responses', False, parser='bool') | |
535 |
|
536 | |||
536 | # statsd |
|
537 | # statsd | |
537 | settings_maker.make_setting('statsd.enabled', False, parser='bool') |
|
538 | settings_maker.make_setting('statsd.enabled', False, parser='bool') | |
538 | settings_maker.make_setting('statsd.statsd_host', 'statsd-exporter', parser='string') |
|
539 | settings_maker.make_setting('statsd.statsd_host', 'statsd-exporter', parser='string') | |
539 | settings_maker.make_setting('statsd.statsd_port', 9125, parser='int') |
|
540 | settings_maker.make_setting('statsd.statsd_port', 9125, parser='int') | |
540 | settings_maker.make_setting('statsd.statsd_prefix', '') |
|
541 | settings_maker.make_setting('statsd.statsd_prefix', '') | |
541 | settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') |
|
542 | settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') | |
542 |
|
543 | |||
543 | settings_maker.make_setting('vcs.svn.compatible_version', '') |
|
544 | settings_maker.make_setting('vcs.svn.compatible_version', '') | |
544 | settings_maker.make_setting('vcs.hooks.protocol', 'http') |
|
545 | settings_maker.make_setting('vcs.hooks.protocol', 'http') | |
545 | settings_maker.make_setting('vcs.hooks.host', '*') |
|
546 | settings_maker.make_setting('vcs.hooks.host', '*') | |
546 | settings_maker.make_setting('vcs.scm_app_implementation', 'http') |
|
547 | settings_maker.make_setting('vcs.scm_app_implementation', 'http') | |
547 | settings_maker.make_setting('vcs.server', '') |
|
548 | settings_maker.make_setting('vcs.server', '') | |
548 | settings_maker.make_setting('vcs.server.protocol', 'http') |
|
549 | settings_maker.make_setting('vcs.server.protocol', 'http') | |
549 | settings_maker.make_setting('vcs.server.enable', 'true', parser='bool') |
|
550 | settings_maker.make_setting('vcs.server.enable', 'true', parser='bool') | |
550 | settings_maker.make_setting('startup.import_repos', 'false', parser='bool') |
|
551 | settings_maker.make_setting('startup.import_repos', 'false', parser='bool') | |
551 | settings_maker.make_setting('vcs.hooks.direct_calls', 'false', parser='bool') |
|
552 | settings_maker.make_setting('vcs.hooks.direct_calls', 'false', parser='bool') | |
552 | settings_maker.make_setting('vcs.start_server', 'false', parser='bool') |
|
553 | settings_maker.make_setting('vcs.start_server', 'false', parser='bool') | |
553 | settings_maker.make_setting('vcs.backends', 'hg, git, svn', parser='list') |
|
554 | settings_maker.make_setting('vcs.backends', 'hg, git, svn', parser='list') | |
554 | settings_maker.make_setting('vcs.connection_timeout', 3600, parser='int') |
|
555 | settings_maker.make_setting('vcs.connection_timeout', 3600, parser='int') | |
555 |
|
556 | |||
556 | settings_maker.make_setting('vcs.methods.cache', True, parser='bool') |
|
557 | settings_maker.make_setting('vcs.methods.cache', True, parser='bool') | |
557 |
|
558 | |||
558 | # Support legacy values of vcs.scm_app_implementation. Legacy |
|
559 | # Support legacy values of vcs.scm_app_implementation. Legacy | |
559 | # configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or |
|
560 | # configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or | |
560 | # disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'. |
|
561 | # disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'. | |
561 | scm_app_impl = settings['vcs.scm_app_implementation'] |
|
562 | scm_app_impl = settings['vcs.scm_app_implementation'] | |
562 | if scm_app_impl in ['rhodecode.lib.middleware.utils.scm_app_http', 'vcsserver.scm_app']: |
|
563 | if scm_app_impl in ['rhodecode.lib.middleware.utils.scm_app_http', 'vcsserver.scm_app']: | |
563 | settings['vcs.scm_app_implementation'] = 'http' |
|
564 | settings['vcs.scm_app_implementation'] = 'http' | |
564 |
|
565 | |||
565 | settings_maker.make_setting('appenlight', False, parser='bool') |
|
566 | settings_maker.make_setting('appenlight', False, parser='bool') | |
566 |
|
567 | |||
567 | temp_store = tempfile.gettempdir() |
|
568 | temp_store = tempfile.gettempdir() | |
568 |
tmp_cache_dir = |
|
569 | tmp_cache_dir = jn(temp_store, 'rc_cache') | |
569 |
|
570 | |||
570 | # save default, cache dir, and use it for all backends later. |
|
571 | # save default, cache dir, and use it for all backends later. | |
571 | default_cache_dir = settings_maker.make_setting( |
|
572 | default_cache_dir = settings_maker.make_setting( | |
572 | 'cache_dir', |
|
573 | 'cache_dir', | |
573 | default=tmp_cache_dir, default_when_empty=True, |
|
574 | default=tmp_cache_dir, default_when_empty=True, | |
574 | parser='dir:ensured') |
|
575 | parser='dir:ensured') | |
575 |
|
576 | |||
576 | # exception store cache |
|
577 | # exception store cache | |
577 | settings_maker.make_setting( |
|
578 | settings_maker.make_setting( | |
578 | 'exception_tracker.store_path', |
|
579 | 'exception_tracker.store_path', | |
579 |
default= |
|
580 | default=jn(default_cache_dir, 'exc_store'), default_when_empty=True, | |
580 | parser='dir:ensured' |
|
581 | parser='dir:ensured' | |
581 | ) |
|
582 | ) | |
582 |
|
583 | |||
583 | settings_maker.make_setting( |
|
584 | settings_maker.make_setting( | |
584 | 'celerybeat-schedule.path', |
|
585 | 'celerybeat-schedule.path', | |
585 |
default= |
|
586 | default=jn(default_cache_dir, 'celerybeat_schedule', 'celerybeat-schedule.db'), default_when_empty=True, | |
586 | parser='file:ensured' |
|
587 | parser='file:ensured' | |
587 | ) |
|
588 | ) | |
588 |
|
589 | |||
589 | settings_maker.make_setting('exception_tracker.send_email', False, parser='bool') |
|
590 | settings_maker.make_setting('exception_tracker.send_email', False, parser='bool') | |
590 | settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True) |
|
591 | settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True) | |
591 |
|
592 | |||
|
593 | # sessions, ensure file since no-value is memory | |||
|
594 | settings_maker.make_setting('beaker.session.type', 'file') | |||
|
595 | settings_maker.make_setting('beaker.session.data_dir', jn(default_cache_dir, 'session_data')) | |||
|
596 | ||||
592 | # cache_general |
|
597 | # cache_general | |
593 | settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace') |
|
598 | settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace') | |
594 | settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int') |
|
599 | settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int') | |
595 |
settings_maker.make_setting('rc_cache.cache_general.arguments.filename', |
|
600 | settings_maker.make_setting('rc_cache.cache_general.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_general.db')) | |
596 |
|
601 | |||
597 | # cache_perms |
|
602 | # cache_perms | |
598 | settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace') |
|
603 | settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace') | |
599 | settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int') |
|
604 | settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int') | |
600 |
settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', |
|
605 | settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_perms_db')) | |
601 |
|
606 | |||
602 | # cache_repo |
|
607 | # cache_repo | |
603 | settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace') |
|
608 | settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace') | |
604 | settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int') |
|
609 | settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int') | |
605 |
settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', |
|
610 | settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_repo_db')) | |
606 |
|
611 | |||
607 | # cache_license |
|
612 | # cache_license | |
608 | settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace') |
|
613 | settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace') | |
609 | settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int') |
|
614 | settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int') | |
610 |
settings_maker.make_setting('rc_cache.cache_license.arguments.filename', |
|
615 | settings_maker.make_setting('rc_cache.cache_license.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_license_db')) | |
611 |
|
616 | |||
612 | # cache_repo_longterm memory, 96H |
|
617 | # cache_repo_longterm memory, 96H | |
613 | settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru') |
|
618 | settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru') | |
614 | settings_maker.make_setting('rc_cache.cache_repo_longterm.expiration_time', 345600, parser='int') |
|
619 | settings_maker.make_setting('rc_cache.cache_repo_longterm.expiration_time', 345600, parser='int') | |
615 | settings_maker.make_setting('rc_cache.cache_repo_longterm.max_size', 10000, parser='int') |
|
620 | settings_maker.make_setting('rc_cache.cache_repo_longterm.max_size', 10000, parser='int') | |
616 |
|
621 | |||
617 | # sql_cache_short |
|
622 | # sql_cache_short | |
618 | settings_maker.make_setting('rc_cache.sql_cache_short.backend', 'dogpile.cache.rc.memory_lru') |
|
623 | settings_maker.make_setting('rc_cache.sql_cache_short.backend', 'dogpile.cache.rc.memory_lru') | |
619 | settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int') |
|
624 | settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int') | |
620 | settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int') |
|
625 | settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int') | |
621 |
|
626 | |||
622 | # archive_cache |
|
627 | # archive_cache | |
623 |
settings_maker.make_setting('archive_cache.store_dir', |
|
628 | settings_maker.make_setting('archive_cache.store_dir', jn(default_cache_dir, 'archive_cache'), default_when_empty=True,) | |
624 | settings_maker.make_setting('archive_cache.cache_size_gb', 10, parser='float') |
|
629 | settings_maker.make_setting('archive_cache.cache_size_gb', 10, parser='float') | |
625 | settings_maker.make_setting('archive_cache.cache_shards', 10, parser='int') |
|
630 | settings_maker.make_setting('archive_cache.cache_shards', 10, parser='int') | |
626 |
|
631 | |||
627 | settings_maker.env_expand() |
|
632 | settings_maker.env_expand() | |
628 |
|
633 | |||
629 | # configure instance id |
|
634 | # configure instance id | |
630 | config_utils.set_instance_id(settings) |
|
635 | config_utils.set_instance_id(settings) | |
631 |
|
636 | |||
632 | return settings |
|
637 | return settings |
General Comments 0
You need to be logged in to leave comments.
Login now