Пример #1
0
def make_app(conf, enable_acl=True, attach_storage=True):
    app = flask.Flask('ceilometer.api')
    app.register_blueprint(v1_blueprint.blueprint, url_prefix='/v1')

    try:
        with open("sources.json", "r") as f:
            sources = jsonutils.load(f)
    except IOError:
        sources = {}

    @app.before_request
    def attach_config():
        flask.request.cfg = conf
        flask.request.sources = sources

    if attach_storage:
        @app.before_request
        def attach_storage():
            storage_engine = storage.get_engine(conf)
            flask.request.storage_engine = storage_engine
            flask.request.storage_conn = \
                storage_engine.get_connection(conf)

    # Install the middleware wrapper
    if enable_acl:
        app.wsgi_app = acl.install(app.wsgi_app, conf)

    return app
Пример #2
0
def setup_app(pecan_config=None, extra_hooks=None):
    storage_engine = storage.get_engine(cfg.CONF)
    # FIXME: Replace DBHook with a hooks.TransactionHook
    app_hooks = [hooks.ConfigHook(),
                 hooks.DBHook(
                     storage_engine,
                     storage_engine.get_connection(cfg.CONF),
                 ),
                 hooks.PipelineHook(),
                 hooks.TranslationHook()]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    if not pecan_config:
        pecan_config = get_pecan_config()

    pecan.configuration.set_config(dict(pecan_config), overwrite=True)

    app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        template_path=pecan_config.app.template_path,
        debug=CONF.debug,
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
        guess_content_type_from_ext=False
    )

    if pecan_config.app.enable_acl:
        return acl.install(app, cfg.CONF)

    return app
Пример #3
0
def setup_app(pecan_config=None, extra_hooks=None):
    # FIXME: Replace DBHook with a hooks.TransactionHook
    app_hooks = [hooks.ConfigHook(),
                 hooks.DBHook()]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    if not pecan_config:
        pecan_config = get_pecan_config()

    if pecan_config.app.enable_acl:
        app_hooks.append(acl.AdminAuthHook())

    configuration.set_config(dict(pecan_config), overwrite=True)

    app = make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        template_path=pecan_config.app.template_path,
        logging=getattr(pecan_config, 'logging', {}),
        debug=getattr(pecan_config.app, 'debug', False),
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
    )

    if pecan_config.app.enable_acl:
        return acl.install(app, cfg.CONF)

    return app
Пример #4
0
def setup_app(pecan_config=None, extra_hooks=None):
    # FIXME: Replace DBHook with a hooks.TransactionHook
    app_hooks = [
        hooks.ConfigHook(),
        hooks.DBHook(storage.get_connection(cfg.CONF), ),
        hooks.PipelineHook(),
        hooks.TranslationHook()
    ]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    if not pecan_config:
        pecan_config = get_pecan_config()

    pecan.configuration.set_config(dict(pecan_config), overwrite=True)

    app = pecan.make_app(pecan_config.app.root,
                         static_root=pecan_config.app.static_root,
                         template_path=pecan_config.app.template_path,
                         debug=CONF.debug,
                         force_canonical=getattr(pecan_config.app,
                                                 'force_canonical', True),
                         hooks=app_hooks,
                         wrap_app=middleware.ParsableErrorMiddleware,
                         guess_content_type_from_ext=False)

    if getattr(pecan_config.app, 'enable_acl', True):
        return acl.install(app, cfg.CONF)

    return app
Пример #5
0
def make_app(conf,
             enable_acl=True,
             attach_storage=True,
             sources_file='sources.json'):
    app = flask.Flask('ceilometer.api')
    app.register_blueprint(v1_blueprint.blueprint, url_prefix='/v1')

    app.json_encoder = JSONEncoder

    try:
        with open(sources_file, "r") as f:
            sources = jsonutils.load(f)
    except IOError:
        sources = {}

    @app.before_request
    def attach_config():
        flask.request.cfg = conf
        flask.request.sources = sources

    if attach_storage:

        @app.before_request
        def attach_storage():
            storage_engine = storage.get_engine(conf)
            flask.request.storage_engine = storage_engine
            flask.request.storage_conn = \
                storage_engine.get_connection(conf)

    # Install the middleware wrapper
    if enable_acl:
        app.wsgi_app = acl.install(app.wsgi_app, conf)

    return app
Пример #6
0
def setup_app(pecan_config=None, extra_hooks=None):
    # FIXME: Replace DBHook with a hooks.TransactionHook
    app_hooks = [hooks.ConfigHook(),
                 hooks.DBHook()]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    if not pecan_config:
        pecan_config = get_pecan_config()

    if pecan_config.app.enable_acl:
        app_hooks.append(acl.AdminAuthHook())

    pecan.configuration.set_config(dict(pecan_config), overwrite=True)

    app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        template_path=pecan_config.app.template_path,
        logging=getattr(pecan_config, 'logging', {}),
        debug=getattr(pecan_config.app, 'debug', False),
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
    )

    if pecan_config.app.enable_acl:
        return acl.install(app, cfg.CONF)

    return app
Пример #7
0
    def _make_app(self):
        # Save the original app constructor so
        # we can use it in our wrapper
        original_setup_app = app.setup_app

        # Wrap application construction with
        # a function that ensures the AdminAuthHook
        # is provided.
        def setup_app(config, extra_hooks=[]):
            extra_hooks = extra_hooks[:]
            extra_hooks.append(acl.AdminAuthHook())
            return original_setup_app(config, extra_hooks)

        self.stubs.Set(app, 'setup_app', setup_app)
        result = super(TestAPIACL, self)._make_app()
        acl.install(result, cfg.CONF)
        return result
Пример #8
0
import flask

from ceilometer.openstack.common import cfg
from ceilometer.openstack.common import jsonutils
from ceilometer import storage
from ceilometer.api import v1
from ceilometer.api import acl


app = flask.Flask('ceilometer.api')
app.register_blueprint(v1.blueprint, url_prefix='/v1')

storage.register_opts(cfg.CONF)


@app.before_request
def attach_config():
    flask.request.cfg = cfg.CONF
    storage_engine = storage.get_engine(cfg.CONF)
    flask.request.storage_engine = storage_engine
    flask.request.storage_conn = storage_engine.get_connection(cfg.CONF)


@app.before_request
def attach_sources():
    with open("sources.json", "r") as f:
        flask.request.sources = jsonutils.load(f)


acl.install(app)
Пример #9
0
 def setUp(self):
     super(TestAPIACL, self).setUp()
     acl.install(self.app, {})