Let providers do DB connection setup for web API

This commit is contained in:
Lance Edgar 2023-03-15 09:33:20 -05:00
parent e19adf8907
commit 1ce67953df

View file

@ -32,6 +32,7 @@ from pyramid.authentication import SessionAuthenticationPolicy
from tailbone import app
from tailbone.auth import TailboneAuthorizationPolicy
from tailbone.providers import get_all_providers
def make_rattail_config(settings):
@ -46,6 +47,7 @@ def make_pyramid_config(settings):
"""
Make a Pyramid config object from the given settings.
"""
rattail_config = settings['rattail_config']
pyramid_config = Configurator(settings=settings, root_factory=app.Root)
# configure user authorization / authentication
@ -77,6 +79,13 @@ def make_pyramid_config(settings):
else:
pyramid_config.include('pyramid_retry')
# fetch all tailbone providers
providers = get_all_providers(rattail_config)
for provider in providers.values():
# configure DB sessions associated with transaction manager
provider.configure_db_sessions(rattail_config, pyramid_config)
# add some permissions magic
pyramid_config.add_directive('add_tailbone_permission_group', 'tailbone.auth.add_permission_group')
pyramid_config.add_directive('add_tailbone_permission', 'tailbone.auth.add_permission')