Mercurial > kallithea
annotate rhodecode/lib/middleware/simplegit.py @ 989:801cdb3e0969 beta
simplified simplegit and simplehg a little
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 01 Feb 2011 02:18:05 +0100 |
parents | b2d5868cc4b8 |
children | 6832ef664673 |
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.) |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
7 It's implemented with basic auth function |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
8 |
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 |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
11 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
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 """ |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # This program is free software; you can redistribute it and/or |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # modify it under the terms of the GNU General Public License |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # as published by the Free Software Foundation; version 2 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # of the License or (at your opinion) any later version of the license. |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # |
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. |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # |
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 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 # along with this program; if not, write to the Free Software |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 # MA 02110-1301, USA. |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
625
diff
changeset
|
28 |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
29 import os |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
30 import logging |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
31 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
|
32 |
625
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
33 from dulwich import server as dulserver |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
34 |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
35 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler): |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
36 |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
37 def handle(self): |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
38 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
|
39 |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
40 graph_walker = dulserver.ProtocolGraphWalker(self, self.repo.object_store, |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
41 self.repo.get_peeled) |
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? |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
47 if len(objects_iter) == 0: |
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)) |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
51 dulserver.write_pack_data(dulserver.ProtocolFile(None, write), objects_iter, |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
52 len(objects_iter)) |
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 |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
625
diff
changeset
|
72 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
|
73 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
|
74 from rhodecode.model.user import UserModel |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
75 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 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
|
77 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 log = logging.getLogger(__name__) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 |
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
|
80 def is_git(environ): |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
81 """Returns True if request's target is git server. |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
82 ``HTTP_USER_AGENT`` would then have git client version given. |
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
|
83 |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
84 :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
|
85 """ |
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 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
|
87 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
|
88 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
|
89 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
|
90 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 class SimpleGit(object): |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 def __init__(self, application, config): |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 self.application = application |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 self.config = config |
625
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
96 #authenticate this git request using |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 self.authenticate = AuthBasicAuthenticator('', authfunc) |
655
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
98 self.ipaddr = '0.0.0.0' |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
99 self.repository = None |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
100 self.username = None |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
101 self.action = None |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
102 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 def __call__(self, environ, start_response): |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 if not is_git(environ): |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 return self.application(environ, start_response) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
106 |
655
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
107 proxy_key = 'HTTP_X_REAL_IP' |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
108 def_key = 'REMOTE_ADDR' |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
109 self.ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0')) |
898
9c4851dce8e6
fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
110 # 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
|
111 environ['pylons.status_code_redirect'] = True |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
112 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
113 #====================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
114 # 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
|
115 #====================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
116 self.action = self.__get_action(environ) |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 try: |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
118 #================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
119 # GET REPOSITORY NAME |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
120 #================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
121 self.repo_name = self.__get_repository(environ) |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 except: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 return HTTPInternalServerError()(environ, start_response) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
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 #====================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
126 # CHECK ANONYMOUS PERMISSION |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
127 #====================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
128 if self.action in ['pull', 'push'] or self.action: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
129 anonymous_user = self.__get_user('default') |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
130 self.username = anonymous_user.username |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
131 anonymous_perm = self.__check_permission(self.action, anonymous_user , |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
132 self.repo_name) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
133 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
134 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
|
135 if anonymous_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
|
136 log.debug('Not enough credentials to access this repository' |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
137 'as anonymous user') |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
138 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
|
139 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
|
140 'authentication') |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
141 #============================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
142 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
143 # 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
|
144 #============================================================== |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
146 if not REMOTE_USER(environ): |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
147 self.authenticate.realm = str(self.config['rhodecode_realm']) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 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
|
152 else: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
153 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
|
154 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
155 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
156 #============================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
157 # 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
|
158 # BASIC AUTH |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
159 #============================================================== |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
161 if self.action in ['pull', 'push'] or self.action: |
989
801cdb3e0969
simplified simplegit and simplehg a little
Marcin Kuzminski <marcin@python-works.com>
parents:
918
diff
changeset
|
162 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
|
163 try: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
164 user = self.__get_user(username) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
165 self.username = user.username |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
166 except: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
167 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
|
168 return HTTPInternalServerError()(environ, start_response) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
169 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
170 #check permissions for this repository |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
171 perm = self.__check_permission(self.action, user, self.repo_name) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
172 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
|
173 print 'not allowed' |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
174 return HTTPForbidden()(environ, start_response) |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 |
655
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
176 self.extras = {'ip':self.ipaddr, |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
177 'username':self.username, |
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
178 'action':self.action, |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
179 'repository':self.repo_name} |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 #=================================================================== |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 # GIT REQUEST HANDLING |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 #=================================================================== |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 self.basepath = self.config['base_path'] |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 self.repo_path = os.path.join(self.basepath, self.repo_name) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 #quick check if that dir exists... |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 if check_repo_fast(self.repo_name, self.basepath): |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 return HTTPNotFound()(environ, start_response) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 try: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
190 app = self.__make_app() |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
635
diff
changeset
|
191 except: |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 log.error(traceback.format_exc()) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 return HTTPInternalServerError()(environ, start_response) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 #invalidate cache on push |
655
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
196 if self.action == 'push': |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 self.__invalidate_cache(self.repo_name) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 messages = [] |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 messages.append('thank you for using rhodecode') |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 return app(environ, start_response) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 else: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 return app(environ, start_response) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 def __make_app(self): |
625
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
206 backend = dulserver.DictBackend({'/' + self.repo_name: Repo(self.repo_path)}) |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 gitserve = HTTPGitApplication(backend) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
208 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 return gitserve |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
211 def __check_permission(self, action, user, repo_name): |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
212 """Checks permissions using action (push/pull) user and repository |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
213 name |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
214 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
215 :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
|
216 :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
|
217 :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
|
218 """ |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
219 if action == 'push': |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
220 if not HasPermissionAnyMiddleware('repository.write', |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
221 'repository.admin')\ |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
222 (user, repo_name): |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
223 return False |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
224 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
225 else: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
226 #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
|
227 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
|
228 'repository.write', |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
229 'repository.admin')\ |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
230 (user, repo_name): |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
231 return False |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
232 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
233 return True |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
234 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
235 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
236 def __get_repository(self, environ): |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
237 """Get's repository name out of PATH_INFO header |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
238 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
239 :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
|
240 """ |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
241 try: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 except: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
246 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
|
247 raise |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
248 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
|
249 return repo_name |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
250 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
251 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
252 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
|
253 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
|
254 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
255 def __get_action(self, environ): |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
256 """Maps git request commands into a pull or push command. |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
257 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
258 :param environ: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
259 """ |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
260 service = environ['QUERY_STRING'].split('=') |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
261 if len(service) > 1: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
262 service_cmd = service[1] |
625
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
263 mapping = {'git-receive-pack': 'push', |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
264 'git-upload-pack': 'pull', |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
265 } |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
266 |
625
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
267 return mapping.get(service_cmd, service_cmd if service_cmd else 'other') |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
268 else: |
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
269 return 'other' |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
270 |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 def __invalidate_cache(self, repo_name): |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
272 """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
|
273 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
|
274 push requests""" |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
275 invalidate_cache('get_repo_cached_%s' % repo_name) |