middlewares: all porting for python3
This commit is contained in:
parent
45554873b3
commit
cf44a5cb75
5 changed files with 52 additions and 37 deletions
|
|
@ -24,9 +24,14 @@ import logging
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from appenlight_client.exceptions import get_current_traceback
|
||||
except ImportError:
|
||||
def get_current_traceback(*args, **kwargs):
|
||||
return
|
||||
|
||||
|
||||
def track_exception(environ):
|
||||
from appenlight_client.exceptions import get_current_traceback
|
||||
|
||||
if 'appenlight.client' not in environ:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ class RequestWrapperTween(object):
|
|||
start = time.time()
|
||||
log.debug('Starting request time measurement')
|
||||
response = None
|
||||
request.req_wrapper_start = start
|
||||
|
||||
try:
|
||||
response = self.handler(request)
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ SimpleHG middleware for handling mercurial protocol request
|
|||
|
||||
import logging
|
||||
import urllib.parse
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import urllib.error
|
||||
|
||||
from rhodecode.lib import utils
|
||||
from rhodecode.lib.ext_json import json
|
||||
|
|
|
|||
|
|
@ -85,26 +85,30 @@ class VcsHttpProxy(object):
|
|||
repo_name, url)
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
config = msgpack.packb(self._config)
|
||||
config = self._config
|
||||
request = webob.request.Request(environ)
|
||||
request_headers = request.headers
|
||||
|
||||
request_headers.update({
|
||||
call_context = {
|
||||
# TODO: johbo: Remove this, rely on URL path only
|
||||
'X-RC-Repo-Name': self._repo_name,
|
||||
'X-RC-Repo-Path': self._repo_path,
|
||||
'X-RC-Path-Info': environ['PATH_INFO'],
|
||||
'repo_name': self._repo_name,
|
||||
'repo_path': self._repo_path,
|
||||
'path_info': get_path_info(environ),
|
||||
|
||||
'X-RC-Repo-Store': self.rc_extras.get('repo_store'),
|
||||
'X-RC-Server-Config-File': self.rc_extras.get('config'),
|
||||
'repo_store': self.rc_extras.get('repo_store'),
|
||||
'server_config_file': self.rc_extras.get('config'),
|
||||
|
||||
'X-RC-Auth-User': self.rc_extras.get('username'),
|
||||
'X-RC-Auth-User-Id': str(self.rc_extras.get('user_id')),
|
||||
'X-RC-Auth-User-Ip': self.rc_extras.get('ip'),
|
||||
'auth_user': self.rc_extras.get('username'),
|
||||
'auth_user_id': str(self.rc_extras.get('user_id')),
|
||||
'auth_user_ip': self.rc_extras.get('ip'),
|
||||
|
||||
'repo_config': config,
|
||||
'locked_status_code': rhodecode.CONFIG.get('lock_ret_code'),
|
||||
}
|
||||
|
||||
request_headers.update({
|
||||
# TODO: johbo: Avoid encoding and put this into payload?
|
||||
'X-RC-Repo-Config': base64.b64encode(config),
|
||||
'X-RC-Locked-Status-Code': rhodecode.CONFIG.get('lock_ret_code'),
|
||||
'X_RC_VCS_STREAM_CALL_CONTEXT': base64.b64encode(msgpack.packb(call_context))
|
||||
})
|
||||
|
||||
method = environ['REQUEST_METHOD']
|
||||
|
|
|
|||
|
|
@ -143,18 +143,6 @@ def is_vcs_call(environ):
|
|||
return False
|
||||
|
||||
|
||||
def get_path_elem(route_path):
|
||||
if not route_path:
|
||||
return None
|
||||
|
||||
cleaned_route_path = route_path.lstrip('/')
|
||||
if cleaned_route_path:
|
||||
cleaned_route_path_elems = cleaned_route_path.split('/')
|
||||
if cleaned_route_path_elems:
|
||||
return cleaned_route_path_elems[0]
|
||||
return None
|
||||
|
||||
|
||||
def detect_vcs_request(environ, backends):
|
||||
checks = {
|
||||
'hg': (is_hg, SimpleHg),
|
||||
|
|
@ -164,11 +152,26 @@ def detect_vcs_request(environ, backends):
|
|||
handler = None
|
||||
# List of path views first chunk we don't do any checks
|
||||
white_list = [
|
||||
# favicon often requested by browsers
|
||||
'favicon.ico',
|
||||
|
||||
# e.g /_file_store/download
|
||||
'_file_store',
|
||||
'_file_store++',
|
||||
|
||||
# _admin/api is safe too
|
||||
'_admin/api',
|
||||
|
||||
# _admin/gist is safe too
|
||||
'_admin/gists++',
|
||||
|
||||
# _admin/my_account is safe too
|
||||
'_admin/my_account++',
|
||||
|
||||
# static files no detection
|
||||
'_static',
|
||||
'_static++',
|
||||
|
||||
# debug-toolbar
|
||||
'_debug_toolbar++',
|
||||
|
||||
# skip ops ping, status
|
||||
'_admin/ops/ping',
|
||||
|
|
@ -180,14 +183,13 @@ def detect_vcs_request(environ, backends):
|
|||
path_info = get_path_info(environ)
|
||||
path_url = path_info.lstrip('/')
|
||||
|
||||
if path_elem in white_list:
|
||||
log.debug('path `%s` in whitelist, skipping...', path_info)
|
||||
return handler
|
||||
|
||||
path_url = path_info.lstrip('/')
|
||||
if path_url in white_list:
|
||||
log.debug('full url path `%s` in whitelist, skipping...', path_url)
|
||||
return handler
|
||||
for item in white_list:
|
||||
if item.endswith('++') and path_url.startswith(item[:-2]):
|
||||
log.debug('path `%s` in whitelist (match:%s), skipping...', path_url, item)
|
||||
return handler
|
||||
if item == path_url:
|
||||
log.debug('path `%s` in whitelist (match:%s), skipping...', path_url, item)
|
||||
return handler
|
||||
|
||||
if VCS_TYPE_KEY in environ:
|
||||
raw_type = environ[VCS_TYPE_KEY]
|
||||
|
|
@ -200,7 +202,7 @@ def detect_vcs_request(environ, backends):
|
|||
log.debug('got handler:%s from environ', handler)
|
||||
|
||||
if not handler:
|
||||
log.debug('request start: checking if request for `%s` is of VCS type in order: %s', path_elem, backends)
|
||||
log.debug('request start: checking if request for `%s` is of VCS type in order: %s', path_url, backends)
|
||||
for vcs_type in backends:
|
||||
vcs_check, _handler = checks[vcs_type]
|
||||
if vcs_check(environ):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue