Beispiel #1
0
def setup_app(pecan_config=None, extra_hooks=None):
    app_hooks = [
        hooks.ConfigHook(),
        hooks.DBHook(),
        hooks.ContextHook(pecan_config.app.acl_public_routes),
        hooks.RPCHook(),
        hooks.NoExceptionTracebackHook()
    ]
    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(hooks.TrustedCallHook())

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

    app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        debug=CONF.debug,
        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, pecan_config.app.acl_public_routes)

    return app
Beispiel #2
0
 def test_trusted_call_hook_public_api(self):
     headers = fake_headers(admin=False)
     env = {'is_public_api': True}
     reqstate = FakeRequestState(headers=headers, environ=env)
     reqstate.set_context()
     trusted_call_hook = hooks.TrustedCallHook()
     trusted_call_hook.before(reqstate)
Beispiel #3
0
 def test_trusted_call_hook_not_admin(self):
     headers = fake_headers(admin=False)
     reqstate = FakeRequestState(headers=headers)
     reqstate.set_context()
     trusted_call_hook = hooks.TrustedCallHook()
     self.assertRaises(webob_exc.HTTPForbidden,
                       trusted_call_hook.before, reqstate)
Beispiel #4
0
def setup_app(pecan_config=None, extra_hooks=None):
    app_hooks = [
        hooks.ConfigHook(),
        hooks.DBHook(),
        hooks.ContextHook(pecan_config.app.acl_public_routes),
        hooks.RPCHook(),
        hooks.NoExceptionTracebackHook(),
        hooks.PublicUrlHook()
    ]
    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(hooks.TrustedCallHook())

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

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

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

    # Create a CORS wrapper, and attach ironic-specific defaults that must be
    # included in all CORS responses.
    app = cors_middleware.CORS(app, CONF)
    app.set_latent(
        allow_headers=[Version.max_string, Version.min_string, Version.string],
        allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
        expose_headers=[
            Version.max_string, Version.min_string, Version.string
        ])

    # Insert the proxy support middleware to generate decent application links.
    app = proxy_middleware.HTTPProxyToWSGI(app, CONF)

    return app
Beispiel #5
0
 def test_trusted_call_hook_admin(self):
     headers = fake_headers(admin=True)
     reqstate = FakeRequestState(headers=headers)
     reqstate.set_context()
     trusted_call_hook = hooks.TrustedCallHook()
     trusted_call_hook.before(reqstate)