Show More
@@ -24,9 +24,14 b' import logging' | |||||
24 |
|
24 | |||
25 | log = logging.getLogger(__name__) |
|
25 | log = logging.getLogger(__name__) | |
26 |
|
26 | |||
|
27 | try: | |||
|
28 | from appenlight_client.exceptions import get_current_traceback | |||
|
29 | except ImportError: | |||
|
30 | def get_current_traceback(*args, **kwargs): | |||
|
31 | return | |||
|
32 | ||||
27 |
|
33 | |||
28 | def track_exception(environ): |
|
34 | def track_exception(environ): | |
29 | from appenlight_client.exceptions import get_current_traceback |
|
|||
30 |
|
35 | |||
31 | if 'appenlight.client' not in environ: |
|
36 | if 'appenlight.client' not in environ: | |
32 | return |
|
37 | return |
@@ -48,6 +48,8 b' class RequestWrapperTween(object):' | |||||
48 | start = time.time() |
|
48 | start = time.time() | |
49 | log.debug('Starting request time measurement') |
|
49 | log.debug('Starting request time measurement') | |
50 | response = None |
|
50 | response = None | |
|
51 | request.req_wrapper_start = start | |||
|
52 | ||||
51 | try: |
|
53 | try: | |
52 | response = self.handler(request) |
|
54 | response = self.handler(request) | |
53 | finally: |
|
55 | finally: |
@@ -24,7 +24,9 b' SimpleHG middleware for handling mercuri' | |||||
24 |
|
24 | |||
25 | import logging |
|
25 | import logging | |
26 | import urllib.parse |
|
26 | import urllib.parse | |
27 |
import urllib.request |
|
27 | import urllib.request | |
|
28 | import urllib.parse | |||
|
29 | import urllib.error | |||
28 |
|
30 | |||
29 | from rhodecode.lib import utils |
|
31 | from rhodecode.lib import utils | |
30 | from rhodecode.lib.ext_json import json |
|
32 | from rhodecode.lib.ext_json import json |
@@ -85,26 +85,30 b' class VcsHttpProxy(object):' | |||||
85 | repo_name, url) |
|
85 | repo_name, url) | |
86 |
|
86 | |||
87 | def __call__(self, environ, start_response): |
|
87 | def __call__(self, environ, start_response): | |
88 |
config = |
|
88 | config = self._config | |
89 | request = webob.request.Request(environ) |
|
89 | request = webob.request.Request(environ) | |
90 | request_headers = request.headers |
|
90 | request_headers = request.headers | |
91 |
|
91 | |||
92 | request_headers.update({ |
|
92 | call_context = { | |
93 | # TODO: johbo: Remove this, rely on URL path only |
|
93 | # TODO: johbo: Remove this, rely on URL path only | |
94 |
' |
|
94 | 'repo_name': self._repo_name, | |
95 |
' |
|
95 | 'repo_path': self._repo_path, | |
96 |
' |
|
96 | 'path_info': get_path_info(environ), | |
|
97 | ||||
|
98 | 'repo_store': self.rc_extras.get('repo_store'), | |||
|
99 | 'server_config_file': self.rc_extras.get('config'), | |||
97 |
|
100 | |||
98 |
' |
|
101 | 'auth_user': self.rc_extras.get('username'), | |
99 |
' |
|
102 | 'auth_user_id': str(self.rc_extras.get('user_id')), | |
|
103 | 'auth_user_ip': self.rc_extras.get('ip'), | |||
100 |
|
104 | |||
101 | 'X-RC-Auth-User': self.rc_extras.get('username'), |
|
105 | 'repo_config': config, | |
102 | 'X-RC-Auth-User-Id': str(self.rc_extras.get('user_id')), |
|
106 | 'locked_status_code': rhodecode.CONFIG.get('lock_ret_code'), | |
103 | 'X-RC-Auth-User-Ip': self.rc_extras.get('ip'), |
|
107 | } | |
104 |
|
108 | |||
|
109 | request_headers.update({ | |||
105 | # TODO: johbo: Avoid encoding and put this into payload? |
|
110 | # TODO: johbo: Avoid encoding and put this into payload? | |
106 | 'X-RC-Repo-Config': base64.b64encode(config), |
|
111 | 'X_RC_VCS_STREAM_CALL_CONTEXT': base64.b64encode(msgpack.packb(call_context)) | |
107 | 'X-RC-Locked-Status-Code': rhodecode.CONFIG.get('lock_ret_code'), |
|
|||
108 | }) |
|
112 | }) | |
109 |
|
113 | |||
110 | method = environ['REQUEST_METHOD'] |
|
114 | method = environ['REQUEST_METHOD'] |
@@ -143,18 +143,6 b' def is_vcs_call(environ):' | |||||
143 | return False |
|
143 | return False | |
144 |
|
144 | |||
145 |
|
145 | |||
146 | def get_path_elem(route_path): |
|
|||
147 | if not route_path: |
|
|||
148 | return None |
|
|||
149 |
|
||||
150 | cleaned_route_path = route_path.lstrip('/') |
|
|||
151 | if cleaned_route_path: |
|
|||
152 | cleaned_route_path_elems = cleaned_route_path.split('/') |
|
|||
153 | if cleaned_route_path_elems: |
|
|||
154 | return cleaned_route_path_elems[0] |
|
|||
155 | return None |
|
|||
156 |
|
||||
157 |
|
||||
158 | def detect_vcs_request(environ, backends): |
|
146 | def detect_vcs_request(environ, backends): | |
159 | checks = { |
|
147 | checks = { | |
160 | 'hg': (is_hg, SimpleHg), |
|
148 | 'hg': (is_hg, SimpleHg), | |
@@ -164,11 +152,26 b' def detect_vcs_request(environ, backends' | |||||
164 | handler = None |
|
152 | handler = None | |
165 | # List of path views first chunk we don't do any checks |
|
153 | # List of path views first chunk we don't do any checks | |
166 | white_list = [ |
|
154 | white_list = [ | |
|
155 | # favicon often requested by browsers | |||
|
156 | 'favicon.ico', | |||
|
157 | ||||
167 | # e.g /_file_store/download |
|
158 | # e.g /_file_store/download | |
168 | '_file_store', |
|
159 | '_file_store++', | |
|
160 | ||||
|
161 | # _admin/api is safe too | |||
|
162 | '_admin/api', | |||
|
163 | ||||
|
164 | # _admin/gist is safe too | |||
|
165 | '_admin/gists++', | |||
|
166 | ||||
|
167 | # _admin/my_account is safe too | |||
|
168 | '_admin/my_account++', | |||
169 |
|
169 | |||
170 | # static files no detection |
|
170 | # static files no detection | |
171 | '_static', |
|
171 | '_static++', | |
|
172 | ||||
|
173 | # debug-toolbar | |||
|
174 | '_debug_toolbar++', | |||
172 |
|
175 | |||
173 | # skip ops ping, status |
|
176 | # skip ops ping, status | |
174 | '_admin/ops/ping', |
|
177 | '_admin/ops/ping', | |
@@ -180,14 +183,13 b' def detect_vcs_request(environ, backends' | |||||
180 | path_info = get_path_info(environ) |
|
183 | path_info = get_path_info(environ) | |
181 | path_url = path_info.lstrip('/') |
|
184 | path_url = path_info.lstrip('/') | |
182 |
|
185 | |||
183 |
|
|
186 | for item in white_list: | |
184 | log.debug('path `%s` in whitelist, skipping...', path_info) |
|
187 | if item.endswith('++') and path_url.startswith(item[:-2]): | |
185 | return handler |
|
188 | log.debug('path `%s` in whitelist (match:%s), skipping...', path_url, item) | |
186 |
|
189 | return handler | ||
187 | path_url = path_info.lstrip('/') |
|
190 | if item == path_url: | |
188 | if path_url in white_list: |
|
191 | log.debug('path `%s` in whitelist (match:%s), skipping...', path_url, item) | |
189 | log.debug('full url path `%s` in whitelist, skipping...', path_url) |
|
192 | return handler | |
190 | return handler |
|
|||
191 |
|
193 | |||
192 | if VCS_TYPE_KEY in environ: |
|
194 | if VCS_TYPE_KEY in environ: | |
193 | raw_type = environ[VCS_TYPE_KEY] |
|
195 | raw_type = environ[VCS_TYPE_KEY] | |
@@ -200,7 +202,7 b' def detect_vcs_request(environ, backends' | |||||
200 | log.debug('got handler:%s from environ', handler) |
|
202 | log.debug('got handler:%s from environ', handler) | |
201 |
|
203 | |||
202 | if not handler: |
|
204 | if not handler: | |
203 |
log.debug('request start: checking if request for `%s` is of VCS type in order: %s', path_ |
|
205 | log.debug('request start: checking if request for `%s` is of VCS type in order: %s', path_url, backends) | |
204 | for vcs_type in backends: |
|
206 | for vcs_type in backends: | |
205 | vcs_check, _handler = checks[vcs_type] |
|
207 | vcs_check, _handler = checks[vcs_type] | |
206 | if vcs_check(environ): |
|
208 | if vcs_check(environ): |
General Comments 0
You need to be logged in to leave comments.
Login now