summaryrefslogtreecommitdiff
path: root/openstackclient/identity
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/identity')
-rw-r--r--openstackclient/identity/v3/identity_provider.py45
-rw-r--r--openstackclient/identity/v3/trust.py87
2 files changed, 130 insertions, 2 deletions
diff --git a/openstackclient/identity/v3/identity_provider.py b/openstackclient/identity/v3/identity_provider.py
index 7307cea0..19a62144 100644
--- a/openstackclient/identity/v3/identity_provider.py
+++ b/openstackclient/identity/v3/identity_provider.py
@@ -63,6 +63,16 @@ class CreateIdentityProvider(command.ShowOne):
'specified, a domain will be created automatically. '
'(Name or ID)'),
)
+ parser.add_argument(
+ '--authorization-ttl',
+ metavar='<authorization-ttl>',
+ type=int,
+ help=_('Time to keep the role assignments for users '
+ 'authenticating via this identity provider. '
+ 'When not provided, global default configured in the '
+ 'Identity service will be used. '
+ 'Available since Identity API version 3.14 (Ussuri).'),
+ )
enable_identity_provider = parser.add_mutually_exclusive_group()
enable_identity_provider.add_argument(
'--enable',
@@ -95,12 +105,23 @@ class CreateIdentityProvider(command.ShowOne):
domain_id = common.find_domain(identity_client,
parsed_args.domain).id
+ # TODO(pas-ha) actually check for 3.14 microversion
+ kwargs = {}
+ auth_ttl = parsed_args.authorization_ttl
+ if auth_ttl is not None:
+ if auth_ttl < 0:
+ msg = (_("%(param)s must be positive integer or zero."
+ ) % {"param": "authorization-ttl"})
+ raise exceptions.CommandError(msg)
+ kwargs['authorization_ttl'] = auth_ttl
+
idp = identity_client.federation.identity_providers.create(
id=parsed_args.identity_provider_id,
remote_ids=remote_ids,
description=parsed_args.description,
domain_id=domain_id,
- enabled=parsed_args.enabled)
+ enabled=parsed_args.enabled,
+ **kwargs)
idp._info.pop('links', None)
remote_ids = format_columns.ListColumn(idp._info.pop('remote_ids', []))
@@ -205,6 +226,14 @@ class SetIdentityProvider(command.Command):
help=_('Name of a file that contains many remote IDs to associate '
'with the identity provider, one per line'),
)
+ parser.add_argument(
+ '--authorization-ttl',
+ metavar='<authorization-ttl>',
+ type=int,
+ help=_('Time to keep the role assignments for users '
+ 'authenticating via this identity provider. '
+ 'Available since Identity API version 3.14 (Ussuri).'),
+ )
enable_identity_provider = parser.add_mutually_exclusive_group()
enable_identity_provider.add_argument(
'--enable',
@@ -241,6 +270,20 @@ class SetIdentityProvider(command.Command):
if parsed_args.remote_id_file or parsed_args.remote_id:
kwargs['remote_ids'] = remote_ids
+ # TODO(pas-ha) actually check for 3.14 microversion
+ # TODO(pas-ha) make it possible to reset authorization_ttl
+ # back to None value.
+ # Currently not possible as filter_kwargs decorator in
+ # keystoneclient/base.py explicitly drops the None-valued keys
+ # from kwargs, and 'update' method is wrapped in this decorator.
+ auth_ttl = parsed_args.authorization_ttl
+ if auth_ttl is not None:
+ if auth_ttl < 0:
+ msg = (_("%(param)s must be positive integer or zero."
+ ) % {"param": "authorization-ttl"})
+ raise exceptions.CommandError(msg)
+ kwargs['authorization_ttl'] = auth_ttl
+
federation_client.identity_providers.update(
parsed_args.identity_provider,
**kwargs
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,