Mercurial > kallithea
annotate rhodecode/lib/middleware/simplehg.py @ 1512:bf263968da47
merge beta in stable branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Oct 2011 01:08:50 +0200 |
parents | 9f6560667743 7d687ed11929 |
children | 752b0a7b7679 |
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.simplehg |
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 |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1128
diff
changeset
|
6 SimpleHG middleware for handling mercurial protocol request |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
7 (push/clone etc.). It's implemented with basic auth function |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1128
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:
1128
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:
1128
diff
changeset
|
18 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
19 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
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:
1128
diff
changeset
|
23 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
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/>. |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
26 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
27 import os |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
28 import logging |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
29 import traceback |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
30 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
31 from mercurial.error import RepoError |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
32 from mercurial.hgweb import hgweb_mod |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
33 |
177
93bd77e1f3c1
Changed auth basic handler only for mercurial request.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
34 from paste.auth.basic import AuthBasicAuthenticator |
93bd77e1f3c1
Changed auth basic handler only for mercurial request.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
35 from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
36 |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1321
diff
changeset
|
37 from rhodecode.lib import safe_str |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
607
diff
changeset
|
38 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:
719
diff
changeset
|
39 from rhodecode.lib.utils import make_ui, invalidate_cache, \ |
1507
7d687ed11929
changed check_... functions from their stupid names to something less retarded :)
Marcin Kuzminski <marcin@python-works.com>
parents:
1506
diff
changeset
|
40 is_valid_repo, ui_sections |
1497
71738535ed78
Removed deprecated usage of UserModel() in simplehg and simplegit
Marcin Kuzminski <marcin@python-works.com>
parents:
1495
diff
changeset
|
41 from rhodecode.model.db import User |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
42 |
334
6c23e72437e3
mercurial middleware now returns 500's instead of 404 on errors and 404 when repo not found, added tracebacks
Marcin Kuzminski <marcin@python-works.com>
parents:
331
diff
changeset
|
43 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
44 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
45 log = logging.getLogger(__name__) |
177
93bd77e1f3c1
Changed auth basic handler only for mercurial request.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
46 |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
47 |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
48 def is_mercurial(environ): |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
49 """Returns True if request's target is mercurial server - header |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
50 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
51 """ |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
52 http_accept = environ.get('HTTP_ACCEPT') |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
53 if http_accept and http_accept.startswith('application/mercurial'): |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
54 return True |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
55 return False |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
719
diff
changeset
|
56 |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
57 |
111 | 58 class SimpleHg(object): |
59 | |
60 def __init__(self, application, config): | |
61 self.application = application | |
62 self.config = config | |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
63 # base path of repo locations |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
64 self.basepath = self.config['base_path'] |
674
99875a8f2ad1
#49 Enabled anonymous access push and pull commands
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
65 #authenticate this mercurial request using authfunc |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
343
diff
changeset
|
66 self.authenticate = AuthBasicAuthenticator('', authfunc) |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
67 self.ipaddr = '0.0.0.0' |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
68 |
111 | 69 def __call__(self, environ, start_response): |
70 if not is_mercurial(environ): | |
71 return self.application(environ, start_response) | |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
72 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
73 proxy_key = 'HTTP_X_REAL_IP' |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
74 def_key = 'REMOTE_ADDR' |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
75 ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0')) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
76 |
898
9c4851dce8e6
fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
77 # 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
|
78 environ['pylons.status_code_redirect'] = True |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
79 |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
80 #====================================================================== |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
81 # EXTRACT REPOSITORY NAME FROM ENV |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
82 #====================================================================== |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
83 try: |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
84 repo_name = environ['REPO_NAME'] = self.__get_repository(environ) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
85 log.debug('Extracted repo name is %s' % repo_name) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
86 except: |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
87 return HTTPInternalServerError()(environ, start_response) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
88 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
89 #====================================================================== |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
90 # GET ACTION PULL or PUSH |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
91 #====================================================================== |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
92 action = self.__get_action(environ) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
93 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
94 #====================================================================== |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
95 # CHECK ANONYMOUS PERMISSION |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
96 #====================================================================== |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
97 if action in ['pull', 'push']: |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
98 anonymous_user = self.__get_user('default') |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
99 username = anonymous_user.username |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
100 anonymous_perm = self.__check_permission(action, |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
101 anonymous_user, |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
102 repo_name) |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
103 |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
104 if anonymous_perm is not True or anonymous_user.active is False: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
105 if anonymous_perm is not True: |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
106 log.debug('Not enough credentials to access this ' |
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
107 'repository as anonymous user') |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
108 if anonymous_user.active is False: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
109 log.debug('Anonymous access is disabled, running ' |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
110 'authentication') |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
111 #============================================================== |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1128
diff
changeset
|
112 # 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:
910
diff
changeset
|
113 # 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:
910
diff
changeset
|
114 #============================================================== |
607
ff449e9e6e38
fixed chrome repo switcher issue
Marcin Kuzminski <marcin@python-works.com>
parents:
606
diff
changeset
|
115 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
116 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:
1321
diff
changeset
|
117 self.authenticate.realm = \ |
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1321
diff
changeset
|
118 safe_str(self.config['rhodecode_realm']) |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
119 result = self.authenticate(environ) |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
120 if isinstance(result, str): |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
121 AUTH_TYPE.update(environ, 'basic') |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
122 REMOTE_USER.update(environ, result) |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
123 else: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
124 return result.wsgi_application(environ, start_response) |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
125 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
126 #============================================================== |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
127 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME FROM |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
128 # BASIC AUTH |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
129 #============================================================== |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
130 |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
131 if action in ['pull', 'push']: |
989
801cdb3e0969
simplified simplegit and simplehg a little
Marcin Kuzminski <marcin@python-works.com>
parents:
918
diff
changeset
|
132 username = REMOTE_USER(environ) |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
133 try: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
134 user = self.__get_user(username) |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
135 username = user.username |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
136 except: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
137 log.error(traceback.format_exc()) |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
138 return HTTPInternalServerError()(environ, |
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
139 start_response) |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
140 |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
141 #check permissions for this repository |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
142 perm = self.__check_permission(action, user, |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
143 repo_name) |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
144 if perm is not True: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
145 return HTTPForbidden()(environ, start_response) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
146 |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
147 extras = {'ip': ipaddr, |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
148 'username': username, |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
149 'action': action, |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
150 'repository': repo_name} |
655
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
151 |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
152 #====================================================================== |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
153 # MERCURIAL REQUEST HANDLING |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
154 #====================================================================== |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
155 |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
156 repo_path = safe_str(os.path.join(self.basepath, repo_name)) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
157 log.debug('Repository path is %s' % repo_path) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
158 |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
159 baseui = make_ui('db') |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
160 self.__inject_extras(repo_path, baseui, extras) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
161 |
334
6c23e72437e3
mercurial middleware now returns 500's instead of 404 on errors and 404 when repo not found, added tracebacks
Marcin Kuzminski <marcin@python-works.com>
parents:
331
diff
changeset
|
162 |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
163 # quick check if that dir exists... |
1507
7d687ed11929
changed check_... functions from their stupid names to something less retarded :)
Marcin Kuzminski <marcin@python-works.com>
parents:
1506
diff
changeset
|
164 if is_valid_repo(repo_name, self.basepath) is False: |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
165 return HTTPNotFound()(environ, start_response) |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
166 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
167 try: |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
168 #invalidate cache on push |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
169 if action == 'push': |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
170 self.__invalidate_cache(repo_name) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
171 |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
172 app = self.__make_app(repo_path, baseui, extras) |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
173 return app(environ, start_response) |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
445
diff
changeset
|
174 except RepoError, e: |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
175 if str(e).find('not found') != -1: |
334
6c23e72437e3
mercurial middleware now returns 500's instead of 404 on errors and 404 when repo not found, added tracebacks
Marcin Kuzminski <marcin@python-works.com>
parents:
331
diff
changeset
|
176 return HTTPNotFound()(environ, start_response) |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
177 except Exception: |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
178 log.error(traceback.format_exc()) |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
179 return HTTPInternalServerError()(environ, start_response) |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
180 |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
181 def __make_app(self, repo_name, baseui, extras): |
1276
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
182 """ |
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
183 Make an wsgi application using hgweb, and inject generated baseui |
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
184 instance, additionally inject some extras into ui object |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
185 """ |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
186 return hgweb_mod.hgweb(repo_name, name=repo_name, baseui=baseui) |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
187 |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
188 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
189 def __check_permission(self, action, user, repo_name): |
1276
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
190 """ |
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
191 Checks permissions using action (push/pull) user and repository |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
192 name |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1128
diff
changeset
|
193 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
194 :param action: push or pull action |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
195 :param user: user instance |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
196 :param repo_name: repository name |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
197 """ |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
198 if action == 'push': |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
199 if not HasPermissionAnyMiddleware('repository.write', |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
200 'repository.admin')(user, |
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
201 repo_name): |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
202 return False |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
203 |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
204 else: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
205 #any other action need at least read permission |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
206 if not HasPermissionAnyMiddleware('repository.read', |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
207 'repository.write', |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
208 'repository.admin')(user, |
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
209 repo_name): |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
210 return False |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
211 |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
212 return True |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
213 |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
214 def __get_repository(self, environ): |
1276
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
215 """ |
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
216 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:
1128
diff
changeset
|
217 |
910
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
218 :param environ: environ where PATH_INFO is stored |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
219 """ |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
220 try: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
221 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:]) |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
222 if repo_name.endswith('/'): |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
223 repo_name = repo_name.rstrip('/') |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
224 except: |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
225 log.error(traceback.format_exc()) |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
226 raise |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
227 |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
228 return repo_name |
811fa5d45de8
Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
229 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
230 def __get_user(self, username): |
1497
71738535ed78
Removed deprecated usage of UserModel() in simplehg and simplegit
Marcin Kuzminski <marcin@python-works.com>
parents:
1495
diff
changeset
|
231 return User.by_username(username) |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
232 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
233 def __get_action(self, environ): |
1276
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
234 """ |
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
235 Maps mercurial request commands into a clone,pull or push command. |
606
f31f1327c1e9
Fixed journal action loggin doubled messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
605
diff
changeset
|
236 This should always return a valid command string |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1128
diff
changeset
|
237 |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
238 :param environ: |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
239 """ |
330
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
240 mapping = {'changegroup': 'pull', |
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
241 'changegroupsubset': 'pull', |
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
242 'stream_out': 'pull', |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
243 'listkeys': 'pull', |
330
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
244 'unbundle': 'push', |
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
245 'pushkey': 'push', } |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
246 for qry in environ['QUERY_STRING'].split('&'): |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
247 if qry.startswith('cmd'): |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
248 cmd = qry.split('=')[-1] |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
249 if cmd in mapping: |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
250 return mapping[cmd] |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
251 else: |
1128
62a1d4155f6b
let action always return pull command for better security on pull restricted repos
Marcin Kuzminski <marcin@python-works.com>
parents:
989
diff
changeset
|
252 return 'pull' |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
253 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
254 def __invalidate_cache(self, repo_name): |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
255 """we know that some change was made to repositories and we should |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
256 invalidate the cache to see the changes right away but only for |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
257 push requests""" |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
258 invalidate_cache('get_repo_cached_%s' % repo_name) |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
259 |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
260 def __inject_extras(self,repo_path, baseui, extras={}): |
1321
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
261 """ |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
262 Injects some extra params into baseui instance |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
263 |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
264 also overwrites global settings with those takes from local hgrc file |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
265 |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
266 :param baseui: baseui instance |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
267 :param extras: dict with extra params to put into baseui |
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
268 """ |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
269 |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
270 hgrc = os.path.join(repo_path, '.hg', 'hgrc') |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
271 |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
272 # make our hgweb quiet so it doesn't print output |
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
273 baseui.setconfig('ui', 'quiet', 'true') |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
274 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
275 #inject some additional parameters that will be available in ui |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
276 #for hooks |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
277 for k, v in extras.items(): |
1276
88e750527c7c
small rewrite for injecting rhodecode_extras into ui. instead of injecting to hgweb instance, inject to ui and pass to hgweb. It's simpler and more readable.
Marcin Kuzminski <marcin@python-works.com>
parents:
1275
diff
changeset
|
278 baseui.setconfig('rhodecode_extras', k, v) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
279 |
341
1ef52a70f3b7
Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
340
diff
changeset
|
280 repoui = make_ui('file', hgrc, False) |
605
72bed56219d6
security bugfix simplehg wasn't checking for permissions on remote commands different than pull or push.
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
281 |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
282 if repoui: |
385
eda5f01de3c4
fixes #20 hg middleware breaks ui() instance when repository has hgrc file.
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
283 #overwrite our ui instance with the section from hgrc file |
eda5f01de3c4
fixes #20 hg middleware breaks ui() instance when repository has hgrc file.
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
284 for section in ui_sections: |
eda5f01de3c4
fixes #20 hg middleware breaks ui() instance when repository has hgrc file.
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
285 for k, v in repoui.configitems(section): |
1321
560206522815
fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
286 baseui.setconfig(section, k, v) |
1495
5bd42279930c
#176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
287 |