Merge "network: Add tenant project filter for RBAC list"

This commit is contained in:
Zuul 2022-09-30 12:10:29 +00:00 committed by Gerrit Code Review
commit 38dda16639
3 changed files with 39 additions and 0 deletions

View File

@ -217,6 +217,11 @@ class ListNetworkRBAC(command.Lister):
help=_('List network RBAC policies according to given '
'action ("access_as_external" or "access_as_shared")')
)
parser.add_argument(
'--target-project',
metavar='<target-project>',
help=_('List network RBAC policies for a specific target project')
)
parser.add_argument(
'--long',
action='store_true',
@ -247,6 +252,16 @@ class ListNetworkRBAC(command.Lister):
query['object_type'] = parsed_args.type
if parsed_args.action is not None:
query['action'] = parsed_args.action
if parsed_args.target_project is not None:
project_id = "*"
if parsed_args.target_project != "*":
identity_client = self.app.client_manager.identity
project_id = identity_common.find_project(
identity_client,
parsed_args.target_project,
).id
query['target_project_id'] = project_id
data = client.rbac_policies(**query)

View File

@ -405,6 +405,9 @@ class TestListNetworkRABC(TestNetworkRBAC):
self.network.rbac_policies = mock.Mock(return_value=self.rbac_policies)
self.project = identity_fakes_v3.FakeProject.create_one_project()
self.projects_mock.get.return_value = self.project
def test_network_rbac_list(self):
arglist = []
verifylist = []
@ -466,6 +469,22 @@ class TestListNetworkRABC(TestNetworkRBAC):
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
def test_network_rbac_list_target_project_opt(self):
arglist = [
'--target-project', self.rbac_policies[0].target_project_id, ]
verifylist = [
('target_project', self.rbac_policies[0].target_project_id)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.network.rbac_policies.assert_called_with(**{
'target_project_id': self.project.id
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
class TestSetNetworkRBAC(TestNetworkRBAC):

View File

@ -0,0 +1,5 @@
---
features:
- |
Add a new argument ``--target-project`` to the ``network rbac list``
command to filter for a specific target project.