summaryrefslogtreecommitdiff
path: root/openstackclient/identity
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-09-30 12:23:14 +0000
committerGerrit Code Review <review@openstack.org>2022-09-30 12:23:14 +0000
commit26946d56703300bcaf636e4ddca8d879c3a50ae9 (patch)
tree136a40fdae2166d2f1417faf3b05b1864d3d362d /openstackclient/identity
parent5043626c8043f35f6a044f1b0845fcd45eaa8775 (diff)
parent64e4520b2a79b9046a791f5e3729f5cbfc2d3fa5 (diff)
downloadpython-openstackclient-26946d56703300bcaf636e4ddca8d879c3a50ae9.tar.gz
Merge "Add trustor and trustee filtering to trusts list"
Diffstat (limited to 'openstackclient/identity')
-rw-r--r--openstackclient/identity/v3/trust.py87
1 files changed, 86 insertions, 1 deletions
diff --git a/openstackclient/identity/v3/trust.py b/openstackclient/identity/v3/trust.py
index cd3a65d0..61273f41 100644
--- a/openstackclient/identity/v3/trust.py
+++ b/openstackclient/identity/v3/trust.py
@@ -176,10 +176,95 @@ class DeleteTrust(command.Command):
class ListTrust(command.Lister):
_description = _("List trusts")
+ def get_parser(self, prog_name):
+ parser = super().get_parser(prog_name)
+ parser.add_argument(
+ '--trustor',
+ metavar='<trustor-user>',
+ help=_('Trustor user to filter (name or ID)'),
+ )
+ parser.add_argument(
+ '--trustee',
+ metavar='<trustee-user>',
+ help=_('Trustee user to filter (name or ID)'),
+ )
+ parser.add_argument(
+ '--trustor-domain',
+ metavar='<trustor-domain>',
+ help=_('Domain that contains <trustor> (name or ID)'),
+ )
+ parser.add_argument(
+ '--trustee-domain',
+ metavar='<trustee-domain>',
+ help=_('Domain that contains <trustee> (name or ID)'),
+ )
+ parser.add_argument(
+ '--auth-user',
+ action="store_true",
+ dest='authuser',
+ help=_('Only list trusts related to the authenticated user'),
+ )
+ return parser
+
def take_action(self, parsed_args):
+ identity_client = self.app.client_manager.identity
+ auth_ref = self.app.client_manager.auth_ref
+
+ if parsed_args.authuser and any([
+ parsed_args.trustor,
+ parsed_args.trustor_domain,
+ parsed_args.trustee,
+ parsed_args.trustee_domain,
+ ]):
+ msg = _("--authuser cannot be used with --trustee or --trustor")
+ raise exceptions.CommandError(msg)
+
+ if parsed_args.trustee_domain and not parsed_args.trustee:
+ msg = _("Using --trustee-domain mandates the use of --trustee")
+ raise exceptions.CommandError(msg)
+
+ if parsed_args.trustor_domain and not parsed_args.trustor:
+ msg = _("Using --trustor-domain mandates the use of --trustor")
+ raise exceptions.CommandError(msg)
+
+ if parsed_args.authuser:
+ if auth_ref:
+ user = common.find_user(
+ identity_client,
+ auth_ref.user_id
+ )
+ # We need two calls here as we want trusts with
+ # either the trustor or the trustee set to current user
+ # using a single call would give us trusts with both
+ # trustee and trustor set to current user
+ data1 = identity_client.trusts.list(trustor_user=user)
+ data2 = identity_client.trusts.list(trustee_user=user)
+ data = set(data1 + data2)
+ else:
+ trustor = None
+ if parsed_args.trustor:
+ trustor = common.find_user(
+ identity_client,
+ parsed_args.trustor,
+ parsed_args.trustor_domain,
+ )
+
+ trustee = None
+ if parsed_args.trustee:
+ trustee = common.find_user(
+ identity_client,
+ parsed_args.trustor,
+ parsed_args.trustor_domain,
+ )
+
+ data = self.app.client_manager.identity.trusts.list(
+ trustor_user=trustor,
+ trustee_user=trustee,
+ )
+
columns = ('ID', 'Expires At', 'Impersonation', 'Project ID',
'Trustee User ID', 'Trustor User ID')
- data = self.app.client_manager.identity.trusts.list()
+
return (columns,
(utils.get_item_properties(
s, columns,