rpc api context
Change-Id: Ic3316d42015ac0e581ed49e44a3bad1b3cc7ff66
This commit is contained in:
parent
5a73c9d575
commit
9d6d492c8c
@ -42,7 +42,8 @@ def setup_app(pecan_config=PECAN_CONFIG, conf=None):
|
||||
raise RuntimeError('Config is actually mandatory')
|
||||
app_hooks = [hooks.ConfigHook(conf),
|
||||
hooks.TranslationHook(),
|
||||
hooks.RPCHook(conf)]
|
||||
hooks.RPCHook(conf),
|
||||
hooks.ContextHook()]
|
||||
|
||||
pecan.configuration.set_config(dict(pecan_config), overwrite=True)
|
||||
pecan_debug = conf.api.pecan_debug
|
||||
|
@ -53,7 +53,8 @@ class AlarmsController(RootRestController):
|
||||
|
||||
@staticmethod
|
||||
def get_alarms(vitrage_id=None):
|
||||
alarms_json = pecan.request.client.call({}, 'get_alarms',
|
||||
alarms_json = pecan.request.client.call(pecan.request.context,
|
||||
'get_alarms',
|
||||
arg=vitrage_id)
|
||||
LOG.info(alarms_json)
|
||||
|
||||
|
@ -44,7 +44,7 @@ class RCAController(RootRestController):
|
||||
@staticmethod
|
||||
def get_rca(alarm_id):
|
||||
try:
|
||||
graph_data = pecan.request.client.call({},
|
||||
graph_data = pecan.request.client.call(pecan.request.context,
|
||||
'get_rca',
|
||||
root=alarm_id)
|
||||
LOG.info(graph_data)
|
||||
|
@ -55,7 +55,8 @@ class TopologyController(RootRestController):
|
||||
def get_graph(graph_type, depth, query, root):
|
||||
|
||||
try:
|
||||
graph_data = pecan.request.client.call({}, 'get_topology',
|
||||
graph_data = pecan.request.client.call(pecan.request.context,
|
||||
'get_topology',
|
||||
graph_type=graph_type,
|
||||
depth=depth,
|
||||
query=query, root=root)
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
import oslo_messaging
|
||||
|
||||
from oslo_context import context
|
||||
from oslo_policy import policy
|
||||
from pecan import hooks
|
||||
|
||||
@ -26,7 +27,6 @@ class ConfigHook(hooks.PecanHook):
|
||||
self.enforcer = policy.Enforcer(conf)
|
||||
|
||||
def before(self, state):
|
||||
# TODO(dany) add Context
|
||||
state.request.cfg = self.conf
|
||||
state.request.enforcer = self.enforcer
|
||||
|
||||
@ -38,7 +38,6 @@ class RPCHook(hooks.PecanHook):
|
||||
transport = oslo_messaging.get_transport(conf)
|
||||
target = oslo_messaging.Target(topic=conf.rpc_topic)
|
||||
self.client = vitrage_rpc.get_client(transport, target)
|
||||
self.ctxt = {}
|
||||
|
||||
def before(self, state):
|
||||
state.request.client = self.client
|
||||
@ -54,3 +53,23 @@ class TranslationHook(hooks.PecanHook):
|
||||
if hasattr(state.response, 'translatable_error'):
|
||||
state.request.environ['translatable_error'] = (
|
||||
state.response.translatable_error)
|
||||
|
||||
|
||||
class ContextHook(hooks.PecanHook):
|
||||
|
||||
def before(self, state):
|
||||
user_id = state.request.headers.get('X-User-Id')
|
||||
user_id = state.request.headers.get('X-User', user_id)
|
||||
user_name = state.request.headers.get('X-User-Name', '')
|
||||
tenant_id = state.request.headers.get('X-Project-Id')
|
||||
auth_token = state.request.headers.get('X-Auth-Token')
|
||||
# TODO(DANY) use roles
|
||||
# roles = pecan.request.headers.get('X-Roles', '').split(',')
|
||||
# roles = [r.strip() for r in roles]
|
||||
ctx = context.RequestContext(auth_token=auth_token, user=user_id,
|
||||
# roles=roles,
|
||||
tenant=tenant_id,
|
||||
is_admin=(user_name == 'admin'))
|
||||
|
||||
# Inject the context...
|
||||
state.request.context = ctx.to_dict()
|
||||
|
Loading…
x
Reference in New Issue
Block a user