rename tenant to project_id

was changed in oslo.context > 4.0.0

Change-Id: I3327f5743d47d83441f4a6607d762043ce753e8e
This commit is contained in:
Eyal 2022-03-14 19:46:43 +02:00
parent 43091cd457
commit a3a84cb4d4
8 changed files with 44 additions and 44 deletions

View File

@ -80,14 +80,14 @@ class ContextHook(hooks.PecanHook):
user_id = state.request.headers.get('X-User-Id') user_id = state.request.headers.get('X-User-Id')
user_id = state.request.headers.get('X-User', user_id) user_id = state.request.headers.get('X-User', user_id)
user_name = state.request.headers.get('X-User-Name', '') user_name = state.request.headers.get('X-User-Name', '')
tenant_id = state.request.headers.get('X-Project-Id') project_id = state.request.headers.get('X-Project-Id')
auth_token = state.request.headers.get('X-Auth-Token') auth_token = state.request.headers.get('X-Auth-Token')
# TODO(DANY) use roles # TODO(DANY) use roles
# roles = pecan.request.headers.get('X-Roles', '').split(',') # roles = pecan.request.headers.get('X-Roles', '').split(',')
# roles = [r.strip() for r in roles] # roles = [r.strip() for r in roles]
ctx = context.RequestContext(auth_token=auth_token, user=user_id, ctx = context.RequestContext(auth_token=auth_token, user=user_id,
# roles=roles, # roles=roles,
tenant=tenant_id, project_id=project_id,
is_admin=(user_name == 'admin')) is_admin=(user_name == 'admin'))
# Inject the context... # Inject the context...

View File

@ -43,7 +43,7 @@ class AlarmApis(base.EntityGraphApisBase):
if not vitrage_id or vitrage_id == 'all': if not vitrage_id or vitrage_id == 'all':
if not all_tenants: if not all_tenants:
kwargs['project_id'] = \ kwargs['project_id'] = \
ctx.get(TenantProps.TENANT, 'no-project') ctx.get(TenantProps.PROJECT_ID, 'no-project')
kwargs['is_admin_project'] = \ kwargs['is_admin_project'] = \
ctx.get(TenantProps.IS_ADMIN, False) ctx.get(TenantProps.IS_ADMIN, False)
else: else:
@ -65,7 +65,7 @@ class AlarmApis(base.EntityGraphApisBase):
return None return None
is_admin = ctx.get(TenantProps.IS_ADMIN, False) is_admin = ctx.get(TenantProps.IS_ADMIN, False)
curr_project = ctx.get(TenantProps.TENANT, None) curr_project = ctx.get(TenantProps.PROJECT_ID, None)
alarm_project = alarm.get(VProps.PROJECT_ID) alarm_project = alarm.get(VProps.PROJECT_ID)
if not is_admin and curr_project != alarm_project: if not is_admin and curr_project != alarm_project:
LOG.warning('Alarm show - Authorization failed (%s)', vitrage_id) LOG.warning('Alarm show - Authorization failed (%s)', vitrage_id)
@ -77,7 +77,7 @@ class AlarmApis(base.EntityGraphApisBase):
def get_alarm_counts(self, ctx, all_tenants): def get_alarm_counts(self, ctx, all_tenants):
LOG.debug("AlarmApis get_alarm_counts - all_tenants=%s", all_tenants) LOG.debug("AlarmApis get_alarm_counts - all_tenants=%s", all_tenants)
project_id = ctx.get(TenantProps.TENANT, None) project_id = ctx.get(TenantProps.PROJECT_ID, None)
is_admin_project = ctx.get(TenantProps.IS_ADMIN, False) is_admin_project = ctx.get(TenantProps.IS_ADMIN, False)
if all_tenants: if all_tenants:

View File

@ -37,7 +37,7 @@ class RcaApis(base.EntityGraphApisBase):
LOG.debug("RcaApis get_rca - root: %s, all_tenants=%s", LOG.debug("RcaApis get_rca - root: %s, all_tenants=%s",
root, all_tenants) root, all_tenants)
project_id = ctx.get(TenantProps.TENANT, None) project_id = ctx.get(TenantProps.PROJECT_ID, None)
is_admin_project = ctx.get(TenantProps.IS_ADMIN, False) is_admin_project = ctx.get(TenantProps.IS_ADMIN, False)
if all_tenants: if all_tenants:

View File

