def main(global_config, **settings): """ This function returns a WSGI application. """ # Security my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet') whoconfig_file = settings['whoconfig_file'] identifier_id = 'auth_tkt' authn_policy = WhoV2AuthenticationPolicy(whoconfig_file, identifier_id) authz_policy = ACLAuthorizationPolicy() # App config config = Configurator(settings=settings, root_factory=Root, session_factory=my_session_factory, authentication_policy=authn_policy, authorization_policy=authz_policy) config.add_static_view('static', 'max:static') config.add_static_view('css', 'max:css') config.add_static_view('less', 'max:less') config.add_static_view('js', 'max:js') config.add_static_view('fonts', 'max:static/fonts') config.add_static_view('maxui', 'max:maxui') config.add_route('profiles', '/profiles/{username}') config.add_route('wadl', '/WADL') # Store in registry db_uri = settings['mongodb.url'] conn = pymongo.Connection(db_uri) db = conn[settings['mongodb.db_name']] config.registry.max_store = db # Set MAX settings config.registry.max_settings = loadMAXSettings(settings, config) # REST Resources # Configure routes based on resources defined in RESOURCES for name, properties in RESOURCES.items(): config.add_route(name, properties.get('route')) config.scan('max', ignore='max.tests') return config.make_wsgi_app()
return JSONHTTPBadRequest(error=dict(error=ObjectNotFound.__name__, error_description=message.value)) except MissingField, message: return JSONHTTPBadRequest(error=dict(error=MissingField.__name__, error_description=message.value)) except DuplicatedItemError, message: return JSONHTTPBadRequest(error=dict(error=DuplicatedItemError.__name__, error_description=message.value)) except UnknownUserError, message: return JSONHTTPBadRequest(error=dict(error=UnknownUserError.__name__, error_description=message.value)) except Unauthorized, message: return JSONHTTPUnauthorized(error=dict(error=Unauthorized.__name__, error_description=message.value)) except InvalidSearchParams, message: return JSONHTTPBadRequest(error=dict(error=InvalidSearchParams.__name__, error_description=message.value)) except InvalidPermission, message: return JSONHTTPBadRequest(error=dict(error=InvalidPermission.__name__, error_description=message.value)) except ValidationError, message: return JSONHTTPBadRequest(error=dict(error=ValidationError.__name__, error_description=message.value)) # JSON decode error???? except ValueError: return JSONHTTPBadRequest(error=dict(error='JSONDecodeError', error_description='Invalid JSON data found on requests body')) except: return HTTPInternalServerError() else: try: # Don't cache by default, get configuration from resource if any route_cache_settings = RESOURCES.get(request.matched_route.name).get('cache', 'must-revalidate, max-age=0, no-cache, no-store') response.headers.update({'Cache-Control': route_cache_settings}) except: pass return response return replacement
except InvalidPermission, message: return JSONHTTPBadRequest( error=dict(error=InvalidPermission.__name__, error_description=message.value)) except ValidationError, message: return JSONHTTPBadRequest( error=dict(error=ValidationError.__name__, error_description=message.value)) # JSON decode error???? except ValueError: return JSONHTTPBadRequest(error=dict( error='JSONDecodeError', error_description='Invalid JSON data found on requests body')) except: return HTTPInternalServerError() else: try: # Don't cache by default, get configuration from resource if any route_cache_settings = RESOURCES.get( request.matched_route.name).get( 'cache', 'must-revalidate, max-age=0, no-cache, no-store') response.headers.update( {'Cache-Control': route_cache_settings}) except: pass return response return replacement