annotate rhodecode/lib/middleware/simplegit.py @ 1496:f4fed0b32103 beta

Rewrote git middleware with the same pattern as recent fix for #176 - additionally fixed dulwich server bug, that used old deprecated method. This fix caused huge improvement of speed for fetching git repos - moved simplehg and simplegit middleware into begining of pylons callstack. This low level middleware don't need to run any of the middlewares except each other.
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 29 Sep 2011 23:34:47 +0300
parents b7563ad4e7ee
children 71738535ed78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
1 # -*- coding: utf-8 -*-
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
2 """
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
3 rhodecode.lib.middleware.simplegit
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
5
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
6 SimpleGit middleware for handling git protocol request (push/clone etc.)
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
7 It's implemented with basic auth function
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
8
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
9 :created_on: Apr 28, 2010
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
10 :author: marcink
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
11 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
12 :license: GPLv3, see COPYING for more details.
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
13 """
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
14 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
15 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
16 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
17 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
18 #
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # This program is distributed in the hope that it will be useful,
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
23 #
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
635
fd63782c4426 Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents: 625
diff changeset
26
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
27 import os
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
28 import logging
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
29 import traceback
635
fd63782c4426 Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents: 625
diff changeset
30
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
31 from dulwich import server as dulserver
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
32
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
33
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
34 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler):
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
35
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
36 def handle(self):
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
37 write = lambda x: self.proto.write_sideband(1, x)
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
38
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
39 graph_walker = dulserver.ProtocolGraphWalker(self,
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
40 self.repo.object_store,
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
41 self.repo.get_peeled)
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
42 objects_iter = self.repo.fetch_objects(
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
43 graph_walker.determine_wants, graph_walker, self.progress,
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
44 get_tagged=self.get_tagged)
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
45
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
46 # Do they want any objects?
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
47 if objects_iter is None or len(objects_iter) == 0:
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
48 return
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
49
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
50 self.progress("counting objects: %d, done.\n" % len(objects_iter))
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
51 dulserver.write_pack_objects(dulserver.ProtocolFile(None, write),
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
52 objects_iter, len(objects_iter))
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
53 messages = []
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
54 messages.append('thank you for using rhodecode')
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
55
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
56 for msg in messages:
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
57 self.progress(msg + "\n")
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
58 # we are done
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
59 self.proto.write("0000")
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
60
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
61 dulserver.DEFAULT_HANDLERS = {
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
62 'git-upload-pack': SimpleGitUploadPackHandler,
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
63 'git-receive-pack': dulserver.ReceivePackHandler,
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
64 }
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
65
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 from dulwich.repo import Repo
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 from dulwich.web import HTTPGitApplication
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
68
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 from paste.auth.basic import AuthBasicAuthenticator
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
71
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
72 from rhodecode.lib import safe_str
635
fd63782c4426 Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents: 625
diff changeset
73 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
74 from rhodecode.lib.utils import invalidate_cache, check_repo_fast
635
fd63782c4426 Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents: 625
diff changeset
75 from rhodecode.model.user import UserModel
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
76
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 log = logging.getLogger(__name__)
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
81
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
82 def is_git(environ):
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
83 """Returns True if request's target is git server.
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
84 ``HTTP_USER_AGENT`` would then have git client version given.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
85
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
86 :param environ:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
87 """
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
88 http_user_agent = environ.get('HTTP_USER_AGENT')
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
89 if http_user_agent and http_user_agent.startswith('git'):
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
90 return True
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
91 return False
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
92
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
93
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 class SimpleGit(object):
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 def __init__(self, application, config):
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 self.application = application
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 self.config = config
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
99 # base path of repo locations
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
100 self.basepath = self.config['base_path']
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
101 #authenticate this mercurial request using authfunc
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 self.authenticate = AuthBasicAuthenticator('', authfunc)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
103
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 def __call__(self, environ, start_response):
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 if not is_git(environ):
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 return self.application(environ, start_response)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
107
655
aefc371a2531 propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents: 643
diff changeset
108 proxy_key = 'HTTP_X_REAL_IP'
aefc371a2531 propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents: 643
diff changeset
109 def_key = 'REMOTE_ADDR'
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
110 ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0'))
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
111 username = None
898
9c4851dce8e6 fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
112 # skip passing error to error controller
9c4851dce8e6 fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
113 environ['pylons.status_code_redirect'] = True
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
114
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
115 #======================================================================
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
116 # EXTRACT REPOSITORY NAME FROM ENV
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
117 #======================================================================
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
118 try:
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
119 repo_name = self.__get_repository(environ)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
120 log.debug('Extracted repo name is %s' % repo_name)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
121 except:
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
122 return HTTPInternalServerError()(environ, start_response)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
123
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
124 #======================================================================
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
125 # GET ACTION PULL or PUSH
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
126 #======================================================================
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
127 action = self.__get_action(environ)
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
129 #======================================================================
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
130 # CHECK ANONYMOUS PERMISSION
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
131 #======================================================================
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
132 if action in ['pull', 'push']:
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
133 anonymous_user = self.__get_user('default')
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
134 username = anonymous_user.username
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
135 anonymous_perm = self.__check_permission(action,
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
136 anonymous_user,
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
137 repo_name)
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
138
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
139 if anonymous_perm is not True or anonymous_user.active is False:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
140 if anonymous_perm is not True:
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
141 log.debug('Not enough credentials to access this '
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
142 'repository as anonymous user')
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
143 if anonymous_user.active is False:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
144 log.debug('Anonymous access is disabled, running '
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
145 'authentication')
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
146 #==============================================================
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
147 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
148 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
149 #==============================================================
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
151 if not REMOTE_USER(environ):
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
152 self.authenticate.realm = \
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
153 safe_str(self.config['rhodecode_realm'])
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
154 result = self.authenticate(environ)
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
155 if isinstance(result, str):
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
156 AUTH_TYPE.update(environ, 'basic')
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
157 REMOTE_USER.update(environ, result)
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
158 else:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
159 return result.wsgi_application(environ, start_response)
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
160
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
161 #==============================================================
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
162 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME FROM
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
163 # BASIC AUTH
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
164 #==============================================================
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
166 if action in ['pull', 'push']:
989
801cdb3e0969 simplified simplegit and simplehg a little
Marcin Kuzminski <marcin@python-works.com>
parents: 918
diff changeset
167 username = REMOTE_USER(environ)
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
168 try:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
169 user = self.__get_user(username)
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
170 username = user.username
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
171 except:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
172 log.error(traceback.format_exc())
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
173 return HTTPInternalServerError()(environ,
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
174 start_response)
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
175
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
176 #check permissions for this repository
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
177 perm = self.__check_permission(action, user,
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
178 repo_name)
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
179 if perm is not True:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
180 return HTTPForbidden()(environ, start_response)
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
182 extras = {'ip': ipaddr,
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
183 'username': username,
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
184 'action': action,
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
185 'repository': repo_name}
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 #===================================================================
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 # GIT REQUEST HANDLING
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 #===================================================================
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
190
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
191 repo_path = safe_str(os.path.join(self.basepath, repo_name))
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
192 log.debug('Repository path is %s' % repo_path)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
193
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
194 # quick check if that dir exists...
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
195 if check_repo_fast(repo_name, self.basepath):
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 return HTTPNotFound()(environ, start_response)
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
197
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 try:
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
199 #invalidate cache on push
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
200 if action == 'push':
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
201 self.__invalidate_cache(repo_name)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
202
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
203 app = self.__make_app(repo_name, repo_path)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
204 return app(environ, start_response)
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
205 except Exception:
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 log.error(traceback.format_exc())
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 return HTTPInternalServerError()(environ, start_response)
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
209 def __make_app(self, repo_name, repo_path):
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
210 """
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
211 Make an wsgi application using dulserver
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
212
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
213 :param repo_name: name of the repository
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
214 :param repo_path: full path to the repository
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
215 """
1283
d6524f3025e8 small fixes for gitmiddleware
Marcin Kuzminski <marcin@python-works.com>
parents: 1275
diff changeset
216
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
217 _d = {'/' + repo_name: Repo(repo_path)}
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
218 backend = dulserver.DictBackend(_d)
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 gitserve = HTTPGitApplication(backend)
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 return gitserve
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
223 def __check_permission(self, action, user, repo_name):
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
224 """
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
225 Checks permissions using action (push/pull) user and repository
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
226 name
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
227
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
228 :param action: push or pull action
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
229 :param user: user instance
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
230 :param repo_name: repository name
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
231 """
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
232 if action == 'push':
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
233 if not HasPermissionAnyMiddleware('repository.write',
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
234 'repository.admin')(user,
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
235 repo_name):
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
236 return False
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
237
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
238 else:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
239 #any other action need at least read permission
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
240 if not HasPermissionAnyMiddleware('repository.read',
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
241 'repository.write',
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
242 'repository.admin')(user,
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
243 repo_name):
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
244 return False
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
245
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
246 return True
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
247
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
248 def __get_repository(self, environ):
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
249 """
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
250 Get's repository name out of PATH_INFO header
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
251
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
252 :param environ: environ where PATH_INFO is stored
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
253 """
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
254 try:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
255 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:])
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
256 if repo_name.endswith('/'):
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
257 repo_name = repo_name.rstrip('/')
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
258 except:
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
259 log.error(traceback.format_exc())
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
260 raise
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
261 repo_name = repo_name.split('/')[0]
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
262 return repo_name
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 903
diff changeset
263
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264 def __get_user(self, username):
635
fd63782c4426 Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents: 625
diff changeset
265 return UserModel().get_by_username(username, cache=True)
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 def __get_action(self, environ):
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
268 """Maps git request commands into a pull or push command.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 989
diff changeset
269
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
270 :param environ:
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
271 """
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
272 service = environ['QUERY_STRING'].split('=')
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 if len(service) > 1:
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 service_cmd = service[1]
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
275 mapping = {'git-receive-pack': 'push',
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
276 'git-upload-pack': 'pull',
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277 }
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
279 return mapping.get(service_cmd,
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
280 service_cmd if service_cmd else 'other')
625
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
281 else:
d5372213db98 some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents: 620
diff changeset
282 return 'other'
620
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
283
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284 def __invalidate_cache(self, repo_name):
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
285 """we know that some change was made to repositories and we should
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286 invalidate the cache to see the changes right away but only for
19a62a5490fe added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287 push requests"""
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
288 invalidate_cache('get_repo_cached_%s' % repo_name)
1496
f4fed0b32103 Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
289