Encapsulate required app config on Devicehub

This commit is contained in:
Santiago L 2021-12-28 12:32:38 +01:00
parent 338afcc556
commit c226844a43
2 changed files with 20 additions and 0 deletions

View File

@ -35,6 +35,7 @@ class DevicehubConfig(Config):
import_resource(metric_def), import_resource(metric_def),
),) ),)
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str] PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
SECRET_KEY = config('SECRET_KEY')
DB_USER = config('DB_USER', 'dhub') DB_USER = config('DB_USER', 'dhub')
DB_PASSWORD = config('DB_PASSWORD', 'ereuse') DB_PASSWORD = config('DB_PASSWORD', 'ereuse')
DB_HOST = config('DB_HOST', 'localhost') DB_HOST = config('DB_HOST', 'localhost')

View File

@ -22,6 +22,11 @@ from ereuse_devicehub.resources.inventory import Inventory, InventoryDef
from ereuse_devicehub.templating import Environment from ereuse_devicehub.templating import Environment
from flask_login import LoginManager
from flask_wtf.csrf import CSRFProtect
from ereuse_devicehub.resources.user.models import User
class Devicehub(Teal): class Devicehub(Teal):
test_client_class = Client test_client_class = Client
Dummy = Dummy Dummy = Dummy
@ -61,6 +66,20 @@ class Devicehub(Teal):
inv.command('search')(self.regenerate_search) inv.command('search')(self.regenerate_search)
self.before_request(self._prepare_request) self.before_request(self._prepare_request)
self.configure_extensions()
def configure_extensions(self):
# configure & enable CSRF of Flask-WTF
CSRFProtect(self)
# configure Flask-Login
login_manager = LoginManager()
login_manager.init_app(self)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(user_id)
# noinspection PyMethodOverriding # noinspection PyMethodOverriding
@click.option('--name', '-n', @click.option('--name', '-n',
default='Test 1', default='Test 1',