Ejemplo n.º 1
0
    def __init__(self, config: QueueWorkerConfig, handle_payloads: Sequence[Type[Payload]]):
        worker_name = environ.get('WORKER_NAME', None)
        if worker_name is None:
            raise RuntimeError('Environment variable WORKER_NAME needs to be set')
        self.worker_name = worker_name
        self.config = config
        self.payloads = handle_payloads
        self.db: AsyncQueueDB

        init_logging(config=config)
        logger.info(f'Starting {self.config.app_name}: {self.worker_name}...')
Ejemplo n.º 2
0
def eduid_init_app_no_db(name, config, app_class=AuthnApp):
    """
    Create and prepare the flask app for eduID APIs with all the attributes
    common to all  apps.

     * Parse and merge configurations
     * Add logging
     * Add db connection
     * Add eduID session

    :param name: The name of the instance, it will affect the configuration file
                 loaded from the filesystem.
    :type name: str
    :param config: any additional configuration settings. Specially useful
                   in test cases
    :type config: dict
    :param app_class: The class used to build the flask app. Should be a
                      descendant of flask.Flask
    :type app_class: type

    :return: the flask application.
    :rtype: flask.Flask
    """
    app = app_class(name)
    app.wsgi_app = ProxyFix(app.wsgi_app)
    app.request_class = Request

    # Init etcd config parsers
    common_parser = EtcdConfigParser('/eduid/webapp/common/')
    app_parser = EtcdConfigParser('/eduid/webapp/{!s}/'.format(name))

    # Load project wide default settings
    app.config.from_object('eduid_webapp.settings.common')

    try:
        # Load optional app specific default settings
        app.config.from_object(
            'eduid_webapp.{!s}.settings.common'.format(name))
    except ImportError:  # No app specific default config found
        pass

    # Load optional project wide settings
    app.config.update(common_parser.read_configuration(silent=True))
    # Load optional app specific settings
    app.config.update(app_parser.read_configuration(silent=True))

    # Load optional init time settings
    app.config.update(config)

    # Initialize shared features
    app = init_logging(app)
    app = init_exception_handlers(app)
    app = init_sentry(app)
    app.session_interface = SessionFactory(app.config)

    return app
Ejemplo n.º 3
0
def eduid_init_app_no_db(name, config, app_class=AuthnApp):
    """
    Create and prepare the flask app for eduID APIs with all the attributes
    common to all  apps.

     * Parse and merge configurations
     * Add logging
     * Add db connection
     * Add eduID session

    :param name: The name of the instance, it will affect the configuration file
                 loaded from the filesystem.
    :type name: str
    :param config: any additional configuration settings. Specially useful
                   in test cases
    :type config: dict
    :param app_class: The class used to build the flask app. Should be a
                      descendant of flask.Flask
    :type app_class: type

    :return: the flask application.
    :rtype: flask.Flask
    """
    app = app_class(name)
    app.wsgi_app = ProxyFix(app.wsgi_app)
    app.request_class = Request

    # Init etcd config parsers
    common_parser = EtcdConfigParser('/eduid/webapp/common/')
    app_parser = EtcdConfigParser('/eduid/webapp/{!s}/'.format(name))

    # Load project wide default settings
    app.config.from_object('eduid_webapp.settings.common')

    try:
        # Load optional app specific default settings
        app.config.from_object('eduid_webapp.{!s}.settings.common'.format(name))
    except ImportError:  # No app specific default config found
        pass

    # Load optional project wide settings
    app.config.update(common_parser.read_configuration(silent=True))
    # Load optional app specific settings
    app.config.update(app_parser.read_configuration(silent=True))

    # Load optional init time settings
    app.config.update(config)

    # Initialize shared features
    app = init_logging(app)
    app = init_exception_handlers(app)
    app = init_sentry(app)
    app.session_interface = SessionFactory(app.config)

    return app
Ejemplo n.º 4
0
def init_idproofing_letter_app(name, config=None):
    """
    :param name: The name of the instance, it will affect the configuration loaded.
    :param config: any additional configuration settings. Specially useful
                   in test cases

    :type name: str
    :type config: dict

    :return: the flask app
    :rtype: flask.Flask
    """
    app = Flask(name, static_folder=None)

    # Load configuration
    app.config.from_object('idproofing_letter.settings.common')
    app.config.from_envvar('IDPROOFING_LETTER_SETTINGS', silent=True)
    if config:
        app.config.update(config)

    # Setup logging
    app = init_logging(app)

    # Setup exception handling
    app = init_exception_handlers(app)

    # Register views
    from idproofing_letter.views import idproofing_letter_views
    app.register_blueprint(idproofing_letter_views)

    # Init dbs
    app.central_userdb = UserDB(app.config['MONGO_URI'], 'eduid_am')
    app.proofing_statedb = LetterProofingStateDB(app.config['MONGO_URI'])

    # Init celery
    init_celery(app)

    # Initiate external modules
    app.ekopost = Ekopost(app)

    # Check for secret key
    if app.config['SECRET_KEY'] is None:
        app.logger.error('Missing SECRET_KEY in the settings file')

    app.logger.info('Application initialized')
    return app
Ejemplo n.º 5
0
def init_idproofing_letter_app(name, config=None):
    """
    :param name: The name of the instance, it will affect the configuration loaded.
    :param config: any additional configuration settings. Specially useful
                   in test cases

    :type name: str
    :type config: dict

    :return: the flask app
    :rtype: flask.Flask
    """
    app = Flask(name, static_folder=None)

    # Load configuration
    app.config.from_object('idproofing_letter.settings.common')
    app.config.from_envvar('IDPROOFING_LETTER_SETTINGS', silent=True)
    if config:
        app.config.update(config)

    # Setup logging
    app = init_logging(app)

    # Setup exception handling
    app = init_exception_handlers(app)

    # Register views
    from idproofing_letter.views import idproofing_letter_views
    app.register_blueprint(idproofing_letter_views)

    # Init dbs
    app.central_userdb = UserDB(app.config['MONGO_URI'], 'eduid_am')
    app.proofing_statedb = LetterProofingStateDB(app.config['MONGO_URI'])

    # Init celery
    init_celery(app)

    # Initiate external modules
    app.ekopost = Ekopost(app)

    # Check for secret key
    if app.config['SECRET_KEY'] is None:
        app.logger.error('Missing SECRET_KEY in the settings file')

    app.logger.info('Application initialized')
    return app