##// END OF EJS Templates
tests(fix): fixed git tests for new head branches
tests(fix): fixed git tests for new head branches

File last commit:

r5185:0b667669 default
r5218:e92a0575 default
Show More
middleware.py
637 lines | 24.6 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2010-2023 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
configuration: Allows to use format style "{ENV_NAME}" placeholders in the configuration.
r2818 import os
exceptions: added new exception tracking capability....
r2907 import sys
core: code refactor and cleanups for easier pylons porting.
r2321 import collections
caches: rewrite of auth/permission caches to dogpile.
r2845 import tempfile
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238 import time
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 import logging.config
project: added all source files and assets
r1
from paste.gzipper import make_gzip_middleware
security: update lastactivity when on audit logs....
r2930 import pyramid.events
pylons: remove pylons as dependency...
r2351 from pyramid.wsgi import wsgiapp
project: added all source files and assets
r1 from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.config import Configurator
from pyramid.settings import asbool, aslist
Martin Bornhold
wsgi-stack: Use the pylons error handling middleware.
r945 from pyramid.httpexceptions import (
pylons: remove pylons as dependency...
r2351 HTTPException, HTTPError, HTTPInternalServerError, HTTPFound, HTTPNotFound)
Martin Bornhold
config: Move appenlight wrapping from pylons to pyramid.
r595 from pyramid.renderers import render_to_response
repo-summary: re-implemented summary view as pyramid....
r1785
dan
db: move Session.remove to outer wsgi layer and also add it...
r669 from rhodecode.model import meta
db: Move db setup code to seperate function.
r121 from rhodecode.config import patches
users: ported controllers from pylons into pyramid views.
r2114 from rhodecode.config import utils as config_utils
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 from rhodecode.config.settings_maker import SettingsMaker
from rhodecode.config.environment import load_pyramid_environment
repo-summary: re-implemented summary view as pyramid....
r1785
security: update lastactivity when on audit logs....
r2930 import rhodecode.events
pylons: remove pylons as dependency...
r2351 from rhodecode.lib.middleware.vcs import VCSMiddleware
debug: add new custom logging to track unique requests across systems.
r2794 from rhodecode.lib.request import Request
repo-summary: re-implemented summary view as pyramid....
r1785 from rhodecode.lib.vcs import VCSCommunicationError
from rhodecode.lib.exceptions import VCSServerUnavailable
project: added all source files and assets
r1 from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled
from rhodecode.lib.middleware.https_fixup import HttpsFixup
from rhodecode.lib.plugins.utils import register_rhodecode_plugin
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 from rhodecode.lib.utils2 import AttributeDict
exc_tracking: always nice format tb for core exceptions
r5127 from rhodecode.lib.exc_tracking import store_exception, format_exc
core: added metadata for control upgrades.
r1392 from rhodecode.subscribers import (
core: remove writing of largeobject dirs on AppStartup....
r1680 scan_repositories_if_enabled, write_js_routes_if_enabled,
app: improve logging, and remove DB calls on app startup.
r4548 write_metadata_if_needed, write_usage_data)
metrics: added new statsd client and enabled new metrics on app
r4792 from rhodecode.lib.statsd_client import StatsdClient
project: added all source files and assets
r1
log = logging.getLogger(__name__)
pylons: remove pylons as dependency...
r2351 def is_http_error(response):
# error which should have traceback
return response.status_code > 499
project: added all source files and assets
r1
app: disconect auth plugin loading from authentication registry....
r3241 def should_load_all():
"""
Returns if all application components should be loaded. In some cases it's
desired to skip apps loading for faster shell script execution
"""
ssh: skip loading parts for SSH to make execution of ssh commands faster.
r3910 ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER')
if ssh_cmd:
return False
app: disconect auth plugin loading from authentication registry....
r3241 return True
project: added all source files and assets
r1 def make_pyramid_app(global_config, **settings):
"""
pylons: remove pylons as dependency...
r2351 Constructs the WSGI application based on Pyramid.
project: added all source files and assets
r1
Specials:
* The application can also be integrated like a plugin via the call to
`includeme`. This is accompanied with the other utility functions which
are called. Changing this should be done with great care to not break
cases when these fragments are assembled from another place.
"""
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238 start_time = time.time()
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610 log.info('Pyramid app config starting')
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults(global_config, settings)
config: move env expansion to common code for EE usage
r4822
metrics: added new statsd client and enabled new metrics on app
r4792 # init and bootstrap StatsdClient
StatsdClient.setup(settings)
project: added all source files and assets
r1 config = Configurator(settings=settings)
metrics: added new statsd client and enabled new metrics on app
r4792 # Init our statsd at very start
config.registry.statsd = StatsdClient.statsd
users: ported controllers from pylons into pyramid views.
r2114
pylons: remove pylons as dependency...
r2351 # Apply compatibility patches
patches.inspect_getargspec()
load_pyramid_environment(global_config, settings)
db: Move initialization of test environment up to pyramid layer.
r116
settings: removed not used supervisor views/models....
r2325 # Static file view comes first
dan
assets: skip RoutesMiddleware matching on certain urls to avoid...
r463 includeme_first(config)
settings: removed not used supervisor views/models....
r2325
project: added all source files and assets
r1 includeme(config)
files: ported repository files controllers to pyramid views.
r1927
project: added all source files and assets
r1 pyramid_app = config.make_wsgi_app()
pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config)
dan
pyramid: add config to make_pyramid_app for inspection afterwards
r619 pyramid_app.config = config
dan
db: move Session.remove to outer wsgi layer and also add it...
r669
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 celery_settings = get_celery_config(settings)
config.configure_celery(celery_settings)
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
dan
db: move Session.remove to outer wsgi layer and also add it...
r669 # creating the app uses a connection - return it after we are done
meta.Session.remove()
metrics: added new statsd client and enabled new metrics on app
r4792
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238 total_time = time.time() - start_time
configs: refactor and updated for python3 migrations
r5060 log.info('Pyramid app created and configured in %.2fs', total_time)
project: added all source files and assets
r1 return pyramid_app
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 def get_celery_config(settings):
"""
Converts basic ini configuration into celery 4.X options
"""
def key_converter(key_name):
pref = 'celery.'
if key_name.startswith(pref):
return key_name[len(pref):].replace('.', '_').lower()
def type_converter(parsed_key, value):
# cast to int
if value.isdigit():
return int(value)
# cast to bool
if value.lower() in ['true', 'false', 'True', 'False']:
return value.lower() == 'true'
return value
celery_config = {}
for k, v in settings.items():
pref = 'celery.'
if k.startswith(pref):
celery_config[key_converter(k)] = type_converter(key_converter(k), v)
# TODO:rethink if we want to support celerybeat based file config, probably NOT
# beat_config = {}
# for section in parser.sections():
# if section.startswith('celerybeat:'):
# name = section.split(':', 1)[1]
# beat_config[name] = get_beat_config(parser, section)
# final compose of settings
celery_settings = {}
if celery_config:
celery_settings.update(celery_config)
# if beat_config:
# celery_settings.update({'beat_schedule': beat_config})
return celery_settings
pylons: remove pylons as dependency...
r2351 def not_found_view(request):
Martin Bornhold
vcs: Move VCSMiddleware up to pyramid layer as wrapper around pylons app....
r581 """
Martin Bornhold
config: Move appenlight wrapping from pylons to pyramid.
r595 This creates the view which should be registered as not-found-view to
pylons: remove pylons as dependency...
r2351 pyramid.
Martin Bornhold
vcs: Move VCSMiddleware up to pyramid layer as wrapper around pylons app....
r581 """
pylons: remove pylons as dependency...
r2351 if not getattr(request, 'vcs_call', None):
# handle like regular case with our error_handler
return error_handler(HTTPNotFound(), request)
Martin Bornhold
config: Move appenlight wrapping from pylons to pyramid.
r595
pylons: remove pylons as dependency...
r2351 # handle not found view as a vcs call
settings = request.registry.settings
ae_client = getattr(request, 'ae_client', None)
vcs_app = VCSMiddleware(
HTTPNotFound(), request.registry, settings,
appenlight_client=ae_client)
Martin Bornhold
vcs: Use response header to decide if error handling is needed.
r609
pylons: remove pylons as dependency...
r2351 return wsgiapp(vcs_app)(None, request)
project: added all source files and assets
r1
dan
errorpages: add appenlight to pyramid layer
r194 def error_handler(exception, request):
error-middleware: read title from cached rhodecode object....
r1496 import rhodecode
error-document: make sure the error document has registered helpers,...
r1748 from rhodecode.lib import helpers
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187
error-middleware: read title from cached rhodecode object....
r1496 rhodecode_title = rhodecode.CONFIG.get('rhodecode_title') or 'RhodeCode'
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187
dan
errorpages: add appenlight to pyramid layer
r194 base_response = HTTPInternalServerError()
# prefer original exception for the response since it may have headers set
core: properly handle new redirections set in decorators....
r1499 if isinstance(exception, HTTPException):
dan
errorpages: add appenlight to pyramid layer
r194 base_response = exception
repo-summary: re-implemented summary view as pyramid....
r1785 elif isinstance(exception, VCSCommunicationError):
base_response = VCSServerUnavailable()
dan
errorpages: add appenlight to pyramid layer
r194
error-handling: show tracebacks only for error code 500 and above.
r1314 if is_http_error(base_response):
exc_tracking: always nice format tb for core exceptions
r5127 traceback_info = format_exc(request.exc_info)
log.error(
'error occurred handling this request for path: %s, \n%s',
request.path, traceback_info)
error-handling: show tracebacks only for error code 500 and above.
r1314
auth: because we use 404 for access denied too. Show proper message about it in error page
r2115 error_explanation = base_response.explanation or str(base_response)
if base_response.status_code == 404:
error-pages: update message to more proper.
r3321 error_explanation += " Optionally you don't have permission to access this page."
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187 c = AttributeDict()
dan
errorpages: add appenlight to pyramid layer
r194 c.error_message = base_response.status
auth: because we use 404 for access denied too. Show proper message about it in error page
r2115 c.error_explanation = error_explanation
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187 c.visual = AttributeDict()
c.visual.rhodecode_support_url = (
request.registry.settings.get('rhodecode_support_url') or
request.route_url('rhodecode_support')
)
c.redirect_time = 0
error-middleware: read title from cached rhodecode object....
r1496 c.rhodecode_name = rhodecode_title
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187 if not c.rhodecode_name:
c.rhodecode_name = 'Rhodecode'
dan
ux: show list of causes for vcs unavailable error page
r683 c.causes = []
error-page: use custom causes for 500+ errors
r2116 if is_http_error(base_response):
c.causes.append('Server is overloaded.')
c.causes.append('Server database connection is lost.')
c.causes.append('Server expected unhandled error.')
dan
ux: show list of causes for vcs unavailable error page
r683 if hasattr(base_response, 'causes'):
c.causes = base_response.causes
error-page: use custom causes for 500+ errors
r2116
pyramid: changes for pyramid migration.
r1908 c.messages = helpers.flash.pop_messages(request=request)
exceptions: added new exception tracking capability....
r2907 exc_info = sys.exc_info()
c.exception_id = id(exc_info)
c.show_exception_id = isinstance(base_response, VCSServerUnavailable) \
or base_response.status_code > 499
c.exception_id_url = request.route_url(
'admin_settings_exception_tracker_show', exception_id=c.exception_id)
configs: refactor and updated for python3 migrations
r5060 debug_mode = rhodecode.ConfigGet().get_bool('debug')
exceptions: added new exception tracking capability....
r2907 if c.show_exception_id:
store_exception(c.exception_id, exc_info)
configs: refactor and updated for python3 migrations
r5060 c.exception_debug = debug_mode
debugging: expose logs/exception when debug log is enabled.
r4768 c.exception_config_ini = rhodecode.CONFIG.get('__file__')
exceptions: added new exception tracking capability....
r2907
configs: refactor and updated for python3 migrations
r5060 if debug_mode:
try:
from rich.traceback import install
install(show_locals=True)
log.debug('Installing rich tracebacks...')
except ImportError:
pass
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187 response = render_to_response(
error-document: make sure the error document has registered helpers,...
r1748 '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request,
dan
errorpages: use original http status for rendered error page
r190 response=base_response)
tests: refactor code to use a single test url generator
r5173 response.headers["X-RC-Exception-Id"] = str(c.exception_id)
metrics: expose exc_type in consistent format
r4808 statsd = request.registry.statsd
if statsd and base_response.status_code > 499:
modernize: updates for python3
r5095 exc_type = f"{exception.__class__.__module__}.{exception.__class__.__name__}"
metrics: expose exc_type in consistent format
r4808 statsd.incr('rhodecode_exception_total',
tags=["exc_source:web",
modernize: updates for python3
r5095 f"http_code:{base_response.status_code}",
f"type:{exc_type}"])
metrics: expose exc_type in consistent format
r4808
dan
pyramid: make responses/exceptions from pyramid/pylons work
r187 return response
middleware: code restructure
r2326 def includeme_first(config):
# redirect automatic browser favicon.ico requests to correct place
def favicon_redirect(context, request):
return HTTPFound(
request.static_path('rhodecode:public/images/favicon.ico'))
config.add_view(favicon_redirect, route_name='favicon')
config.add_route('favicon', '/favicon.ico')
def robots_redirect(context, request):
return HTTPFound(
request.static_path('rhodecode:public/robots.txt'))
config.add_view(robots_redirect, route_name='robots')
config.add_route('robots', '/robots.txt')
config.add_static_view(
'_static/deform', 'deform:static')
config.add_static_view(
'_static/rhodecode', path='rhodecode:public', cache_max_age=3600 * 24)
configs: refactor and updated for python3 migrations
r5060 ce_auth_resources = [
'rhodecode.authentication.plugins.auth_crowd',
'rhodecode.authentication.plugins.auth_headers',
'rhodecode.authentication.plugins.auth_jasig_cas',
'rhodecode.authentication.plugins.auth_ldap',
'rhodecode.authentication.plugins.auth_pam',
'rhodecode.authentication.plugins.auth_rhodecode',
'rhodecode.authentication.plugins.auth_token',
]
core: allow loading all auth plugins in once place for CE/EE code.
r4602 def includeme(config, auth_resources=None):
imports: fixed recursive imports on EE
r4621 from rhodecode.lib.celerylib.loader import configure_celery
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238 log.debug('Initializing main includeme from %s', os.path.basename(__file__))
project: added all source files and assets
r1 settings = config.registry.settings
debug: add new custom logging to track unique requests across systems.
r2794 config.set_request_factory(Request)
project: added all source files and assets
r1
middleware: add the register plugin directive further up the config stack
r470 # plugin information
core: code refactor and cleanups for easier pylons porting.
r2321 config.registry.rhodecode_plugins = collections.OrderedDict()
middleware: add the register plugin directive further up the config stack
r470
config.add_directive(
'register_rhodecode_plugin', register_rhodecode_plugin)
celery: celery 4.X support. Fixes #4169...
r2359 config.add_directive('configure_celery', configure_celery)
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 if settings.get('appenlight', False):
dan
errorpages: add appenlight to pyramid layer
r194 config.include('appenlight_client.ext.pyramid_tween')
app: disconect auth plugin loading from authentication registry....
r3241 load_all = should_load_all()
project: added all source files and assets
r1 # Includes which are required. The application would fail without them.
config.include('pyramid_mako')
session: moved pyramid_beaker internally to apply some patches required for better session handling
r3748 config.include('rhodecode.lib.rc_beaker')
caches: rewrite of auth/permission caches to dogpile.
r2845 config.include('rhodecode.lib.rc_cache')
configs: refactor and updated for python3 migrations
r5060 config.include('rhodecode.lib.rc_cache.archive_cache')
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238 config.include('rhodecode.apps._base.navigation')
config.include('rhodecode.apps._base.subscribers')
config.include('rhodecode.tweens')
ssh: skip loading parts for SSH to make execution of ssh commands faster.
r3910 config.include('rhodecode.authentication')
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238
ssh: skip loading parts for SSH to make execution of ssh commands faster.
r3910 if load_all:
core: allow loading all auth plugins in once place for CE/EE code.
r4602
app: disconect auth plugin loading from authentication registry....
r3241 # load CE authentication plugins
core: allow loading all auth plugins in once place for CE/EE code.
r4602
if auth_resources:
ce_auth_resources.extend(auth_resources)
for resource in ce_auth_resources:
config.include(resource)
app: disconect auth plugin loading from authentication registry....
r3241
# Auto discover authentication plugins and include their configuration.
app-setup: allow skip of legacy plugin discovery.
r4108 if asbool(settings.get('auth_plugin.import_legacy_plugins', 'true')):
from rhodecode.authentication import discover_legacy_plugins
discover_legacy_plugins(config)
app: disconect auth plugin loading from authentication registry....
r3241
user-profile: migrated to pyramid views.
r1502 # apps
app: disconect auth plugin loading from authentication registry....
r3241 if load_all:
middleware: use explicit call to .includeme while importing apps and modules. This is a bit faster for code discovery and app startup
r5024 log.debug('Starting config.include() calls')
config.include('rhodecode.api.includeme')
config.include('rhodecode.apps._base.includeme')
config.include('rhodecode.apps._base.navigation.includeme')
config.include('rhodecode.apps._base.subscribers.includeme')
config.include('rhodecode.apps.hovercards.includeme')
config.include('rhodecode.apps.ops.includeme')
config.include('rhodecode.apps.channelstream.includeme')
config.include('rhodecode.apps.file_store.includeme')
config.include('rhodecode.apps.admin.includeme')
config.include('rhodecode.apps.login.includeme')
config.include('rhodecode.apps.home.includeme')
config.include('rhodecode.apps.journal.includeme')
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
middleware: use explicit call to .includeme while importing apps and modules. This is a bit faster for code discovery and app startup
r5024 config.include('rhodecode.apps.repository.includeme')
config.include('rhodecode.apps.repo_group.includeme')
config.include('rhodecode.apps.user_group.includeme')
config.include('rhodecode.apps.search.includeme')
config.include('rhodecode.apps.user_profile.includeme')
config.include('rhodecode.apps.user_group_profile.includeme')
config.include('rhodecode.apps.my_account.includeme')
config.include('rhodecode.apps.gist.includeme')
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
middleware: use explicit call to .includeme while importing apps and modules. This is a bit faster for code discovery and app startup
r5024 config.include('rhodecode.apps.svn_support.includeme')
config.include('rhodecode.apps.ssh_support.includeme')
app: disconect auth plugin loading from authentication registry....
r3241 config.include('rhodecode.apps.debug_style')
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
if load_all:
middleware: use explicit call to .includeme while importing apps and modules. This is a bit faster for code discovery and app startup
r5024 config.include('rhodecode.integrations.includeme')
config.include('rhodecode.integrations.routes.includeme')
admin: moved admin pyramid into apps.
r1503
application: re-organize imports for pyramid to prepare code for speedup optimization.
r3238 config.add_route('rhodecode_support', 'https://rhodecode.com/help/', static=True)
middleware: use timing for complete stack call
r4997 settings['default_locale_name'] = settings.get('lang', 'en')
i18n: enable translation defaults for pyramid views.
r1303 config.add_translation_dirs('rhodecode:i18n/')
Martin Bornhold
config: Move initial repo scan up to the pyramid layer....
r580 # Add subscribers.
ssh: skip loading parts for SSH to make execution of ssh commands faster.
r3910 if load_all:
middleware: use explicit call to .includeme while importing apps and modules. This is a bit faster for code discovery and app startup
r5024 log.debug('Adding subscribers....')
ssh: skip loading parts for SSH to make execution of ssh commands faster.
r3910 config.add_subscriber(scan_repositories_if_enabled,
pyramid.events.ApplicationCreated)
config.add_subscriber(write_metadata_if_needed,
pyramid.events.ApplicationCreated)
hosting: added usage writers for hosting needs.
r4473 config.add_subscriber(write_usage_data,
pyramid.events.ApplicationCreated)
ssh: skip loading parts for SSH to make execution of ssh commands faster.
r3910 config.add_subscriber(write_js_routes_if_enabled,
pyramid.events.ApplicationCreated)
events: re-organizate events handling....
r1789
project: added all source files and assets
r1
# Set the default renderer for HTML templates to mako.
config.add_mako_renderer('.html')
core: added ext_json as custom renderer using our ext_json lib for pyramid.
r1664 config.add_renderer(
name='json_ext',
factory='rhodecode.lib.ext_json_renderer.pyramid_ext_json')
reviewers: added observers as another way to define reviewers....
r4500 config.add_renderer(
name='string_html',
factory='rhodecode.lib.string_renderer.html')
project: added all source files and assets
r1 # include RhodeCode plugins
includes = aslist(settings.get('rhodecode.includes', []))
middleware: use explicit call to .includeme while importing apps and modules. This is a bit faster for code discovery and app startup
r5024 log.debug('processing rhodecode.includes data...')
project: added all source files and assets
r1 for inc in includes:
config.include(inc)
pylons: remove pylons as dependency...
r2351 # custom not found view, if our pyramid app doesn't know how to handle
# the request pass it to potential VCS handling ap
config.add_notfound_view(not_found_view)
dan
errorpages: fix case when a pyramid httperror was not being rendered...
r449 if not settings.get('debugtoolbar.enabled', False):
pyramid: allows easier turning off the pylons components.
r1912 # disabled debugtoolbar handle all exceptions via the error_handlers
dan
errorpages: fix case when a pyramid httperror was not being rendered...
r449 config.add_view(error_handler, context=Exception)
pylons: remove pylons as dependency...
r2351 # all errors including 403/404/50X
dan
errorpages: fix case when a pyramid httperror was not being rendered...
r449 config.add_view(error_handler, context=HTTPError)
project: added all source files and assets
r1
def wrap_app_in_wsgi_middlewares(pyramid_app, config):
"""
Apply outer WSGI middlewares around the application.
"""
events: use a distinction between RhodeCodeEvent which is a base class and it used by all events, and...
r2921 registry = config.registry
settings = registry.settings
project: added all source files and assets
r1
config: Move HttpsFixup middleware up...
r181 # enable https redirects based on HTTP_X_URL_SCHEME set by proxy
pyramid_app = HttpsFixup(pyramid_app, settings)
pylons: remove pylons as dependency...
r2351 pyramid_app, _ae_client = wrap_in_appenlight_if_enabled(
pyramid_app, settings)
events: use a distinction between RhodeCodeEvent which is a base class and it used by all events, and...
r2921 registry.ae_client = _ae_client
dan
errorpages: add appenlight to pyramid layer
r194
Martin Bornhold
config: Sanitize 'appenlight' and 'gzip_responses' settings.
r598 if settings['gzip_responses']:
project: added all source files and assets
r1 pyramid_app = make_gzip_middleware(
pyramid_app, settings, compress_level=1)
dan
db: move Session.remove to outer wsgi layer and also add it...
r669 # this should be the outer most middleware in the wsgi stack since
# middleware like Routes make database calls
def pyramid_app_with_cleanup(environ, start_response):
middleware: use timing for complete stack call
r4997 start = time.time()
dan
db: move Session.remove to outer wsgi layer and also add it...
r669 try:
return pyramid_app(environ, start_response)
finally:
# Dispose current database session and rollback uncommitted
# transactions.
meta.Session.remove()
# In a single threaded mode server, on non sqlite db we should have
# '0 Current Checked out connections' at the end of a request,
# if not, then something, somewhere is leaving a connection open
configs: refactor and updated for python3 migrations
r5060 pool = meta.get_engine().pool
dan
db: move Session.remove to outer wsgi layer and also add it...
r669 log.debug('sa pool status: %s', pool.status())
middleware: use timing for complete stack call
r4997 total = time.time() - start
log.debug('Request processing finalized: %.4fs', total)
dan
db: move Session.remove to outer wsgi layer and also add it...
r669
return pyramid_app_with_cleanup
project: added all source files and assets
r1
configuration: expose the config file location to the pyramid settings.
r3431 def sanitize_settings_and_apply_defaults(global_config, settings):
project: added all source files and assets
r1 """
Applies settings defaults and does all type conversion.
We would move all settings parsing and preparation into this place, so that
we have only one place left which deals with this part. The remaining parts
of the application would start to rely fully on well prepared settings.
This piece would later be split up per topic to avoid a big fat monster
function.
"""
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 jn = os.path.join
project: added all source files and assets
r1
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 global_settings_maker = SettingsMaker(global_config)
global_settings_maker.make_setting('debug', default=False, parser='bool')
debug_enabled = asbool(global_config.get('debug'))
settings_maker = SettingsMaker(settings)
settings_maker.make_setting(
'logging.autoconfigure',
logging: set logging autoconfigure default to False so it's not a breaking change
r4861 default=False,
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 parser='bool')
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 logging_conf = jn(os.path.dirname(global_config.get('__file__')), 'logging.ini')
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.enable_logging(logging_conf, level='INFO' if debug_enabled else 'DEBUG')
# Default includes, possible to change as a user
pyramid_includes = settings_maker.make_setting('pyramid.includes', [], parser='list:newline')
log.debug(
"Using the following pyramid.includes: %s",
pyramid_includes)
settings_maker.make_setting('rhodecode.edition', 'Community Edition')
settings_maker.make_setting('rhodecode.edition_id', 'CE')
core: cleanup settings cleanups on pyramid app.
r2316
if 'mako.default_filters' not in settings:
# set custom default filters if we don't have it defined
settings['mako.imports'] = 'from rhodecode.lib.base import h_filter'
settings['mako.default_filters'] = 'h_filter'
if 'mako.directories' not in settings:
mako_directories = settings.setdefault('mako.directories', [
# Base templates of the original application
'rhodecode:templates',
])
log.debug(
"Using the following Mako template directories: %s",
mako_directories)
project: added all source files and assets
r1
redis: fixed new redis url schema requirement for connection string
r3867 # NOTE(marcink): fix redis requirement for schema of connection since 3.X
if 'beaker.session.type' in settings and settings['beaker.session.type'] == 'ext:redis':
raw_url = settings['beaker.session.url']
if not raw_url.startswith(('redis://', 'rediss://', 'unix://')):
settings['beaker.session.url'] = 'redis://' + raw_url
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('__file__', global_config.get('__file__'))
project: added all source files and assets
r1
# TODO: johbo: Re-think this, usually the call to config.include
# should allow to pass in a prefix.
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('rhodecode.api.url', '/_admin/api')
project: added all source files and assets
r1
Martin Bornhold
config: Sanitize 'appenlight' and 'gzip_responses' settings.
r598 # Sanitize generic settings.
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('default_encoding', 'UTF-8', parser='list')
settings_maker.make_setting('is_test', False, parser='bool')
settings_maker.make_setting('gzip_responses', False, parser='bool')
project: added all source files and assets
r1
env-config: use proper ALL keys reconfiguration based on env vars
r4825 # statsd
settings_maker.make_setting('statsd.enabled', False, parser='bool')
env: small fixes to sync with vcsserver settings maker
r4826 settings_maker.make_setting('statsd.statsd_host', 'statsd-exporter', parser='string')
settings_maker.make_setting('statsd.statsd_port', 9125, parser='int')
env-config: use proper ALL keys reconfiguration based on env vars
r4825 settings_maker.make_setting('statsd.statsd_prefix', '')
settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool')
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('vcs.svn.compatible_version', '')
settings_maker.make_setting('vcs.hooks.protocol', 'http')
configs: refactor and updated for python3 migrations
r5060 settings_maker.make_setting('vcs.hooks.host', '*')
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('vcs.scm_app_implementation', 'http')
settings_maker.make_setting('vcs.server', '')
settings_maker.make_setting('vcs.server.protocol', 'http')
settings-maker: moved key to common section
r4956 settings_maker.make_setting('vcs.server.enable', 'true', parser='bool')
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('startup.import_repos', 'false', parser='bool')
settings_maker.make_setting('vcs.hooks.direct_calls', 'false', parser='bool')
settings_maker.make_setting('vcs.start_server', 'false', parser='bool')
settings_maker.make_setting('vcs.backends', 'hg, git, svn', parser='list')
settings_maker.make_setting('vcs.connection_timeout', 3600, parser='int')
settings_maker.make_setting('vcs.methods.cache', True, parser='bool')
# Support legacy values of vcs.scm_app_implementation. Legacy
# configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or
# disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'.
scm_app_impl = settings['vcs.scm_app_implementation']
if scm_app_impl in ['rhodecode.lib.middleware.utils.scm_app_http', 'vcsserver.scm_app']:
settings['vcs.scm_app_implementation'] = 'http'
settings_maker.make_setting('appenlight', False, parser='bool')
exception_tracker: use a default value of exception store that is working across all instances e.g vcsserver and enterprise.
r3028 temp_store = tempfile.gettempdir()
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 tmp_cache_dir = jn(temp_store, 'rc_cache')
caches: use single default cache dir for all backends....
r3008
# save default, cache dir, and use it for all backends later.
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 default_cache_dir = settings_maker.make_setting(
caches: use single default cache dir for all backends....
r3008 'cache_dir',
small naming fixes
r4884 default=tmp_cache_dir, default_when_empty=True,
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 parser='dir:ensured')
caches: use single default cache dir for all backends....
r3008
exc_tracker: allow setting custom store via .ini file...
r3019 # exception store cache
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting(
exception_store: rename .ini option for future
r3024 'exception_tracker.store_path',
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 default=jn(default_cache_dir, 'exc_store'), default_when_empty=True,
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 parser='dir:ensured'
)
settings_maker.make_setting(
'celerybeat-schedule.path',
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 default=jn(default_cache_dir, 'celerybeat_schedule', 'celerybeat-schedule.db'), default_when_empty=True,
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 parser='file:ensured'
)
settings_maker.make_setting('exception_tracker.send_email', False, parser='bool')
settings_maker.make_setting('exception_tracker.email_prefix', '[RHODECODE ERROR]', default_when_empty=True)
exc_tracker: allow setting custom store via .ini file...
r3019
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 # sessions, ensure file since no-value is memory
settings_maker.make_setting('beaker.session.type', 'file')
settings_maker.make_setting('beaker.session.data_dir', jn(default_cache_dir, 'session_data'))
caches: remove settings cache to use invalidation context as it's slowing down much usage
r4833 # cache_general
settings_maker.make_setting('rc_cache.cache_general.backend', 'dogpile.cache.rc.file_namespace')
settings_maker.make_setting('rc_cache.cache_general.expiration_time', 60 * 60 * 12, parser='int')
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 settings_maker.make_setting('rc_cache.cache_general.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_general.db'))
caches: remove settings cache to use invalidation context as it's slowing down much usage
r4833
caches: use dogpile for sql_cache_short region.
r2883 # cache_perms
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace')
caches: remove settings cache to use invalidation context as it's slowing down much usage
r4833 settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int')
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_perms_db'))
caches: rewrite of auth/permission caches to dogpile.
r2845
caches: use dogpile for sql_cache_short region.
r2883 # cache_repo
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace')
caches: remove settings cache to use invalidation context as it's slowing down much usage
r4833 settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int')
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_repo_db'))
caches: rewrite of auth/permission caches to dogpile.
r2845
caches: configure license cache to some default settings.
r2959 # cache_license
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace')
caches: remove settings cache to use invalidation context as it's slowing down much usage
r4833 settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int')
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 settings_maker.make_setting('rc_cache.cache_license.arguments.filename', jn(default_cache_dir, 'rhodecode_cache_license_db'))
caches: configure license cache to some default settings.
r2959
caches: new cache context managers....
r2932 # cache_repo_longterm memory, 96H
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru')
settings_maker.make_setting('rc_cache.cache_repo_longterm.expiration_time', 345600, parser='int')
settings_maker.make_setting('rc_cache.cache_repo_longterm.max_size', 10000, parser='int')
caches: new cache context managers....
r2932
caches: use dogpile for sql_cache_short region.
r2883 # sql_cache_short
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 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')
env-config: use proper ALL keys reconfiguration based on env vars
r4825
configs: refactor and updated for python3 migrations
r5060 # archive_cache
config: set default file-based sessions if not specified. This will prevent memory session to kick-in
r5185 settings_maker.make_setting('archive_cache.store_dir', jn(default_cache_dir, 'archive_cache'), default_when_empty=True,)
configs: refactor and updated for python3 migrations
r5060 settings_maker.make_setting('archive_cache.cache_size_gb', 10, parser='float')
settings_maker.make_setting('archive_cache.cache_shards', 10, parser='int')
env-config: use proper ALL keys reconfiguration based on env vars
r4825 settings_maker.env_expand()
# configure instance id
config_utils.set_instance_id(settings)
return settings