Mercurial > kallithea
comparison rhodecode/lib/middleware/simplegit.py @ 2065:9ab21c5ddb84 rhodecode-0.0.1.3.2
merge with beta
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 28 Feb 2012 20:21:35 +0200 |
parents | 82a88013a3fd 9f0fe6777833 |
children | ecd59c28f432 |
comparison
equal
deleted
inserted
replaced
2051:8fbb1d250804 | 2065:9ab21c5ddb84 |
---|---|
23 # | 23 # |
24 # You should have received a copy of the GNU General Public License | 24 # You should have received a copy of the GNU General Public License |
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 25 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | 26 |
27 import os | 27 import os |
28 import re | |
28 import logging | 29 import logging |
29 import traceback | 30 import traceback |
30 | 31 |
31 from dulwich import server as dulserver | 32 from dulwich import server as dulserver |
32 | 33 |
77 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError | 78 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
78 | 79 |
79 log = logging.getLogger(__name__) | 80 log = logging.getLogger(__name__) |
80 | 81 |
81 | 82 |
83 GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)') | |
84 | |
85 | |
82 def is_git(environ): | 86 def is_git(environ): |
83 """Returns True if request's target is git server. | 87 path_info = environ['PATH_INFO'] |
84 ``HTTP_USER_AGENT`` would then have git client version given. | 88 isgit_path = GIT_PROTO_PAT.match(path_info) |
85 | 89 log.debug('is a git path %s pathinfo : %s' % (isgit_path, path_info)) |
86 :param environ: | 90 return isgit_path |
87 """ | |
88 http_user_agent = environ.get('HTTP_USER_AGENT') | |
89 if http_user_agent and http_user_agent.startswith('git'): | |
90 return True | |
91 return False | |
92 | 91 |
93 | 92 |
94 class SimpleGit(BaseVCSController): | 93 class SimpleGit(BaseVCSController): |
95 | 94 |
96 def _handle_request(self, environ, start_response): | 95 def _handle_request(self, environ, start_response): |
96 | |
97 if not is_git(environ): | 97 if not is_git(environ): |
98 return self.application(environ, start_response) | 98 return self.application(environ, start_response) |
99 | 99 |
100 proxy_key = 'HTTP_X_REAL_IP' | 100 proxy_key = 'HTTP_X_REAL_IP' |
101 def_key = 'REMOTE_ADDR' | 101 def_key = 'REMOTE_ADDR' |
216 | 216 |
217 :param environ: environ where PATH_INFO is stored | 217 :param environ: environ where PATH_INFO is stored |
218 """ | 218 """ |
219 try: | 219 try: |
220 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO']) | 220 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO']) |
221 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:]) | 221 repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1) |
222 if repo_name.endswith('/'): | |
223 repo_name = repo_name.rstrip('/') | |
224 except: | 222 except: |
225 log.error(traceback.format_exc()) | 223 log.error(traceback.format_exc()) |
226 raise | 224 raise |
227 repo_name = repo_name.split('/')[0] | 225 |
228 return repo_name | 226 return repo_name |
229 | 227 |
230 def __get_user(self, username): | 228 def __get_user(self, username): |
231 return User.get_by_username(username) | 229 return User.get_by_username(username) |
232 | 230 |
236 :param environ: | 234 :param environ: |
237 """ | 235 """ |
238 service = environ['QUERY_STRING'].split('=') | 236 service = environ['QUERY_STRING'].split('=') |
239 if len(service) > 1: | 237 if len(service) > 1: |
240 service_cmd = service[1] | 238 service_cmd = service[1] |
241 mapping = {'git-receive-pack': 'push', | 239 mapping = { |
242 'git-upload-pack': 'pull', | 240 'git-receive-pack': 'push', |
243 } | 241 'git-upload-pack': 'pull', |
242 } | |
244 | 243 |
245 return mapping.get(service_cmd, | 244 return mapping.get(service_cmd, |
246 service_cmd if service_cmd else 'other') | 245 service_cmd if service_cmd else 'other') |
247 else: | 246 else: |
248 return 'other' | 247 return 'other' |