Example #1
0
def create_app(config: dict = None):
    app = Flask(__name__, static_url_path='', instance_relative_config=True)

    if config:
        app.config.update(config)
    else:
        app.config.from_envvar("CMSERVICE_CONFIG")

    mako = MakoTemplates()
    mako.init_app(app)
    app._mako_lookup = TemplateLookup(directories=[pkg_resources.resource_filename('cmservice.service', 'templates')],
                                      input_encoding='utf-8', output_encoding='utf-8',
                                      imports=['from flask_babel import gettext as _'])

    app.cm = init_consent_manager(app)

    babel = Babel(app)
    babel.localeselector(get_locale)
    app.config['BABEL_TRANSLATION_DIRECTORIES'] = pkg_resources.resource_filename('cmservice.service',
                                                                                  'data/i18n/locales')

    from .views import consent_views
    app.register_blueprint(consent_views)

    setup_logging(app.config.get('LOGGING_LEVEL', 'INFO'))

    logger = logging.getLogger(__name__)
    logger.info("Running CMservice version %s", pkg_resources.get_distribution("CMservice").version)
    return app
if __name__ == "__main__":
    import ssl

    app.config.from_pyfile("settings.cfg")
    LOGGER = logging.getLogger("alservice")
    hdlr = logging.FileHandler(app.config["LOG_FILE"])
    base_formatter = logging.Formatter("[%(asctime)-19.19s] [%(levelname)-5.5s]: %(message)s")
    hdlr.setLevel(app.config["LOG_LEVEL"])
    hdlr.setFormatter(base_formatter)
    LOGGER.addHandler(hdlr)
    LOGGER.setLevel(logging.DEBUG)
    mako = MakoTemplates()
    mako.init_app(app)
    app._mako_lookup = TemplateLookup(directories=["templates"],
                                      input_encoding='utf-8', output_encoding='utf-8',
                                      imports=["from flask.ext.babel import gettext as _"])
    context = None
    if app.config['SSL']:
        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        context.load_cert_chain(app.config["SERVER_CERT"], app.config["SERVER_KEY"])
    global keys
    global stat_service
    global base
    keys = []
    for key in app.config["JWT_PUB_KEY"]:
        _bkey = rsa_load(key)
        pub_key = RSAKey().load_key(_bkey)
        keys.append(pub_key)
    # salt = app.config["SALT"]