|
@ -1,14 +1,14 @@ |
|
|
"""Corvus Flask Application.""" |
|
|
|
|
|
|
|
|
"""Flask Application.""" |
|
|
import os |
|
|
import os |
|
|
from logging.config import dictConfig |
|
|
from logging.config import dictConfig |
|
|
|
|
|
|
|
|
from flask import Flask |
|
|
from flask import Flask |
|
|
from flask_migrate import Migrate |
|
|
from flask_migrate import Migrate |
|
|
|
|
|
|
|
|
from corvus.db import db |
|
|
|
|
|
from corvus.errors import BaseError, handle_corvus_base_error, \ |
|
|
|
|
|
handle_corvus_404_error |
|
|
|
|
|
from corvus.utility import json_utility, session_utility |
|
|
|
|
|
|
|
|
from server.db import db |
|
|
|
|
|
from server.errors import BaseError, handle_base_error, \ |
|
|
|
|
|
handle_404_error |
|
|
|
|
|
from server.utility import json_utility, session_utility |
|
|
|
|
|
|
|
|
dictConfig({ |
|
|
dictConfig({ |
|
|
'version': 1, |
|
|
'version': 1, |
|
@ -29,18 +29,18 @@ dictConfig({ |
|
|
|
|
|
|
|
|
def create_app(test_config: dict = None) -> Flask: |
|
|
def create_app(test_config: dict = None) -> Flask: |
|
|
""" |
|
|
""" |
|
|
Create an instance of Corvus. |
|
|
|
|
|
|
|
|
Create a server instance. |
|
|
|
|
|
|
|
|
:param test_config: |
|
|
:param test_config: |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
app = Flask(__name__, instance_relative_config=True) |
|
|
app = Flask(__name__, instance_relative_config=True) |
|
|
app.logger.debug('Creating Corvus Server') |
|
|
|
|
|
|
|
|
app.logger.debug('Creating Server') |
|
|
|
|
|
|
|
|
data_directory = os.getenv('CORVUS_DATA_DIRECTORY', '/tmp') |
|
|
|
|
|
app.logger.debug('Corvus Data Directory: %s', data_directory) |
|
|
|
|
|
|
|
|
data_directory = os.getenv('SERVER_DATA_DIRECTORY', '/tmp') |
|
|
|
|
|
app.logger.debug('Server Data Directory: %s', data_directory) |
|
|
|
|
|
|
|
|
default_database_uri = 'sqlite:///{}/corvus.db'.format(data_directory) |
|
|
|
|
|
|
|
|
default_database_uri = 'sqlite:///{}/server.db'.format(data_directory) |
|
|
app.config.from_mapping( |
|
|
app.config.from_mapping( |
|
|
SECRET_KEY='dev', |
|
|
SECRET_KEY='dev', |
|
|
SQLALCHEMY_DATABASE_URI=default_database_uri, |
|
|
SQLALCHEMY_DATABASE_URI=default_database_uri, |
|
@ -50,10 +50,10 @@ def create_app(test_config: dict = None) -> Flask: |
|
|
|
|
|
|
|
|
if test_config is None: |
|
|
if test_config is None: |
|
|
app.logger.debug('Loading configurations') |
|
|
app.logger.debug('Loading configurations') |
|
|
app.config.from_object('corvus.default_settings') |
|
|
|
|
|
|
|
|
app.config.from_object('server.default_settings') |
|
|
app.config.from_pyfile('config.py', silent=True) |
|
|
app.config.from_pyfile('config.py', silent=True) |
|
|
if os.getenv('CORVUS_SETTINGS', None): |
|
|
|
|
|
app.config.from_envvar('CORVUS_SETTINGS') |
|
|
|
|
|
|
|
|
if os.getenv('SERVER_SETTINGS', None): |
|
|
|
|
|
app.config.from_envvar('SERVER_SETTINGS') |
|
|
else: |
|
|
else: |
|
|
app.logger.debug('Loading test configuration') |
|
|
app.logger.debug('Loading test configuration') |
|
|
app.config.from_mapping(test_config) |
|
|
app.config.from_mapping(test_config) |
|
@ -81,7 +81,7 @@ def register_blueprints(app: Flask) -> None: |
|
|
:param app: |
|
|
:param app: |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
from corvus.api import AUTH_BLUEPRINT, USER_BLUEPRINT, HEALTH_BLUEPRINT |
|
|
|
|
|
|
|
|
from server.api import AUTH_BLUEPRINT, USER_BLUEPRINT, HEALTH_BLUEPRINT |
|
|
app.register_blueprint(AUTH_BLUEPRINT) |
|
|
app.register_blueprint(AUTH_BLUEPRINT) |
|
|
app.register_blueprint(USER_BLUEPRINT) |
|
|
app.register_blueprint(USER_BLUEPRINT) |
|
|
app.register_blueprint(HEALTH_BLUEPRINT) |
|
|
app.register_blueprint(HEALTH_BLUEPRINT) |
|
@ -94,15 +94,15 @@ def register_error_handlers(app: Flask) -> None: |
|
|
:param app: |
|
|
:param app: |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
app.register_error_handler(404, handle_corvus_404_error) |
|
|
|
|
|
app.register_error_handler(BaseError, handle_corvus_base_error) |
|
|
|
|
|
|
|
|
app.register_error_handler(404, handle_404_error) |
|
|
|
|
|
app.register_error_handler(BaseError, handle_base_error) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
corvus = create_app() # pylint: disable=C0103 |
|
|
|
|
|
register_blueprints(corvus) |
|
|
|
|
|
register_error_handlers(corvus) |
|
|
|
|
|
|
|
|
server = create_app() # pylint: disable=C0103 |
|
|
|
|
|
register_blueprints(server) |
|
|
|
|
|
register_error_handlers(server) |
|
|
|
|
|
|
|
|
logger = corvus.logger # pylint: disable=C0103 |
|
|
|
|
|
|
|
|
logger = server.logger # pylint: disable=C0103 |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
corvus.run() |
|
|
|
|
|
|
|
|
server.run() |