forked from eucalyptus/eucaconsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
29 lines (24 loc) · 1.04 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Pyramid configuration helpers
"""
from pyramid.config import Configurator
from pyramid.authentication import SessionAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from .models import SiteRootFactory
from .models.auth import groupfinder, User
from .routes import urls
def get_configurator(settings, enable_auth=True):
config = Configurator(root_factory=SiteRootFactory, settings=settings)
if enable_auth:
authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.set_default_permission('view')
config.add_request_method(User.get_auth_user, 'user', reify=True)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_layout('koala.layout.MasterLayout', 'koala.layout:templates/master_layout.pt')
for route in urls:
config.add_route(route.name, route.pattern)
config.scan()
return config