##// END OF EJS Templates
Changed auth basic handler only for mercurial request.
marcink -
r177:93bd77e1 default
parent child Browse files
Show More
@@ -10,7 +10,6 b' from routes.middleware import RoutesMidd'
10 from paste.auth.basic import AuthBasicHandler
10 from paste.auth.basic import AuthBasicHandler
11 from pylons_app.lib.simplehg import SimpleHg
11 from pylons_app.lib.simplehg import SimpleHg
12 from pylons_app.config.environment import load_environment
12 from pylons_app.config.environment import load_environment
13 from pylons_app.lib.auth import authfunc
14
13
15 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
14 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
16 """Create a Pylons WSGI application and return it
15 """Create a Pylons WSGI application and return it
@@ -45,7 +44,6 b' def make_app(global_conf, full_stack=Tru'
45
44
46 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
45 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
47 app = SimpleHg(app, config)
46 app = SimpleHg(app, config)
48 app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc)
49
47
50 if asbool(full_stack):
48 if asbool(full_stack):
51 # Handle Python exceptions
49 # Handle Python exceptions
@@ -1,19 +1,38 b''
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
4 from pylons_app.lib.utils import make_ui, invalidate_cache
3 from paste.auth.basic import AuthBasicAuthenticator
4 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
5 from pylons.controllers.util import abort
5 from pylons.controllers.util import abort
6 from pylons_app.lib.auth import authfunc
7 from pylons_app.lib.utils import make_ui, invalidate_cache
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:
@@ -50,6 +69,8 b' class SimpleHg(object):'
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 """
General Comments 0
You need to be logged in to leave comments. Login now