Exemple #1
0
def setup_app(config=None):
    opts = cfg.CONF.api_pecan

    LOG.info(VERSION_STRING)
    LOG.info('Creating %s as Pecan app.' % __name__)

    if not config:
        config = __get_pecan_config()

    app_conf = dict(config.app)

    active_hooks = [hooks.JSONErrorResponseHook()]

    if cfg.CONF.auth.enable:
        active_hooks.append(hooks.AuthHook())

    active_hooks.append(hooks.CorsHook())

    app = pecan.make_app(app_conf.pop('root'),
                         logging=getattr(config, 'logging', {}),
                         hooks=active_hooks,
                         **app_conf)

    # Static middleware which servers common static assets such as logos
    static_root = os.path.join(BASE_DIR, 'public')
    app = StaticFileMiddleware(app=app, directory=static_root)

    if cfg.CONF.api.serve_webui_files:
        # Static middleware which serves webui files
        LOG.info('Serving WebUi at /webui/index.html')
        app = StaticFileMiddleware(app=app, directory=opts.static_root)

    LOG.info('%s app created.' % __name__)

    return app
Exemple #2
0
def setup_app(config):

    model.init_model()
    app_conf = dict(config.app)

    app = make_app(
        app_conf.pop('root'),
        logging=getattr(config, 'logging', {}),
        **app_conf
    )
    return StaticFileMiddleware(app, app_conf.get('static_root'))
Exemple #3
0
def setup_app(config=None):
    LOG.info('Creating st2api: %s as Pecan app.', VERSION_STRING)

    is_gunicorn = getattr(config, 'is_gunicorn', False)
    if is_gunicorn:
        # Note: We need to perform monkey patching in the worker. If we do it in
        # the master process (gunicorn_config.py), it breaks tons of things
        # including shutdown
        monkey_patch()

        st2api_config.register_opts()
        # This should be called in gunicorn case because we only want
        # workers to connect to db, rabbbitmq etc. In standalone HTTP
        # server case, this setup would have already occurred.
        common_setup(service='api',
                     config=st2api_config,
                     setup_db=True,
                     register_mq_exchanges=True,
                     register_signal_handlers=True,
                     register_internal_trigger_types=True,
                     run_migrations=True,
                     config_args=config.config_args)

    if not config:
        # standalone HTTP server case
        config = _get_pecan_config()
    else:
        # gunicorn case
        if is_gunicorn:
            config.app = _get_pecan_config().app

    app_conf = dict(config.app)

    active_hooks = [
        hooks.RequestIDHook(),
        hooks.JSONErrorResponseHook(),
        hooks.LoggingHook()
    ]

    active_hooks.append(hooks.AuthHook())
    active_hooks.append(hooks.CorsHook())

    app = pecan.make_app(app_conf.pop('root'),
                         logging=getattr(config, 'logging', {}),
                         hooks=active_hooks,
                         **app_conf)

    # Static middleware which servers common static assets such as logos
    static_root = os.path.join(BASE_DIR, 'public')
    app = StaticFileMiddleware(app=app, directory=static_root)

    LOG.info('%s app created.' % __name__)

    return app
    def setUp(self):
        super(TestStaticFileMiddleware, self).setUp()

        def app(environ, start_response):
            response_headers = [('Content-type', 'text/plain')]
            start_response('200 OK', response_headers)
            return ['Hello world!\n']

        self.app = StaticFileMiddleware(
            app, os.path.dirname(__file__)
        )

        self._status = None
        self._response_headers = None