Mercurial > kallithea
annotate rhodecode/lib/middleware/simplehg.py @ 1036:405b80e4ccd5 beta
Major refactoring, removed when possible calls to app globals.
Refactored models to fetch the paths needed for scans from database directly
small fixes in base
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 12 Feb 2011 21:21:23 +0100 |
parents | 801cdb3e0969 |
children | 62a1d4155f6b |
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 |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
6 SimpleHG middleware for handling mercurial protocol request |
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 |
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 """ |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
14 # This program is free software; you can redistribute it and/or |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
15 # modify it under the terms of the GNU General Public License |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
16 # as published by the Free Software Foundation; version 2 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
17 # of the License or (at your opinion) any later version of the license. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
18 # |
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. |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
23 # |
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 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
25 # along with this program; if not, write to the Free Software |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
248
diff
changeset
|
27 # MA 02110-1301, USA. |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
385
diff
changeset
|
28 |
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
|
29 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
|
30 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
|
31 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
|
32 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
33 from mercurial.error import RepoError |
111 | 34 from mercurial.hgweb import hgweb |
35 from mercurial.hgweb.request import wsgiapplication | |
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 |
177
93bd77e1f3c1
Changed auth basic handler only for mercurial request.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
37 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
|
38 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
|
39 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
607
diff
changeset
|
40 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
|
41 from rhodecode.lib.utils import make_ui, invalidate_cache, \ |
385
eda5f01de3c4
fixes #20 hg middleware breaks ui() instance when repository has hgrc file.
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
42 check_repo_fast, ui_sections |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
607
diff
changeset
|
43 from rhodecode.model.user import UserModel |
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
|
44 |
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
|
45 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
|
46 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
47 log = logging.getLogger(__name__) |
177
93bd77e1f3c1
Changed auth basic handler only for mercurial request.
Marcin Kuzminski <marcin@python-works.com>
parents:
171
diff
changeset
|
48 |
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
|
49 def is_mercurial(environ): |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
50 """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
|
51 ``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
|
52 """ |
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 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
|
54 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
|
55 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
|
56 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
|
57 |
111 | 58 class SimpleHg(object): |
59 | |
60 def __init__(self, application, config): | |
61 self.application = application | |
62 self.config = config | |
674
99875a8f2ad1
#49 Enabled anonymous access push and pull commands
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
63 #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
|
64 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
|
65 self.ipaddr = '0.0.0.0' |
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
|
66 self.repo_name = None |
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.username = None |
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
|
68 self.action = None |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
69 |
111 | 70 def __call__(self, environ, start_response): |
71 if not is_mercurial(environ): | |
72 return self.application(environ, start_response) | |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
73 |
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
|
74 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
|
75 def_key = 'REMOTE_ADDR' |
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
|
76 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
|
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 |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
79 |
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
|
80 #====================================================================== |
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
|
81 # 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
|
82 #====================================================================== |
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
|
83 self.action = self.__get_action(environ) |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
84 try: |
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
|
85 #================================================================== |
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
|
86 # GET 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
|
87 #================================================================== |
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
|
88 self.repo_name = self.__get_repository(environ) |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
89 except: |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
90 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
|
91 |
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
|
92 #====================================================================== |
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
|
93 # 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
|
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 if self.action in ['pull', '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
|
96 anonymous_user = self.__get_user('default') |
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
|
97 self.username = anonymous_user.username |
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_perm = self.__check_permission(self.action, anonymous_user , |
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
|
99 self.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
|
100 |
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
|
101 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
|
102 if anonymous_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
|
103 log.debug('Not enough credentials to access this repository' |
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 'as anonymous user') |
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_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
|
106 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
|
107 'authentication') |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
108 #============================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
109 # 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:
910
diff
changeset
|
110 # 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
|
111 #============================================================== |
607
ff449e9e6e38
fixed chrome repo switcher issue
Marcin Kuzminski <marcin@python-works.com>
parents:
606
diff
changeset
|
112 |
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
|
113 if not REMOTE_USER(environ): |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
114 self.authenticate.realm = 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 |
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
|
122 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
910
diff
changeset
|
123 #============================================================== |
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
|
124 # 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
|
125 # BASIC AUTH |
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 |
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 if self.action in ['pull', 'push']: |
989
801cdb3e0969
simplified simplegit and simplehg a little
Marcin Kuzminski <marcin@python-works.com>
parents:
918
diff
changeset
|
129 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
|
130 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
|
131 user = self.__get_user(username) |
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
|
132 self.username = user.username |
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 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
|
134 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
|
135 return HTTPInternalServerError()(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
|
136 |
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 #check permissions for this repository |
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
|
138 perm = self.__check_permission(self.action, user, self.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
|
139 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
|
140 return HTTPForbidden()(environ, start_response) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
141 |
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
|
142 self.extras = {'ip':self.ipaddr, |
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
|
143 'username':self.username, |
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
|
144 'action':self.action, |
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
|
145 'repository':self.repo_name} |
655
aefc371a2531
propagate changes for #48 into simplegit.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
146 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
147 #=================================================================== |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
148 # MERCURIAL REQUEST HANDLING |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
149 #=================================================================== |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
150 environ['PATH_INFO'] = '/'#since we wrap into hgweb, reset the path |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
151 self.baseui = make_ui('db') |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
152 self.basepath = self.config['base_path'] |
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
|
153 self.repo_path = os.path.join(self.basepath, self.repo_name) |
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
|
154 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
155 #quick check if that dir exists... |
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
|
156 if check_repo_fast(self.repo_name, self.basepath): |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
157 return HTTPNotFound()(environ, start_response) |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
158 try: |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
159 app = wsgiapplication(self.__make_app) |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
445
diff
changeset
|
160 except RepoError, e: |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
161 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
|
162 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
|
163 except Exception: |
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
164 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
|
165 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
|
166 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
167 #invalidate cache on push |
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
|
168 if self.action == '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
|
169 self.__invalidate_cache(self.repo_name) |
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
|
170 |
719
62c1fab8d29b
removed 'thank you..' message from simpleHG, it should be used in hooks.
Marcin Kuzminski <marcin@python-works.com>
parents:
674
diff
changeset
|
171 return app(environ, start_response) |
257
66f617f162f8
added custom messages for remote responses.
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
172 |
111 | 173 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
174 def __make_app(self): |
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
|
175 """Make an wsgi application using hgweb, and my generated baseui |
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
|
176 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
|
177 """ |
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
|
178 |
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
|
179 hgserve = hgweb(str(self.repo_path), baseui=self.baseui) |
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
|
180 return self.__load_web_settings(hgserve, self.extras) |
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
|
181 |
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
|
182 |
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
|
183 def __check_permission(self, action, user, 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
|
184 """Checks permissions using action (push/pull) user and repository |
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 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
|
186 |
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 :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
|
188 :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
|
189 :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
|
190 """ |
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
|
191 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
|
192 if not HasPermissionAnyMiddleware('repository.write', |
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
|
193 'repository.admin')\ |
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 (user, 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
|
195 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
|
196 |
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 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
|
198 #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
|
199 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
|
200 'repository.write', |
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
|
201 'repository.admin')\ |
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 (user, 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
|
203 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
|
204 |
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 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
|
206 |
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 |
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
|
208 def __get_repository(self, 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
|
209 """Get's repository name out of PATH_INFO header |
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 |
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 :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
|
212 """ |
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 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 |
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 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
|
222 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
223 def __get_user(self, username): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
607
diff
changeset
|
224 return UserModel().get_by_username(username, cache=True) |
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
|
225 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
226 def __get_action(self, environ): |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
227 """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
|
228 This should always return a valid command string |
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
|
229 |
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
|
230 :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
|
231 """ |
330
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
232 mapping = {'changegroup': 'pull', |
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
233 'changegroupsubset': 'pull', |
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
234 '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
|
235 'listkeys': 'pull', |
330
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
236 'unbundle': 'push', |
4c9a295d80a4
added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents:
317
diff
changeset
|
237 '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
|
238 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
|
239 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
|
240 cmd = qry.split('=')[-1] |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
241 if mapping.has_key(cmd): |
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
242 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
|
243 else: |
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
|
244 return cmd |
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
|
245 |
197
da59b7e07e3c
Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents:
194
diff
changeset
|
246 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
|
247 """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
|
248 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
|
249 push requests""" |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
250 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
|
251 |
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
|
252 |
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
|
253 def __load_web_settings(self, hgserve, extras={}): |
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
|
254 #set the global ui for hgserve instance passed |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
255 hgserve.repo.ui = self.baseui |
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
|
256 |
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
|
257 hgrc = os.path.join(self.repo_path, '.hg', 'hgrc') |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
258 |
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
|
259 #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
|
260 #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
|
261 for k, v in extras.items(): |
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
|
262 hgserve.repo.ui.setconfig('rhodecode_extras', k, v) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
263 |
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
|
264 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
|
265 |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
266 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
|
267 #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
|
268 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
|
269 for k, v in repoui.configitems(section): |
eda5f01de3c4
fixes #20 hg middleware breaks ui() instance when repository has hgrc file.
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
270 hgserve.repo.ui.setconfig(section, k, v) |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
271 |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
272 return hgserve |