Merge "rename tenant to project_id"
This commit is contained in:
commit
a7cd8e8c0b
@ -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', user_id)
|
||||
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')
|
||||
# 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,
|
||||
project_id=project_id,
|
||||
is_admin=(user_name == 'admin'))
|
||||
|
||||
# Inject the context...
|
||||
|
@ -43,7 +43,7 @@ class AlarmApis(base.EntityGraphApisBase):
|
||||
if not vitrage_id or vitrage_id == 'all':
|
||||
if not all_tenants:
|
||||
kwargs['project_id'] = \
|
||||
ctx.get(TenantProps.TENANT, 'no-project')
|
||||
ctx.get(TenantProps.PROJECT_ID, 'no-project')
|
||||
kwargs['is_admin_project'] = \
|
||||
ctx.get(TenantProps.IS_ADMIN, False)
|
||||
else:
|
||||
@ -65,7 +65,7 @@ class AlarmApis(base.EntityGraphApisBase):
|
||||
return None
|
||||
|
||||
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)
|
||||
if not is_admin and curr_project != alarm_project:
|
||||
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):
|
||||
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)
|
||||
|
||||
if all_tenants:
|
||||
|
@ -37,7 +37,7 @@ class RcaApis(base.EntityGraphApisBase):
|
||||
LOG.debug("RcaApis get_rca - root: %s, all_tenants=%s",
|
||||
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)
|
||||
|
||||
if all_tenants:
|
||||
|
@ -68,7 +68,7 @@ class ResourceApis(base.EntityGraphApisBase):
|
||||
return json.dumps(counts)
|
||||
|
||||
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)
|
||||
|
||||
if all_tenants:
|
||||
@ -99,7 +99,7 @@ class ResourceApis(base.EntityGraphApisBase):
|
||||
return None
|
||||
|
||||
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)
|
||||
if not is_admin and curr_project != resource_project:
|
||||
LOG.warning('Resource show - Authorization failed (%s)',
|
||||
|
@ -40,7 +40,7 @@ class TopologyApis(base.EntityGraphApisBase):
|
||||
LOG.debug("TopologyApis get_topology - root: %s, all_tenants=%s",
|
||||
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)
|
||||
|
||||
LOG.debug('project_id = %s, is_admin_project %s',
|
||||
|
@ -54,7 +54,7 @@ class WebhookApis(object):
|
||||
res = self.db_conn.webhooks.query()
|
||||
else:
|
||||
res = self.db_conn.webhooks.query(project_id=ctx.get(
|
||||
TenantProps.TENANT, ""))
|
||||
TenantProps.PROJECT_ID, ""))
|
||||
LOG.info(res)
|
||||
webhooks = [db_row_to_dict(webhook) for webhook in res]
|
||||
|
||||
@ -81,7 +81,7 @@ class WebhookApis(object):
|
||||
if len(webhooks) == 0:
|
||||
LOG.warning("Webhook not found - %s" % id)
|
||||
return None
|
||||
if ctx.get(TenantProps.TENANT, "") == \
|
||||
if ctx.get(TenantProps.PROJECT_ID, "") == \
|
||||
webhooks[0][Vprops.PROJECT_ID] or ctx.get(
|
||||
TenantProps.IS_ADMIN, False):
|
||||
return webhooks[0]
|
||||
@ -99,7 +99,7 @@ class WebhookApis(object):
|
||||
if not headers:
|
||||
headers = ""
|
||||
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)
|
||||
created_at = str(datetime.datetime.now())
|
||||
db_row = Webhooks(id=uuid,
|
||||
|
@ -188,7 +188,7 @@ class TemplateStatus(object):
|
||||
|
||||
class TenantProps(object):
|
||||
ALL_TENANTS = 'all_tenants'
|
||||
TENANT = 'tenant'
|
||||
PROJECT_ID = 'project_id'
|
||||
IS_ADMIN = 'is_admin'
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = AlarmApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False)
|
||||
@ -70,7 +70,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = AlarmApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=False)
|
||||
@ -84,7 +84,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = AlarmApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
counts = apis.get_alarm_counts(ctx, all_tenants=False)
|
||||
@ -101,7 +101,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = AlarmApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
alarms = apis.get_alarms(ctx, vitrage_id='all', all_tenants=True)
|
||||
@ -115,7 +115,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = AlarmApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
counts = apis.get_alarm_counts(ctx, all_tenants=True)
|
||||
@ -132,7 +132,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = RcaApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False)
|
||||
@ -146,7 +146,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = RcaApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
graph_rca = apis.get_rca(ctx,
|
||||
@ -162,7 +162,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = RcaApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=False)
|
||||
@ -176,7 +176,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = RcaApis(graph, self.api_lock, self._db)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
graph_rca = apis.get_rca(ctx, root='alarm_on_host', all_tenants=True)
|
||||
@ -190,7 +190,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = TopologyApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
graph_topology = apis.get_topology(
|
||||
@ -212,7 +212,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = TopologyApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
graph_topology = apis.get_topology(
|
||||
@ -234,7 +234,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = TopologyApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
graph_topology = apis.get_topology(
|
||||
@ -253,7 +253,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resources = apis.get_resources(
|
||||
@ -269,7 +269,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resources = apis.get_resources(
|
||||
@ -286,7 +286,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.get_resources(
|
||||
@ -302,7 +302,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.get_resources(
|
||||
@ -318,7 +318,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.get_resources(
|
||||
@ -334,7 +334,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.get_resources(
|
||||
@ -350,7 +350,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -369,7 +369,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -386,7 +386,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -402,7 +402,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -418,7 +418,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -434,7 +434,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -453,7 +453,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resources = apis.count_resources(
|
||||
@ -472,7 +472,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resource = apis.show_resource(ctx, 'zone_1')
|
||||
@ -487,7 +487,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resource = apis.show_resource(ctx, 'zone_1')
|
||||
@ -499,7 +499,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resource = apis.show_resource(ctx, 'instance_2')
|
||||
@ -515,7 +515,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': False}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': False}
|
||||
|
||||
# Action
|
||||
resource = apis.show_resource(ctx, 'instance_2')
|
||||
@ -527,7 +527,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_1', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_1', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resource = apis.show_resource(ctx, 'instance_2')
|
||||
@ -543,7 +543,7 @@ class TestApis(TestEntityGraphUnitBase, TestConfiguration):
|
||||
# Setup
|
||||
graph = self._create_graph()
|
||||
apis = ResourceApis(graph, self.api_lock)
|
||||
ctx = {'tenant': 'project_2', 'is_admin': True}
|
||||
ctx = {'project_id': 'project_2', 'is_admin': True}
|
||||
|
||||
# Action
|
||||
resource = apis.show_resource(ctx, 'instance_2')
|
||||
|
Loading…
Reference in New Issue
Block a user