comparison rhodecode/lib/middleware/simplegit.py @ 903:04c9bb9ca6d6 beta

code docs, updates
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 31 Dec 2010 19:58:43 +0100
parents 07a6e8c65526
children b2d5868cc4b8
comparison
equal deleted inserted replaced
902:07a6e8c65526 903:04c9bb9ca6d6
1 #!/usr/bin/env python 1 # -*- coding: utf-8 -*-
2 # encoding: utf-8 2 """
3 # middleware to handle git api calls 3 rhodecode.lib.middleware.simplegit
4 # Copyright (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 # 5
6 SimpleGit middleware for handling git protocol request (push/clone etc.)
7 It's implemented with basic auth function
8
9 :created_on: Apr 28, 2010
10 :author: marcink
11 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
13 """
6 # This program is free software; you can redistribute it and/or 14 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 15 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2 16 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license. 17 # of the License or (at your opinion) any later version of the license.
10 # 18 #
15 # 23 #
16 # 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
17 # along with this program; if not, write to the Free Software 25 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA. 27 # MA 02110-1301, USA.
20 """ 28
21 Created on 2010-04-28 29 import os
22 30 import logging
23 @author: marcink 31 import traceback
24 SimpleGit middleware for handling git protocol request (push/clone etc.)
25 It's implemented with basic auth function
26 """
27 32
28 from dulwich import server as dulserver 33 from dulwich import server as dulserver
29 34
30 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler): 35 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler):
31 36
58 'git-receive-pack': dulserver.ReceivePackHandler, 63 'git-receive-pack': dulserver.ReceivePackHandler,
59 } 64 }
60 65
61 from dulwich.repo import Repo 66 from dulwich.repo import Repo
62 from dulwich.web import HTTPGitApplication 67 from dulwich.web import HTTPGitApplication
68
63 from paste.auth.basic import AuthBasicAuthenticator 69 from paste.auth.basic import AuthBasicAuthenticator
64 from paste.httpheaders import REMOTE_USER, AUTH_TYPE 70 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
71
65 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware 72 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware
66 from rhodecode.lib.utils import invalidate_cache, check_repo_fast 73 from rhodecode.lib.utils import invalidate_cache, check_repo_fast
67 from rhodecode.model.user import UserModel 74 from rhodecode.model.user import UserModel
75
68 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError 76 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
69 import logging
70 import os
71 import traceback
72 77
73 log = logging.getLogger(__name__) 78 log = logging.getLogger(__name__)
74 79
75 def is_git(environ): 80 def is_git(environ):
76 """ 81 """Returns True if request's target is git server. ``HTTP_USER_AGENT`` would
77 Returns True if request's target is git server. ``HTTP_USER_AGENT`` would
78 then have git client version given. 82 then have git client version given.
79 83
80 :param environ: 84 :param environ:
81 """ 85 """
82 http_user_agent = environ.get('HTTP_USER_AGENT') 86 http_user_agent = environ.get('HTTP_USER_AGENT')
198 202
199 def __get_user(self, username): 203 def __get_user(self, username):
200 return UserModel().get_by_username(username, cache=True) 204 return UserModel().get_by_username(username, cache=True)
201 205
202 def __get_action(self, environ): 206 def __get_action(self, environ):
203 """ 207 """Maps git request commands into a pull or push command.
204 Maps git request commands into a pull or push command. 208
205 :param environ: 209 :param environ:
206 """ 210 """
207 service = environ['QUERY_STRING'].split('=') 211 service = environ['QUERY_STRING'].split('=')
208 if len(service) > 1: 212 if len(service) > 1:
209 service_cmd = service[1] 213 service_cmd = service[1]