@ -68,7 +68,7 @@ class ResourceApis(base.EntityGraphApisBase):
return json.dumps(counts) return json.dumps(counts)
def _get_query(self, ctx, resource_type, all_tenants, query_dict): def _get_query(self, ctx, resource_type, all_tenants, query_dict):
project_id = ctx.get(TenantProps.TENANT, None) project_id = ctx.get(TenantProps.PROJECT_ID, None)
is_admin_project = ctx.get(TenantProps.IS_ADMIN, False) is_admin_project = ctx.get(TenantProps.IS_ADMIN, False)
if all_tenants: if all_tenants:
@ -99,7 +99,7 @@ class ResourceApis(base.EntityGraphApisBase):
return None return None
is_admin = ctx.get(TenantProps.IS_ADMIN, False) is_admin = ctx.get(TenantProps.IS_ADMIN, False)
curr_project = ctx.get(TenantProps.TENANT, None) curr_project = ctx.get(TenantProps.PROJECT_ID, None)
resource_project = resource.get(VProps.PROJECT_ID) resource_project = resource.get(VProps.PROJECT_ID)
if not is_admin and curr_project != resource_project: if not is_admin and curr_project != resource_project:
LOG.warning('Resource show - Authorization failed (%s)', LOG.warning('Resource show - Authorization failed (%s)',

View File

@ -40,7 +40,7 @@ class TopologyApis(base.EntityGraphApisBase):
LOG.debug("TopologyApis get_topology - root: %s, all_tenants=%s", LOG.debug("TopologyApis get_topology - root: %s, all_tenants=%s",
root, all_tenants) root, all_tenants)
project_id = ctx.get(TenantProps.TENANT, None) project_id = ctx.get(TenantProps.PROJECT_ID, None)
is_admin_project = ctx.get(TenantProps.IS_ADMIN, False) is_admin_project = ctx.get(TenantProps.IS_ADMIN, False)
LOG.debug('project_id = %s, is_admin_project %s', LOG.debug('project_id = %s, is_admin_project %s',

View File

@ -54,7 +54,7 @@ class WebhookApis(object):
res = self.db_conn.webhooks.query() res = self.db_conn.webhooks.query()
else: else:
res = self.db_conn.webhooks.query(project_id=ctx.get( res = self.db_conn.webhooks.query(project_id=ctx.get(
TenantProps.TENANT, "")) TenantProps.PROJECT_ID, ""))
LOG.info(res) LOG.info(res)
webhooks = [db_row_to_dict(webhook) for webhook in res] webhooks = [db_row_to_dict(webhook) for webhook in res]
@ -81,7 +81,7 @@ class WebhookApis(object):
if len(webhooks) == 0: if len(webhooks) == 0:
LOG.warning("Webhook not found - %s" % id) LOG.warning("Webhook not found - %s" % id)
return None return None
if ctx.get(TenantProps.TENANT, "") == \ if ctx.get(TenantProps.PROJECT_ID, "") == \
webhooks[0][Vprops.PROJECT_ID] or ctx.get( webhooks[0][Vprops.PROJECT_ID] or ctx.get(
TenantProps.IS_ADMIN, False): TenantProps.IS_ADMIN, False):
return webhooks[0] return webhooks[0]
@ -99,7 +99,7 @@ class WebhookApis(object):
if not headers: if not headers:
headers = "" headers = ""
uuid = uuidutils.generate_uuid() uuid = uuidutils.generate_uuid()
project_id = ctx.get(TenantProps.TENANT, "") project_id = ctx.get(TenantProps.PROJECT_ID, "")
is_admin = ctx.get(TenantProps.IS_ADMIN, False) is_admin = ctx.get(TenantProps.IS_ADMIN, False)
created_at = str(datetime.datetime.now()) created_at = str(datetime.datetime.now())
db_row = Webhooks(id=uuid, db_row = Webhooks(id=uuid,

View File

@ -188,7 +188,7 @@ class TemplateStatus(object):
class TenantProps(object): class TenantProps(object):
ALL_TENANTS = 'all_tenants' ALL_TENANTS = 'all_tenants'
TENANT = 'tenant' PROJECT_ID = 'project_id'
IS_ADMIN = 'is_admin' IS_ADMIN = 'is_admin'

View File

@ -56,7 +56,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = AlarmApis(graph, self.api_lock, self._db) apis = AlarmApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'project_id': 'project_1', 'is_admin': True}
# Action # Action
alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False) alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False)
@ -70,7 +70,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = AlarmApis(graph, self.api_lock, self._db) apis = AlarmApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False) alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False)
@ -84,7 +84,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = AlarmApis(graph, self.api_lock, self._db) apis = AlarmApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
counts = apis.get_alarm_counts(ctx, all_tenants=False) counts = apis.get_alarm_counts(ctx, all_tenants=False)
@ -101,7 +101,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = AlarmApis(graph, self.api_lock, self._db) apis = AlarmApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=True) alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=True)
@ -115,7 +115,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = AlarmApis(graph, self.api_lock, self._db) apis = AlarmApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
counts = apis.get_alarm_counts(ctx, all_tenants=True) counts = apis.get_alarm_counts(ctx, all_tenants=True)
@ -132,7 +132,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = RcaApis(graph, self.api_lock, self._db) apis = RcaApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'project_id': 'project_1', 'is_admin': True}
# Action # Action
graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False) graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False)
@ -146,7 +146,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = RcaApis(graph, self.api_lock, self._db) apis = RcaApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
graph_rca = apis.get_rca(ctx, graph_rca = apis.get_rca(ctx,
@ -162,7 +162,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = RcaApis(graph, self.api_lock, self._db) apis = RcaApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False) graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False)
@ -176,7 +176,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = RcaApis(graph, self.api_lock, self._db) apis = RcaApis(graph, self.api_lock, self._db)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=True) graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=True)
@ -190,7 +190,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = TopologyApis(graph, self.api_lock) apis = TopologyApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'project_id': 'project_1', 'is_admin': True}
# Action # Action
graph_topology = apis.get_topology( graph_topology = apis.get_topology(
@ -212,7 +212,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = TopologyApis(graph, self.api_lock) apis = TopologyApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
graph_topology = apis.get_topology( graph_topology = apis.get_topology(
@ -234,7 +234,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = TopologyApis(graph, self.api_lock) apis = TopologyApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
graph_topology = apis.get_topology( graph_topology = apis.get_topology(
@ -253,7 +253,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': True} ctx = {'project_id': 'project_2', 'is_admin': True}
# Action # Action
resources = apis.get_resources( resources = apis.get_resources(
@ -269,7 +269,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': True} ctx = {'project_id': 'project_2', 'is_admin': True}
# Action # Action
resources = apis.get_resources( resources = apis.get_resources(
@ -286,7 +286,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resources = apis.get_resources( resources = apis.get_resources(
@ -302,7 +302,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resources = apis.get_resources( resources = apis.get_resources(
@ -318,7 +318,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resources = apis.get_resources( resources = apis.get_resources(
@ -334,7 +334,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
resources = apis.get_resources( resources = apis.get_resources(
@ -350,7 +350,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': True} ctx = {'project_id': 'project_2', 'is_admin': True}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -369,7 +369,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': True} ctx = {'project_id': 'project_2', 'is_admin': True}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -386,7 +386,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -402,7 +402,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -418,7 +418,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -434,7 +434,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -453,7 +453,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
resources = apis.count_resources( resources = apis.count_resources(
@ -472,7 +472,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'project_id': 'project_1', 'is_admin': True}
# Action # Action
resource = apis.show_resource(ctx, 'zone_1') resource = apis.show_resource(ctx, 'zone_1')
@ -487,7 +487,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
resource = apis.show_resource(ctx, 'zone_1') resource = apis.show_resource(ctx, 'zone_1')
@ -499,7 +499,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': False} ctx = {'project_id': 'project_1', 'is_admin': False}
# Action # Action
resource = apis.show_resource(ctx, 'instance_2') resource = apis.show_resource(ctx, 'instance_2')
@ -515,7 +515,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': False} ctx = {'project_id': 'project_2', 'is_admin': False}
# Action # Action
resource = apis.show_resource(ctx, 'instance_2') resource = apis.show_resource(ctx, 'instance_2')
@ -527,7 +527,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_1', 'is_admin': True} ctx = {'project_id': 'project_1', 'is_admin': True}
# Action # Action
resource = apis.show_resource(ctx, 'instance_2') resource = apis.show_resource(ctx, 'instance_2')
@ -543,7 +543,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
# Setup # Setup
graph = self._create_graph() graph = self._create_graph()
apis = ResourceApis(graph, self.api_lock) apis = ResourceApis(graph, self.api_lock)
ctx = {'tenant': 'project_2', 'is_admin': True} ctx = {'project_id': 'project_2', 'is_admin': True}
# Action # Action
resource = apis.show_resource(ctx, 'instance_2') resource = apis.show_resource(ctx, 'instance_2')