Mercurial > public > src > rhodecode
comparison pylons_app/lib/simplehg.py @ 177:93bd77e1f3c1
Changed auth basic handler only for mercurial request.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 21 May 2010 20:50:03 +0200 |
parents | 52bbeb1e813f |
children | 24dbf4bc57aa |
comparison
equal
deleted
inserted
replaced
176:8dd7305fbc2d | 177:93bd77e1f3c1 |
---|---|
1 import os | |
2 from mercurial.hgweb import hgweb | 1 from mercurial.hgweb import hgweb |
3 from mercurial.hgweb.request import wsgiapplication | 2 from mercurial.hgweb.request import wsgiapplication |
3 from paste.auth.basic import AuthBasicAuthenticator | |
4 from paste.httpheaders import REMOTE_USER, AUTH_TYPE | |
5 from pylons.controllers.util import abort | |
6 from pylons_app.lib.auth import authfunc | |
4 from pylons_app.lib.utils import make_ui, invalidate_cache | 7 from pylons_app.lib.utils import make_ui, invalidate_cache |
5 from pylons.controllers.util import abort | |
6 from webob.exc import HTTPNotFound | 8 from webob.exc import HTTPNotFound |
9 import os | |
10 | |
7 class SimpleHg(object): | 11 class SimpleHg(object): |
8 | 12 |
9 def __init__(self, application, config): | 13 def __init__(self, application, config): |
10 self.application = application | 14 self.application = application |
11 self.config = config | 15 self.config = config |
16 #authenticate this mercurial request using | |
17 realm = '%s %s' % (config['repos_name'], 'mercurial repository') | |
18 self.authenticate = AuthBasicAuthenticator(realm, authfunc) | |
12 | 19 |
13 def __call__(self, environ, start_response): | 20 def __call__(self, environ, start_response): |
14 if not is_mercurial(environ): | 21 if not is_mercurial(environ): |
15 return self.application(environ, start_response) | 22 return self.application(environ, start_response) |
16 else: | 23 else: |
24 #=================================================================== | |
25 # AUTHENTICATE THIS MERCURIAL REQUEST | |
26 #=================================================================== | |
27 username = REMOTE_USER(environ) | |
28 if not username: | |
29 result = self.authenticate(environ) | |
30 if isinstance(result, str): | |
31 AUTH_TYPE.update(environ, 'basic') | |
32 REMOTE_USER.update(environ, result) | |
33 else: | |
34 return result.wsgi_application(environ, start_response) | |
35 | |
17 try: | 36 try: |
18 repo_name = environ['PATH_INFO'].split('/')[1] | 37 repo_name = environ['PATH_INFO'].split('/')[1] |
19 except: | 38 except: |
20 return HTTPNotFound()(environ, start_response) | 39 return HTTPNotFound()(environ, start_response) |
21 | 40 |
48 if repoui: | 67 if repoui: |
49 #set the repository based config | 68 #set the repository based config |
50 hgserve.repo.ui = repoui | 69 hgserve.repo.ui = repoui |
51 | 70 |
52 return hgserve | 71 return hgserve |
72 | |
73 | |
53 | 74 |
54 def is_mercurial(environ): | 75 def is_mercurial(environ): |
55 """ | 76 """ |
56 Returns True if request's target is mercurial server - header | 77 Returns True if request's target is mercurial server - header |
57 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. | 78 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. |