-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhooks.py
More file actions
42 lines (30 loc) · 1.15 KB
/
hooks.py
File metadata and controls
42 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pecan import hooks
from oslo.config import cfg
from billingstack import storage
from billingstack.central.rpcapi import CentralAPI
from billingstack.openstack.common import log
from billingstack.openstack.common.context import RequestContext
class NoAuthHook(hooks.PecanHook):
"""
Simple auth - all requests will be is_admin=True
"""
def before(self, state):
state.request.ctxt = RequestContext(is_admin=True)
class ConfigHook(hooks.PecanHook):
"""Attach the configuration object to the request
so controllers can get to it.
"""
def before(self, state):
state.request.cfg = cfg.CONF
class DBHook(hooks.PecanHook):
def before(self, state):
storage_engine = storage.get_engine(
state.request.cfg['service:api'].storage_driver)
state.request.storage_engine = storage_engine
state.request.storage_conn = storage_engine.get_connection()
# def after(self, state):
# print 'method:', state.request.method
# print 'response:', state.response.status
class RPCHook(hooks.PecanHook):
def before(self, state):
state.request.central_api = CentralAPI()