annotate rhodecode/lib/middleware/simplehg.py @ 3997:156cb1cdd7ad

Added handling of copied files diff parsing
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 15 Jun 2013 20:47:41 +0200
parents 5293d4bbb1ea
children a5888ca796b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
903
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
1 # -*- coding: utf-8 -*-
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
2 """
04c9bb9ca6d6 code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
3 rhodecode.lib.middleware.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
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
11 :copyright: (C) 2010-2012 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
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
177
93bd77e1f3c1 Changed auth basic handler only for mercurial request.
Marcin Kuzminski <marcin@python-works.com>
parents: 171
diff changeset
32 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
2668
f0851f37d6be Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2525
diff changeset
33 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \
f0851f37d6be Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2525
diff changeset
34 HTTPBadRequest, HTTPNotAcceptable
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
35
3577
238486bb71ab Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents: 3522
diff changeset
36 from rhodecode.lib.utils2 import safe_str, fix_PATH, get_server_url,\
238486bb71ab Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents: 3522
diff changeset
37 _set_extras
1761
b265be1c6093 Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 1630
diff changeset
38 from rhodecode.lib.base import BaseVCSController
b265be1c6093 Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 1630
diff changeset
39 from rhodecode.lib.auth import get_container_username
b265be1c6093 Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 1630
diff changeset
40 from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections
2716
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
41 from rhodecode.lib.compat import json
3941
3208aaefc9ca Moved all Mercurial imports into hgcompat from vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3823
diff changeset
42 from rhodecode.lib.vcs.utils.hgcompat import RepoError, hgweb_mod
1497
71738535ed78 Removed deprecated usage of UserModel() in simplehg and simplegit
Marcin Kuzminski <marcin@python-works.com>
parents: 1495
diff changeset
43 from rhodecode.model.db import User
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
44 from rhodecode.lib.exceptions import HTTPLockedRC
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
45
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
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
49
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 def is_mercurial(environ):
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
51 """
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
52 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
53 ``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
54 """
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 http_accept = environ.get('HTTP_ACCEPT')
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
56 path_info = environ['PATH_INFO']
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
57 if http_accept and http_accept.startswith('application/mercurial'):
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
58 ishg_path = True
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
59 else:
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
60 ishg_path = False
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
61
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
62 log.debug('pathinfo: %s detected as HG %s' % (
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
63 path_info, ishg_path)
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
64 )
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
65 return ishg_path
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
66
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
67
1761
b265be1c6093 Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 1630
diff changeset
68 class SimpleHg(BaseVCSController):
111
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69
1761
b265be1c6093 Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 1630
diff changeset
70 def _handle_request(self, environ, start_response):
111
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 if not is_mercurial(environ):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 return self.application(environ, start_response)
2668
f0851f37d6be Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2525
diff changeset
73 if not self._check_ssl(environ, start_response):
f0851f37d6be Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2525
diff changeset
74 return HTTPNotAcceptable('SSL REQUIRED !')(environ, start_response)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
75
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 2969
diff changeset
76 ip_addr = self._get_ip_addr(environ)
2673
d5e42c00f3c1 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2668
diff changeset
77 username = None
898
9c4851dce8e6 fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
78 # 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
79 environ['pylons.status_code_redirect'] = True
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
80
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
81 #======================================================================
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
82 # EXTRACT REPOSITORY NAME FROM ENV
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
83 #======================================================================
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
84 try:
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
85 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
86 log.debug('Extracted repo name is %s' % repo_name)
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3625
diff changeset
87 except Exception:
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
88 return HTTPInternalServerError()(environ, start_response)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
89
2122
c137b8a81f8e git+hg middleware do repo verification at earliest possible state, giving 404 as fast as possible. If repo is not found.
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
90 # quick check if that dir exists...
3625
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 3577
diff changeset
91 if not is_valid_repo(repo_name, self.basepath, 'hg'):
2122
c137b8a81f8e git+hg middleware do repo verification at earliest possible state, giving 404 as fast as possible. If repo is not found.
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
92 return HTTPNotFound()(environ, start_response)
c137b8a81f8e git+hg middleware do repo verification at earliest possible state, giving 404 as fast as possible. If repo is not found.
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
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 # 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
96 #======================================================================
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
97 action = self.__get_action(environ)
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
98
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
99 #======================================================================
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 # 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
101 #======================================================================
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
102 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
103 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
104 username = anonymous_user.username
2021
a04844d9c85b better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
105 anonymous_perm = self._check_permission(action, anonymous_user,
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 2969
diff changeset
106 repo_name, ip_addr)
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
107
3625
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 3577
diff changeset
108 if not anonymous_perm or not anonymous_user.active:
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 3577
diff changeset
109 if not anonymous_perm:
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
110 log.debug('Not enough credentials to access this '
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
111 'repository as anonymous user')
3625
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 3577
diff changeset
112 if not anonymous_user.active:
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 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
114 'authentication')
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
115 #==============================================================
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1128
diff changeset
116 # 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
117 # 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
118 #==============================================================
607
ff449e9e6e38 fixed chrome repo switcher issue
Marcin Kuzminski <marcin@python-works.com>
parents: 606
diff changeset
119
1630
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
120 # Attempting to retrieve username from the container
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
121 username = get_container_username(environ, self.config)
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
122
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
123 # If not authenticated by the container, running basic auth
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
124 if not username:
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
125 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
126 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
127 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
128 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
129 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
130 REMOTE_USER.update(environ, result)
1630
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
131 username = result
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
132 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
133 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
134
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
135 #==============================================================
1630
25d8e4836bc2 Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents: 1620
diff changeset
136 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
918
b2d5868cc4b8 fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
137 #==============================================================
2500
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
138 try:
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
139 user = self.__get_user(username)
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
140 if user is None or not user.active:
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
141 return HTTPForbidden()(environ, start_response)
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
142 username = user.username
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3625
diff changeset
143 except Exception:
2500
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
144 log.error(traceback.format_exc())
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
145 return HTTPInternalServerError()(environ, 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
146
2500
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
147 #check permissions for this repository
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 2969
diff changeset
148 perm = self._check_permission(action, user, repo_name, ip_addr)
3625
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 3577
diff changeset
149 if not perm:
2500
94ef0b609d17 possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents: 2203
diff changeset
150 return HTTPForbidden()(environ, start_response)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
151
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
152 # extras are injected into mercurial UI object and later available
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
153 # in hg hooks executed by rhodecode
2857
bad89b2fe618 Pass on RhodeCode config file down to a python-based Hg hook via the extras pseudo-config key, see https://bitbucket.org/marcinkuzminski/rhodecode/issue/558/access-to-rhodecode-config-from-a-hg
Vincent Caron <vcaron@bearstech.com>
parents: 2726
diff changeset
154 from rhodecode import CONFIG
2969
5085e51fba3a Implemented #628: Pass server URL to rc-extensions hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 2869
diff changeset
155 server_url = get_server_url(environ)
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
156 extras = {
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 2969
diff changeset
157 'ip': ip_addr,
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
158 'username': username,
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
159 'action': action,
2203
d9972f76322e added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents: 2184
diff changeset
160 'repository': repo_name,
d9972f76322e added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents: 2184
diff changeset
161 'scm': 'hg',
2857
bad89b2fe618 Pass on RhodeCode config file down to a python-based Hg hook via the extras pseudo-config key, see https://bitbucket.org/marcinkuzminski/rhodecode/issue/558/access-to-rhodecode-config-from-a-hg
Vincent Caron <vcaron@bearstech.com>
parents: 2726
diff changeset
162 'config': CONFIG['__file__'],
2969
5085e51fba3a Implemented #628: Pass server URL to rc-extensions hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 2869
diff changeset
163 'server_url': server_url,
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
164 'make_lock': None,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
165 'locked_by': [None, None]
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2026
diff changeset
166 }
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
167 #======================================================================
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
168 # MERCURIAL REQUEST HANDLING
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
169 #======================================================================
3634
336184b9f4cf fix unicode issues on logging in SCM middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
170 str_repo_name = safe_str(repo_name)
336184b9f4cf fix unicode issues on logging in SCM middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
171 repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
172 log.debug('Repository path is %s' % repo_path)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
173
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
174 # CHECK LOCKING only if it's not ANONYMOUS USER
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
175 if username != User.DEFAULT_USER:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
176 log.debug('Checking locking on repository')
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
177 (make_lock,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
178 locked,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
179 locked_by) = self._check_locking_state(
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
180 environ=environ, action=action,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
181 repo=repo_name, user_id=user.user_id
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
182 )
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
183 # store the make_lock for later evaluation in hooks
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
184 extras.update({'make_lock': make_lock,
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
185 'locked_by': locked_by})
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
186
2869
ccbdff90e5a0 fix for issue #578 git hooks sometimes cannot be executed due to different python they runned under, this commit tries to fix that by altering the PATH env variable using current python that rhodecode is running
Marcin Kuzminski <marcin@python-works.com>
parents: 2857
diff changeset
187 fix_PATH()
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
188 log.debug('HOOKS extras is %s' % extras)
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
189 baseui = make_ui('db')
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
190 self.__inject_extras(repo_path, baseui, extras)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
191
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
192 try:
3135
e7ba69286276 logging: include more info in action logging
Mads Kiilerich <madski@unity3d.com>
parents: 3125
diff changeset
193 log.info('%s action on HG repo "%s" by "%s" from %s' %
3634
336184b9f4cf fix unicode issues on logging in SCM middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
194 (action, str_repo_name, safe_str(username), ip_addr))
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
195 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
196 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
197 except RepoError, e:
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
198 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
199 return HTTPNotFound()(environ, start_response)
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
200 except HTTPLockedRC, e:
3522
7174ee850baa configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
201 _code = CONFIG.get('lock_ret_code')
7174ee850baa configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents: 3278
diff changeset
202 log.debug('Repository LOCKED ret code %s!' % (_code))
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
203 return e(environ, start_response)
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
204 except Exception:
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
205 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
206 return HTTPInternalServerError()(environ, start_response)
3278
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3135
diff changeset
207 finally:
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3135
diff changeset
208 # invalidate cache on push
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3135
diff changeset
209 if action == 'push':
c2bf0fa7b3cb git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents: 3135
diff changeset
210 self._invalidate_cache(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
211
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
212 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
213 """
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
214 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
215 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
216 """
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
217 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
218
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 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
220 """
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
221 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
222
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
223 :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
224 """
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 try:
1813
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1761
diff changeset
226 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO'])
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
227 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
228 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
229 repo_name = repo_name.rstrip('/')
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3625
diff changeset
230 except Exception:
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
231 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
232 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
233
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
234 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
235
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
236 def __get_user(self, username):
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
237 return User.get_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
238
197
da59b7e07e3c Changed import to base. Removed action logging from auth to simplehg.
Marcin Kuzminski <marcin@python-works.com>
parents: 194
diff changeset
239 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
240 """
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
241 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
242 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
243
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
244 :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
245 """
330
4c9a295d80a4 added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents: 317
diff changeset
246 mapping = {'changegroup': 'pull',
4c9a295d80a4 added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents: 317
diff changeset
247 'changegroupsubset': 'pull',
4c9a295d80a4 added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents: 317
diff changeset
248 '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
249 'listkeys': 'pull',
330
4c9a295d80a4 added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents: 317
diff changeset
250 'unbundle': 'push',
4c9a295d80a4 added new command mappings for mercurial 1.6
Marcin Kuzminski <marcin@python-works.com>
parents: 317
diff changeset
251 '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
252 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
253 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
254 cmd = qry.split('=')[-1]
1275
2723276285ae pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
255 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
256 return mapping[cmd]
2501
044c31d67ccc make get_action always return action
Marcin Kuzminski <marcin@python-works.com>
parents: 2500
diff changeset
257
2525
c35980ae7958 Don't always return action, raise an Exception if we cannot check what the action is
Marcin Kuzminski <marcin@python-works.com>
parents: 2501
diff changeset
258 return 'pull'
c35980ae7958 Don't always return action, raise an Exception if we cannot check what the action is
Marcin Kuzminski <marcin@python-works.com>
parents: 2501
diff changeset
259
c35980ae7958 Don't always return action, raise an Exception if we cannot check what the action is
Marcin Kuzminski <marcin@python-works.com>
parents: 2501
diff changeset
260 raise Exception('Unable to detect pull/push action !!'
c35980ae7958 Don't always return action, raise an Exception if we cannot check what the action is
Marcin Kuzminski <marcin@python-works.com>
parents: 2501
diff changeset
261 'Are you using non standard command or client ?')
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
262
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
263 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
264 """
560206522815 fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
265 Injects some extra params into baseui instance
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1813
diff changeset
266
1321
560206522815 fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
267 also overwrites global settings with those takes from local hgrc file
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1813
diff changeset
268
1321
560206522815 fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
269 :param baseui: baseui instance
560206522815 fixed local hgrc settings, patch introduced by Marc Villetard
Marcin Kuzminski <marcin@python-works.com>
parents: 1293
diff changeset
270 :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
271 """
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
272
1495
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
273 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
274
5bd42279930c #176 LookupError: 00changelog.i@66f0739d7517: no node
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
275 # 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
276 baseui.setconfig('ui', 'quiet', 'true')
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 655
diff changeset
277
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
278 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
279
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 111
diff changeset
280 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
281 #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
282 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
283 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
284 baseui.setconfig(section, k, v)
3577
238486bb71ab Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents: 3522
diff changeset
285 _set_extras(extras)