diff options
Diffstat (limited to 'openstackclient/identity')
39 files changed, 1638 insertions, 973 deletions
diff --git a/openstackclient/identity/client.py b/openstackclient/identity/client.py index 0292aac2..5ed81e58 100644 --- a/openstackclient/identity/client.py +++ b/openstackclient/identity/client.py @@ -43,18 +43,15 @@ AUTH_VERSIONS = { def make_client(instance): """Returns an identity service client.""" identity_client = utils.get_client_class( - API_NAME, - instance._api_version[API_NAME], - API_VERSIONS) + API_NAME, instance._api_version[API_NAME], API_VERSIONS + ) LOG.debug('Instantiating identity client: %s', identity_client) # Remember interface only if interface is set kwargs = utils.build_kwargs_dict('interface', instance.interface) client = identity_client( - session=instance.session, - region_name=instance.region_name, - **kwargs + session=instance.session, region_name=instance.region_name, **kwargs ) return client @@ -66,8 +63,11 @@ def build_option_parser(parser): '--os-identity-api-version', metavar='<identity-api-version>', default=utils.env('OS_IDENTITY_API_VERSION'), - help=_('Identity API version, default=%s ' - '(Env: OS_IDENTITY_API_VERSION)') % DEFAULT_API_VERSION, + help=_( + 'Identity API version, default=%s ' + '(Env: OS_IDENTITY_API_VERSION)' + ) + % DEFAULT_API_VERSION, ) return parser diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py index a75db4f8..745ffb2b 100644 --- a/openstackclient/identity/common.py +++ b/openstackclient/identity/common.py @@ -33,7 +33,8 @@ def find_service_in_list(service_list, service_id): if service.id == service_id: return service raise exceptions.CommandError( - "No service with a type, name or ID of '%s' exists." % service_id) + "No service with a type, name or ID of '%s' exists." % service_id + ) def find_service(identity_client, name_type_or_id): @@ -52,8 +53,10 @@ def find_service(identity_client, name_type_or_id): except identity_exc.NotFound: pass except identity_exc.NoUniqueMatch: - msg = _("Multiple service matches found for '%s', " - "use an ID to be more specific.") + msg = _( + "Multiple service matches found for '%s', " + "use an ID to be more specific." + ) raise exceptions.CommandError(msg % name_type_or_id) try: @@ -63,8 +66,10 @@ def find_service(identity_client, name_type_or_id): msg = _("No service with a type, name or ID of '%s' exists.") raise exceptions.CommandError(msg % name_type_or_id) except identity_exc.NoUniqueMatch: - msg = _("Multiple service matches found for '%s', " - "use an ID to be more specific.") + msg = _( + "Multiple service matches found for '%s', " + "use an ID to be more specific." + ) raise exceptions.CommandError(msg % name_type_or_id) @@ -141,42 +146,56 @@ def _get_domain_id_if_requested(identity_client, domain_name_or_id): def find_domain(identity_client, name_or_id): - return _find_identity_resource(identity_client.domains, name_or_id, - domains.Domain) + return _find_identity_resource( + identity_client.domains, name_or_id, domains.Domain + ) def find_group(identity_client, name_or_id, domain_name_or_id=None): domain_id = _get_domain_id_if_requested(identity_client, domain_name_or_id) if not domain_id: - return _find_identity_resource(identity_client.groups, name_or_id, - groups.Group) + return _find_identity_resource( + identity_client.groups, name_or_id, groups.Group + ) else: - return _find_identity_resource(identity_client.groups, name_or_id, - groups.Group, domain_id=domain_id) + return _find_identity_resource( + identity_client.groups, + name_or_id, + groups.Group, + domain_id=domain_id, + ) def find_project(identity_client, name_or_id, domain_name_or_id=None): domain_id = _get_domain_id_if_requested(identity_client, domain_name_or_id) if not domain_id: - return _find_identity_resource(identity_client.projects, name_or_id, - projects.Project) + return _find_identity_resource( + identity_client.projects, name_or_id, projects.Project + ) else: - return _find_identity_resource(identity_client.projects, name_or_id, - projects.Project, domain_id=domain_id) + return _find_identity_resource( + identity_client.projects, + name_or_id, + projects.Project, + domain_id=domain_id, + ) def find_user(identity_client, name_or_id, domain_name_or_id=None): domain_id = _get_domain_id_if_requested(identity_client, domain_name_or_id) if not domain_id: - return _find_identity_resource(identity_client.users, name_or_id, - users.User) + return _find_identity_resource( + identity_client.users, name_or_id, users.User + ) else: - return _find_identity_resource(identity_client.users, name_or_id, - users.User, domain_id=domain_id) + return _find_identity_resource( + identity_client.users, name_or_id, users.User, domain_id=domain_id + ) -def _find_identity_resource(identity_client_manager, name_or_id, - resource_type, **kwargs): +def _find_identity_resource( + identity_client_manager, name_or_id, resource_type, **kwargs +): """Find a specific identity resource. Using keystoneclient's manager, attempt to find a specific resource by its @@ -203,8 +222,9 @@ def _find_identity_resource(identity_client_manager, name_or_id, """ try: - identity_resource = utils.find_resource(identity_client_manager, - name_or_id, **kwargs) + identity_resource = utils.find_resource( + identity_client_manager, name_or_id, **kwargs + ) if identity_resource is not None: return identity_resource except (exceptions.Forbidden, identity_exc.Forbidden): @@ -226,9 +246,11 @@ def add_user_domain_option_to_parser(parser): parser.add_argument( '--user-domain', metavar='<user-domain>', - help=_('Domain the user belongs to (name or ID). ' - 'This can be used in case collisions between user names ' - 'exist.'), + help=_( + 'Domain the user belongs to (name or ID). ' + 'This can be used in case collisions between user names ' + 'exist.' + ), ) @@ -236,9 +258,11 @@ def add_group_domain_option_to_parser(parser): parser.add_argument( '--group-domain', metavar='<group-domain>', - help=_('Domain the group belongs to (name or ID). ' - 'This can be used in case collisions between group names ' - 'exist.'), + help=_( + 'Domain the group belongs to (name or ID). ' + 'This can be used in case collisions between group names ' + 'exist.' + ), ) @@ -246,9 +270,13 @@ def add_project_domain_option_to_parser(parser, enhance_help=lambda _h: _h): parser.add_argument( '--project-domain', metavar='<project-domain>', - help=enhance_help(_('Domain the project belongs to (name or ID). This ' - 'can be used in case collisions between project ' - 'names exist.')), + help=enhance_help( + _( + 'Domain the project belongs to (name or ID). This ' + 'can be used in case collisions between project ' + 'names exist.' + ) + ), ) @@ -256,9 +284,11 @@ def add_role_domain_option_to_parser(parser): parser.add_argument( '--role-domain', metavar='<role-domain>', - help=_('Domain the role belongs to (name or ID). ' - 'This must be specified when the name of a domain specific ' - 'role is used.'), + help=_( + 'Domain the role belongs to (name or ID). ' + 'This must be specified when the name of a domain specific ' + 'role is used.' + ), ) @@ -267,8 +297,9 @@ def add_inherited_option_to_parser(parser): '--inherited', action='store_true', default=False, - help=_('Specifies if the role grant is inheritable to the sub ' - 'projects'), + help=_( + 'Specifies if the role grant is inheritable to the sub ' 'projects' + ), ) @@ -277,8 +308,10 @@ def add_resource_option_to_parser(parser): enable_group.add_argument( '--immutable', action='store_true', - help=_('Make resource immutable. An immutable project may not ' - 'be deleted or modified except to remove the immutable flag'), + help=_( + 'Make resource immutable. An immutable project may not ' + 'be deleted or modified except to remove the immutable flag' + ), ) enable_group.add_argument( '--no-immutable', diff --git a/openstackclient/identity/v2_0/catalog.py b/openstackclient/identity/v2_0/catalog.py index 05d0e9ae..bea97cce 100644 --- a/openstackclient/identity/v2_0/catalog.py +++ b/openstackclient/identity/v2_0/catalog.py @@ -47,7 +47,6 @@ class ListCatalog(command.Lister): _description = _("List services in the service catalog") def take_action(self, parsed_args): - # Trigger auth if it has not happened yet auth_ref = self.app.client_manager.auth_ref if not auth_ref: @@ -57,13 +56,19 @@ class ListCatalog(command.Lister): data = auth_ref.service_catalog.catalog columns = ('Name', 'Type', 'Endpoints') - return (columns, - (utils.get_dict_properties( - s, columns, + return ( + columns, + ( + utils.get_dict_properties( + s, + columns, formatters={ 'Endpoints': EndpointsColumn, }, - ) for s in data)) + ) + for s in data + ), + ) class ShowCatalog(command.ShowOne): @@ -79,7 +84,6 @@ class ShowCatalog(command.ShowOne): return parser def take_action(self, parsed_args): - # Trigger auth if it has not happened yet auth_ref = self.app.client_manager.auth_ref if not auth_ref: @@ -89,8 +93,10 @@ class ShowCatalog(command.ShowOne): data = None for service in auth_ref.service_catalog.catalog: - if (service.get('name') == parsed_args.service or - service.get('type') == parsed_args.service): + if ( + service.get('name') == parsed_args.service + or service.get('type') == parsed_args.service + ): data = service.copy() data['endpoints'] = EndpointsColumn(data['endpoints']) if 'endpoints_links' in data: diff --git a/openstackclient/identity/v2_0/ec2creds.py b/openstackclient/identity/v2_0/ec2creds.py index f712bf45..94d68330 100644 --- a/openstackclient/identity/v2_0/ec2creds.py +++ b/openstackclient/identity/v2_0/ec2creds.py @@ -77,9 +77,7 @@ class CreateEC2Creds(command.ShowOne): info.update(creds._info) if 'tenant_id' in info: - info.update( - {'project_id': info.pop('tenant_id')} - ) + info.update({'project_id': info.pop('tenant_id')}) return zip(*sorted(info.items())) @@ -120,14 +118,19 @@ class DeleteEC2Creds(command.Command): identity_client.ec2.delete(user, access_key) except Exception as e: result += 1 - LOG.error(_("Failed to delete EC2 credentials with " - "access key '%(access_key)s': %(e)s"), - {'access_key': access_key, 'e': e}) + LOG.error( + _( + "Failed to delete EC2 credentials with " + "access key '%(access_key)s': %(e)s" + ), + {'access_key': access_key, 'e': e}, + ) if result > 0: total = len(parsed_args.access_keys) - msg = (_("%(result)s of %(total)s EC2 keys failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s EC2 keys failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -159,11 +162,17 @@ class ListEC2Creds(command.Lister): column_headers = ('Access', 'Secret', 'Project ID', 'User ID') data = identity_client.ec2.list(user) - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ShowEC2Creds(command.ShowOne): @@ -201,8 +210,6 @@ class ShowEC2Creds(command.ShowOne): info.update(creds._info) if 'tenant_id' in info: - info.update( - {'project_id': info.pop('tenant_id')} - ) + info.update({'project_id': info.pop('tenant_id')}) return zip(*sorted(info.items())) diff --git a/openstackclient/identity/v2_0/endpoint.py b/openstackclient/identity/v2_0/endpoint.py index 57906ddf..2b9970a6 100644 --- a/openstackclient/identity/v2_0/endpoint.py +++ b/openstackclient/identity/v2_0/endpoint.py @@ -69,7 +69,8 @@ class CreateEndpoint(command.ShowOne): service.id, parsed_args.publicurl, parsed_args.adminurl, - parsed_args.internalurl,) + parsed_args.internalurl, + ) info = {} info.update(endpoint._info) @@ -100,14 +101,19 @@ class DeleteEndpoint(command.Command): identity_client.endpoints.delete(endpoint) except Exception as e: result += 1 - LOG.error(_("Failed to delete endpoint with " - "ID '%(endpoint)s': %(e)s"), - {'endpoint': endpoint, 'e': e}) + LOG.error( + _( + "Failed to delete endpoint with " + "ID '%(endpoint)s': %(e)s" + ), + {'endpoint': endpoint, 'e': e}, + ) if result > 0: total = len(parsed_args.endpoints) - msg = (_("%(result)s of %(total)s endpoints failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s endpoints failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -127,8 +133,15 @@ class ListEndpoint(command.Lister): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity if parsed_args.long: - columns = ('ID', 'Region', 'Service Name', 'Service Type', - 'PublicURL', 'AdminURL', 'InternalURL') + columns = ( + 'ID', + 'Region', + 'Service Name', + 'Service Type', + 'PublicURL', + 'AdminURL', + 'InternalURL', + ) else: columns = ('ID', 'Region', 'Service Name', 'Service Type') data = identity_client.endpoints.list() @@ -137,11 +150,17 @@ class ListEndpoint(command.Lister): service = common.find_service(identity_client, ep.service_id) ep.service_name = service.name ep.service_type = service.type - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ShowEndpoint(command.ShowOne): @@ -152,8 +171,10 @@ class ShowEndpoint(command.ShowOne): parser.add_argument( 'endpoint_or_service', metavar='<endpoint>', - help=_('Endpoint to display (endpoint ID, service ID,' - ' service name, service type)'), + help=_( + 'Endpoint to display (endpoint ID, service ID,' + ' service name, service type)' + ), ) return parser @@ -166,8 +187,9 @@ class ShowEndpoint(command.ShowOne): match = ep service = common.find_service(identity_client, ep.service_id) if match is None: - service = common.find_service(identity_client, - parsed_args.endpoint_or_service) + service = common.find_service( + identity_client, parsed_args.endpoint_or_service + ) for ep in data: if ep.service_id == service.id: match = ep diff --git a/openstackclient/identity/v2_0/project.py b/openstackclient/identity/v2_0/project.py index f431c021..e2f378db 100644 --- a/openstackclient/identity/v2_0/project.py +++ b/openstackclient/identity/v2_0/project.py @@ -60,8 +60,10 @@ class CreateProject(command.ShowOne): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Add a property to <name> ' - '(repeat option to set multiple properties)'), + help=_( + 'Add a property to <name> ' + '(repeat option to set multiple properties)' + ), ) parser.add_argument( '--or-show', @@ -128,14 +130,19 @@ class DeleteProject(command.Command): identity_client.tenants.delete(project_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete project with " - "name or ID '%(project)s': %(e)s"), - {'project': project, 'e': e}) + LOG.error( + _( + "Failed to delete project with " + "name or ID '%(project)s': %(e)s" + ), + {'project': project, 'e': e}, + ) if errors > 0: total = len(parsed_args.projects) - msg = (_("%(errors)s of %(total)s projects failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _( + "%(errors)s of %(total)s projects failed " "to delete." + ) % {'errors': errors, 'total': total} raise exceptions.CommandError(msg) @@ -153,9 +160,11 @@ class ListProject(command.Lister): parser.add_argument( '--sort', metavar='<key>[:<direction>]', - help=_('Sort output by selected keys and directions (asc or desc) ' - '(default: asc), repeat this option to specify multiple ' - 'keys and directions.'), + help=_( + 'Sort output by selected keys and directions (asc or desc) ' + '(default: asc), repeat this option to specify multiple ' + 'keys and directions.' + ), ) return parser @@ -167,11 +176,17 @@ class ListProject(command.Lister): data = self.app.client_manager.identity.tenants.list() if parsed_args.sort: data = utils.sort_items(data, parsed_args.sort) - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetProject(command.Command): @@ -209,8 +224,10 @@ class SetProject(command.Command): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a project property ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a project property ' + '(repeat option to set multiple properties)' + ), ) return parser @@ -268,8 +285,8 @@ class ShowProject(command.ShowOne): except ks_exc.Forbidden: auth_ref = self.app.client_manager.auth_ref if ( - parsed_args.project == auth_ref.project_id or - parsed_args.project == auth_ref.project_name + parsed_args.project == auth_ref.project_id + or parsed_args.project == auth_ref.project_name ): # Ask for currently auth'ed project so return it info = { @@ -316,8 +333,10 @@ class UnsetProject(command.Command): metavar='<key>', action='append', default=[], - help=_('Unset a project property ' - '(repeat option to unset multiple properties)'), + help=_( + 'Unset a project property ' + '(repeat option to unset multiple properties)' + ), ) return parser diff --git a/openstackclient/identity/v2_0/role.py b/openstackclient/identity/v2_0/role.py index 5c53fbcd..931957bd 100644 --- a/openstackclient/identity/v2_0/role.py +++ b/openstackclient/identity/v2_0/role.py @@ -133,14 +133,20 @@ class DeleteRole(command.Command): identity_client.roles.delete(role_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete role with " - "name or ID '%(role)s': %(e)s"), - {'role': role, 'e': e}) + LOG.error( + _( + "Failed to delete role with " + "name or ID '%(role)s': %(e)s" + ), + {'role': role, 'e': e}, + ) if errors > 0: total = len(parsed_args.roles) - msg = (_("%(errors)s of %(total)s roles failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s roles failed " "to delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) @@ -153,11 +159,17 @@ class ListRole(command.Lister): columns = ('ID', 'Name') data = identity_client.roles.list() - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class RemoveRole(command.Command): @@ -192,10 +204,7 @@ class RemoveRole(command.Command): parsed_args.project, ) user = utils.find_resource(identity_client.users, parsed_args.user) - identity_client.roles.remove_user_role( - user.id, - role.id, - project.id) + identity_client.roles.remove_user_role(user.id, role.id, project.id) class ShowRole(command.ShowOne): diff --git a/openstackclient/identity/v2_0/role_assignment.py b/openstackclient/identity/v2_0/role_assignment.py index 8236bbfc..c3d492e2 100644 --- a/openstackclient/identity/v2_0/role_assignment.py +++ b/openstackclient/identity/v2_0/role_assignment.py @@ -51,7 +51,7 @@ class ListRoleAssignment(command.Lister): action="store_true", dest='authproject', help='Only list assignments for the project to which the ' - 'authenticated user\'s token is scoped', + 'authenticated user\'s token is scoped', ) return parser @@ -70,8 +70,7 @@ class ListRoleAssignment(command.Lister): elif parsed_args.authuser: if auth_ref: user = utils.find_resource( - identity_client.users, - auth_ref.user_id + identity_client.users, auth_ref.user_id ) project = None @@ -83,8 +82,7 @@ class ListRoleAssignment(command.Lister): elif parsed_args.authproject: if auth_ref: project = utils.find_resource( - identity_client.projects, - auth_ref.project_id + identity_client.projects, auth_ref.project_id ) # If user or project is not specified, we would ideally list all @@ -107,8 +105,14 @@ class ListRoleAssignment(command.Lister): user_role.user = user.id user_role.project = project.id - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) diff --git a/openstackclient/identity/v2_0/service.py b/openstackclient/identity/v2_0/service.py index afc0b3d7..15203e69 100644 --- a/openstackclient/identity/v2_0/service.py +++ b/openstackclient/identity/v2_0/service.py @@ -90,14 +90,19 @@ class DeleteService(command.Command): identity_client.services.delete(service.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete service with " - "name or ID '%(service)s': %(e)s"), - {'service': service, 'e': e}) + LOG.error( + _( + "Failed to delete service with " + "name or ID '%(service)s': %(e)s" + ), + {'service': service, 'e': e}, + ) if result > 0: total = len(parsed_args.services) - msg = (_("%(result)s of %(total)s services failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s services failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -115,7 +120,6 @@ class ListService(command.Lister): return parser def take_action(self, parsed_args): - if parsed_args.long: columns = ('ID', 'Name', 'Type', 'Description') else: @@ -151,15 +155,17 @@ class ShowService(command.ShowOne): if parsed_args.catalog: endpoints = auth_ref.service_catalog.get_endpoints( - service_type=parsed_args.service) - for (service, service_endpoints) in endpoints.items(): + service_type=parsed_args.service + ) + for service, service_endpoints in endpoints.items(): if service_endpoints: info = {"type": service} info.update(service_endpoints[0]) return zip(*sorted(info.items())) - msg = _("No service catalog with a type, name or ID of '%s' " - "exists.") % (parsed_args.service) + msg = _( + "No service catalog with a type, name or ID of '%s' " "exists." + ) % (parsed_args.service) raise exceptions.CommandError(msg) else: service = common.find_service(identity_client, parsed_args.service) diff --git a/openstackclient/identity/v2_0/token.py b/openstackclient/identity/v2_0/token.py index 205e15d3..8759df8d 100644 --- a/openstackclient/identity/v2_0/token.py +++ b/openstackclient/identity/v2_0/token.py @@ -35,7 +35,8 @@ class IssueToken(command.ShowOne): auth_ref = self.app.client_manager.auth_ref if not auth_ref: raise exceptions.AuthorizationFailure( - "Only an authorized user may issue a new token.") + "Only an authorized user may issue a new token." + ) data = {} if auth_ref.auth_token: diff --git a/openstackclient/identity/v2_0/user.py b/openstackclient/identity/v2_0/user.py index 8dac093e..7bcbc451 100644 --- a/openstackclient/identity/v2_0/user.py +++ b/openstackclient/identity/v2_0/user.py @@ -122,8 +122,12 @@ class CreateUser(command.ShowOne): parsed_args.password = utils.get_password(self.app.stdin) if not parsed_args.password: - LOG.warning(_("No password was supplied, authentication will fail " - "when a user does not have a password.")) + LOG.warning( + _( + "No password was supplied, authentication will fail " + "when a user does not have a password." + ) + ) try: user = identity_client.users.create( @@ -147,9 +151,7 @@ class CreateUser(command.ShowOne): # the returned resource has 'tenantId'. Sigh. # We're using project_id now inside OSC so there. if 'tenantId' in user._info: - user._info.update( - {'project_id': user._info.pop('tenantId')} - ) + user._info.update({'project_id': user._info.pop('tenantId')}) info = {} info.update(user._info) @@ -182,14 +184,20 @@ class DeleteUser(command.Command): identity_client.users.delete(user_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete user with " - "name or ID '%(user)s': %(e)s"), - {'user': user, 'e': e}) + LOG.error( + _( + "Failed to delete user with " + "name or ID '%(user)s': %(e)s" + ), + {'user': user, 'e': e}, + ) if errors > 0: total = len(parsed_args.users) - msg = (_("%(errors)s of %(total)s users failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s users failed " "to delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) @@ -246,7 +254,8 @@ class ListUser(command.Lister): # Just forget it if there's any trouble pass formatters['tenantId'] = functools.partial( - ProjectColumn, project_cache=project_cache) + ProjectColumn, project_cache=project_cache + ) else: columns = column_headers = ('ID', 'Name') data = identity_client.users.list(tenant_id=project) @@ -267,12 +276,18 @@ class ListUser(command.Lister): d._info['tenantId'] = d._info.pop('tenant_id') d._add_details(d._info) - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, mixed_case_fields=('tenantId',), formatters=formatters, - ) for s in data)) + ) + for s in data + ), + ) class SetUser(command.Command): @@ -331,8 +346,12 @@ class SetUser(command.Command): parsed_args.password = utils.get_password(self.app.stdin) if '' == parsed_args.password: - LOG.warning(_("No password was supplied, authentication will fail " - "when a user does not have a password.")) + LOG.warning( + _( + "No password was supplied, authentication will fail " + "when a user does not have a password." + ) + ) user = utils.find_resource( identity_client.users, @@ -394,8 +413,8 @@ class ShowUser(command.ShowOne): except ks_exc.Forbidden: auth_ref = self.app.client_manager.auth_ref if ( - parsed_args.user == auth_ref.user_id or - parsed_args.user == auth_ref.username + parsed_args.user == auth_ref.user_id + or parsed_args.user == auth_ref.username ): # Ask for currently auth'ed project so return it info = { @@ -409,12 +428,8 @@ class ShowUser(command.ShowOne): raise if 'tenantId' in info: - info.update( - {'project_id': info.pop('tenantId')} - ) + info.update({'project_id': info.pop('tenantId')}) if 'tenant_id' in info: - info.update( - {'project_id': info.pop('tenant_id')} - ) + info.update({'project_id': info.pop('tenant_id')}) return zip(*sorted(info.items())) diff --git a/openstackclient/identity/v3/access_rule.py b/openstackclient/identity/v3/access_rule.py index ffda04f9..5eff39c7 100644 --- a/openstackclient/identity/v3/access_rule.py +++ b/openstackclient/identity/v3/access_rule.py @@ -48,18 +48,24 @@ class DeleteAccessRule(command.Command): for ac in parsed_args.access_rule: try: access_rule = utils.find_resource( - identity_client.access_rules, ac) + identity_client.access_rules, ac + ) identity_client.access_rules.delete(access_rule.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete access rule with " - "ID '%(ac)s': %(e)s"), - {'ac': ac, 'e': e}) + LOG.error( + _( + "Failed to delete access rule with " + "ID '%(ac)s': %(e)s" + ), + {'ac': ac, 'e': e}, + ) if errors > 0: total = len(parsed_args.access_rule) - msg = (_("%(errors)s of %(total)s access rules failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _( + "%(errors)s of %(total)s access rules failed " "to delete." + ) % {'errors': errors, 'total': total} raise exceptions.CommandError(msg) @@ -79,20 +85,25 @@ class ListAccessRule(command.Lister): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity if parsed_args.user: - user_id = common.find_user(identity_client, - parsed_args.user, - parsed_args.user_domain).id + user_id = common.find_user( + identity_client, parsed_args.user, parsed_args.user_domain + ).id else: user_id = None columns = ('ID', 'Service', 'Method', 'Path') - data = identity_client.access_rules.list( - user=user_id) - return (columns, - (utils.get_item_properties( - s, columns, + data = identity_client.access_rules.list(user=user_id) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ShowAccessRule(command.ShowOne): @@ -109,8 +120,9 @@ class ShowAccessRule(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - access_rule = utils.find_resource(identity_client.access_rules, - parsed_args.access_rule) + access_rule = utils.find_resource( + identity_client.access_rules, parsed_args.access_rule + ) access_rule._info.pop('links', None) diff --git a/openstackclient/identity/v3/application_credential.py b/openstackclient/identity/v3/application_credential.py index a2089856..c75de3a4 100644 --- a/openstackclient/identity/v3/application_credential.py +++ b/openstackclient/identity/v3/application_credential.py @@ -43,23 +43,29 @@ class CreateApplicationCredential(command.ShowOne): parser.add_argument( '--secret', metavar='<secret>', - help=_('Secret to use for authentication (if not provided, one' - ' will be generated)'), + help=_( + 'Secret to use for authentication (if not provided, one' + ' will be generated)' + ), ) parser.add_argument( '--role', metavar='<role>', action='append', default=[], - help=_('Roles to authorize (name or ID) (repeat option to set' - ' multiple values)'), + help=_( + 'Roles to authorize (name or ID) (repeat option to set' + ' multiple values)' + ), ) parser.add_argument( '--expiration', metavar='<expiration>', - help=_('Sets an expiration date for the application credential,' - ' format of YYYY-mm-ddTHH:MM:SS (if not provided, the' - ' application credential will not expire)'), + help=_( + 'Sets an expiration date for the application credential,' + ' format of YYYY-mm-ddTHH:MM:SS (if not provided, the' + ' application credential will not expire)' + ), ) parser.add_argument( '--description', @@ -69,27 +75,32 @@ class CreateApplicationCredential(command.ShowOne): parser.add_argument( '--unrestricted', action="store_true", - help=_('Enable application credential to create and delete other' - ' application credentials and trusts (this is potentially' - ' dangerous behavior and is disabled by default)'), + help=_( + 'Enable application credential to create and delete other' + ' application credentials and trusts (this is potentially' + ' dangerous behavior and is disabled by default)' + ), ) parser.add_argument( '--restricted', action="store_true", - help=_('Prohibit application credential from creating and deleting' - ' other application credentials and trusts (this is the' - ' default behavior)'), + help=_( + 'Prohibit application credential from creating and deleting' + ' other application credentials and trusts (this is the' + ' default behavior)' + ), ) parser.add_argument( '--access-rules', metavar='<access-rules>', - help=_('Either a string or file path containing a JSON-formatted ' - 'list of access rules, each containing a request method, ' - 'path, and service, for example ' - '\'[{"method": "GET", ' - '"path": "/v2.1/servers", ' - '"service": "compute"}]\''), - + help=_( + 'Either a string or file path containing a JSON-formatted ' + 'list of access rules, each containing a request method, ' + 'path, and service, for example ' + '\'[{"method": "GET", ' + '"path": "/v2.1/servers", ' + '"service": "compute"}]\'' + ), ) return parser @@ -103,14 +114,16 @@ class CreateApplicationCredential(command.ShowOne): # which they are currently scoped with a subset of the role # assignments they have on that project. Don't bother trying to # look up roles via keystone, just introspect the token. - role_id = common._get_token_resource(identity_client, "roles", - role) + role_id = common._get_token_resource( + identity_client, "roles", role + ) role_ids.append(role_id) expires_at = None if parsed_args.expiration: - expires_at = datetime.datetime.strptime(parsed_args.expiration, - '%Y-%m-%dT%H:%M:%S') + expires_at = datetime.datetime.strptime( + parsed_args.expiration, '%Y-%m-%dT%H:%M:%S' + ) if parsed_args.restricted: unrestricted = False @@ -125,9 +138,11 @@ class CreateApplicationCredential(command.ShowOne): with open(parsed_args.access_rules) as f: access_rules = json.load(f) except IOError: - raise exceptions.CommandError( - _("Access rules is not valid JSON string or file does" - " not exist.")) + msg = _( + "Access rules is not valid JSON string or file does" + " not exist." + ) + raise exceptions.CommandError(msg) else: access_rules = None @@ -172,18 +187,25 @@ class DeleteApplicationCredential(command.Command): for ac in parsed_args.application_credential: try: app_cred = utils.find_resource( - identity_client.application_credentials, ac) + identity_client.application_credentials, ac + ) identity_client.application_credentials.delete(app_cred.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete application credential with " - "name or ID '%(ac)s': %(e)s"), - {'ac': ac, 'e': e}) + LOG.error( + _( + "Failed to delete application credential with " + "name or ID '%(ac)s': %(e)s" + ), + {'ac': ac, 'e': e}, + ) if errors > 0: total = len(parsed_args.application_credential) - msg = (_("%(errors)s of %(total)s application credentials failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _( + "%(errors)s of %(total)s application credentials failed " + "to delete." + ) % {'errors': errors, 'total': total} raise exceptions.CommandError(msg) @@ -203,20 +225,25 @@ class ListApplicationCredential(command.Lister): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity if parsed_args.user: - user_id = common.find_user(identity_client, - parsed_args.user, - parsed_args.user_domain).id + user_id = common.find_user( + identity_client, parsed_args.user, parsed_args.user_domain + ).id else: user_id = None columns = ('ID', 'Name', 'Project ID', 'Description', 'Expires At') - data = identity_client.application_credentials.list( - user=user_id) - return (columns, - (utils.get_item_properties( - s, columns, + data = identity_client.application_credentials.list(user=user_id) + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ShowApplicationCredential(command.ShowOne): @@ -233,8 +260,10 @@ class ShowApplicationCredential(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - app_cred = utils.find_resource(identity_client.application_credentials, - parsed_args.application_credential) + app_cred = utils.find_resource( + identity_client.application_credentials, + parsed_args.application_credential, + ) app_cred._info.pop('links', None) diff --git a/openstackclient/identity/v3/catalog.py b/openstackclient/identity/v3/catalog.py index d1f7d319..a5c2ee47 100644 --- a/openstackclient/identity/v3/catalog.py +++ b/openstackclient/identity/v3/catalog.py @@ -42,7 +42,6 @@ class ListCatalog(command.Lister): _description = _("List services in the service catalog") def take_action(self, parsed_args): - # Trigger auth if it has not happened yet auth_ref = self.app.client_manager.auth_ref if not auth_ref: @@ -52,13 +51,19 @@ class ListCatalog(command.Lister): data = auth_ref.service_catalog.catalog columns = ('Name', 'Type', 'Endpoints') - return (columns, - (utils.get_dict_properties( - s, columns, + return ( + columns, + ( + utils.get_dict_properties( + s, + columns, formatters={ 'Endpoints': EndpointsColumn, }, - ) for s in data)) + ) + for s in data + ), + ) class ShowCatalog(command.ShowOne): @@ -74,7 +79,6 @@ class ShowCatalog(command.ShowOne): return parser def take_action(self, parsed_args): - # Trigger auth if it has not happened yet auth_ref = self.app.client_manager.auth_ref if not auth_ref: @@ -84,8 +88,10 @@ class ShowCatalog(command.ShowOne): data = None for service in auth_ref.service_catalog.catalog: - if (service.get('name') == parsed_args.service or - service.get('type') == parsed_args.service): + if ( + service.get('name') == parsed_args.service + or service.get('type') == parsed_args.service + ): data = dict(service) data['endpoints'] = EndpointsColumn(data['endpoints']) if 'links' in data: diff --git a/openstackclient/identity/v3/consumer.py b/openstackclient/identity/v3/consumer.py index 2f925aba..c40c9886 100644 --- a/openstackclient/identity/v3/consumer.py +++ b/openstackclient/identity/v3/consumer.py @@ -67,17 +67,24 @@ class DeleteConsumer(command.Command): for i in parsed_args.consumer: try: consumer = utils.find_resource( - identity_client.oauth1.consumers, i) + identity_client.oauth1.consumers, i + ) identity_client.oauth1.consumers.delete(consumer.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete consumer with name or " - "ID '%(consumer)s': %(e)s"), {'consumer': i, 'e': e}) + LOG.error( + _( + "Failed to delete consumer with name or " + "ID '%(consumer)s': %(e)s" + ), + {'consumer': i, 'e': e}, + ) if result > 0: total = len(parsed_args.consumer) - msg = (_("%(result)s of %(total)s consumers failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s consumers failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -87,11 +94,17 @@ class ListConsumer(command.Lister): def take_action(self, parsed_args): columns = ('ID', 'Description') data = self.app.client_manager.identity.oauth1.consumers.list() - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetConsumer(command.Command): @@ -114,13 +127,15 @@ class SetConsumer(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity consumer = utils.find_resource( - identity_client.oauth1.consumers, parsed_args.consumer) + identity_client.oauth1.consumers, parsed_args.consumer + ) kwargs = {} if parsed_args.description: kwargs['description'] = parsed_args.description consumer = identity_client.oauth1.consumers.update( - consumer.id, **kwargs) + consumer.id, **kwargs + ) class ShowConsumer(command.ShowOne): @@ -138,7 +153,8 @@ class ShowConsumer(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity consumer = utils.find_resource( - identity_client.oauth1.consumers, parsed_args.consumer) + identity_client.oauth1.consumers, parsed_args.consumer + ) consumer._info.pop('links', None) return zip(*sorted(consumer._info.items())) diff --git a/openstackclient/identity/v3/credential.py b/openstackclient/identity/v3/credential.py index bf48df83..80b65bef 100644 --- a/openstackclient/identity/v3/credential.py +++ b/openstackclient/identity/v3/credential.py @@ -52,25 +52,30 @@ class CreateCredential(command.ShowOne): parser.add_argument( '--project', metavar='<project>', - help=_('Project which limits the scope of ' - 'the credential (name or ID)'), + help=_( + 'Project which limits the scope of ' + 'the credential (name or ID)' + ), ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - user_id = utils.find_resource(identity_client.users, - parsed_args.user).id + user_id = utils.find_resource( + identity_client.users, parsed_args.user + ).id if parsed_args.project: - project = utils.find_resource(identity_client.projects, - parsed_args.project).id + project = utils.find_resource( + identity_client.projects, parsed_args.project + ).id else: project = None credential = identity_client.credentials.create( user=user_id, type=parsed_args.type, blob=parsed_args.data, - project=project) + project=project, + ) credential._info.pop('links') return zip(*sorted(credential._info.items())) @@ -97,14 +102,19 @@ class DeleteCredential(command.Command): identity_client.credentials.delete(i) except Exception as e: result += 1 - LOG.error(_("Failed to delete credentials with " - "ID '%(credential)s': %(e)s"), - {'credential': i, 'e': e}) + LOG.error( + _( + "Failed to delete credentials with " + "ID '%(credential)s': %(e)s" + ), + {'credential': i, 'e': e}, + ) if result > 0: total = len(parsed_args.credential) - msg = (_("%(result)s of %(total)s credential failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s credential failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -144,11 +154,17 @@ class ListCredential(command.Lister): columns = ('ID', 'Type', 'User ID', 'Blob', 'Project ID') column_headers = ('ID', 'Type', 'User ID', 'Data', 'Project ID') data = self.app.client_manager.identity.credentials.list(**kwargs) - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetCredential(command.Command): @@ -182,28 +198,34 @@ class SetCredential(command.Command): parser.add_argument( '--project', metavar='<project>', - help=_('Project which limits the scope of ' - 'the credential (name or ID)'), + help=_( + 'Project which limits the scope of ' + 'the credential (name or ID)' + ), ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - user_id = utils.find_resource(identity_client.users, - parsed_args.user).id + user_id = utils.find_resource( + identity_client.users, parsed_args.user + ).id if parsed_args.project: - project = utils.find_resource(identity_client.projects, - parsed_args.project).id + project = utils.find_resource( + identity_client.projects, parsed_args.project + ).id else: project = None - identity_client.credentials.update(parsed_args.credential, - user=user_id, - type=parsed_args.type, - blob=parsed_args.data, - project=project) + identity_client.credentials.update( + parsed_args.credential, + user=user_id, + type=parsed_args.type, + blob=parsed_args.data, + project=project, + ) class ShowCredential(command.ShowOne): @@ -220,8 +242,9 @@ class ShowCredential(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - credential = utils.find_resource(identity_client.credentials, - parsed_args.credential) + credential = utils.find_resource( + identity_client.credentials, parsed_args.credential + ) credential._info.pop('links') return zip(*sorted(credential._info.items())) diff --git a/openstackclient/identity/v3/domain.py b/openstackclient/identity/v3/domain.py index e0bd1020..1fcf245c 100644 --- a/openstackclient/identity/v3/domain.py +++ b/openstackclient/identity/v3/domain.py @@ -81,8 +81,9 @@ class CreateDomain(command.ShowOne): ) except ks_exc.Conflict: if parsed_args.or_show: - domain = utils.find_resource(identity_client.domains, - parsed_args.name) + domain = utils.find_resource( + identity_client.domains, parsed_args.name + ) LOG.info(_('Returning existing domain %s'), domain.name) else: raise @@ -113,13 +114,20 @@ class DeleteDomain(command.Command): identity_client.domains.delete(domain.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete domain with name or " - "ID '%(domain)s': %(e)s"), {'domain': i, 'e': e}) + LOG.error( + _( + "Failed to delete domain with name or " + "ID '%(domain)s': %(e)s" + ), + {'domain': i, 'e': e}, + ) if result > 0: total = len(parsed_args.domain) - msg = (_("%(result)s of %(total)s domains failed " - "to delete.") % {'result': result, 'total': total}) + msg = _("%(result)s of %(total)s domains failed " "to delete.") % { + 'result': result, + 'total': total, + } raise exceptions.CommandError(msg) @@ -150,11 +158,17 @@ class ListDomain(command.Lister): columns = ('ID', 'Name', 'Enabled', 'Description') data = self.app.client_manager.identity.domains.list(**kwargs) - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetDomain(command.Command): @@ -193,8 +207,9 @@ class SetDomain(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - domain = utils.find_resource(identity_client.domains, - parsed_args.domain) + domain = utils.find_resource( + identity_client.domains, parsed_args.domain + ) kwargs = {} if parsed_args.name: kwargs['name'] = parsed_args.name @@ -228,11 +243,11 @@ class ShowDomain(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - domain_str = common._get_token_resource(identity_client, 'domain', - parsed_args.domain) + domain_str = common._get_token_resource( + identity_client, 'domain', parsed_args.domain + ) - domain = utils.find_resource(identity_client.domains, - domain_str) + domain = utils.find_resource(identity_client.domains, domain_str) domain._info.pop('links') return zip(*sorted(domain._info.items())) diff --git a/openstackclient/identity/v3/ec2creds.py b/openstackclient/identity/v3/ec2creds.py index 921b9168..49bedc74 100644 --- a/openstackclient/identity/v3/ec2creds.py +++ b/openstackclient/identity/v3/ec2creds.py @@ -36,17 +36,20 @@ def _determine_ec2_user(parsed_args, client_manager): user_domain = None if parsed_args.user_domain: - user_domain = common.find_domain(client_manager.identity, - parsed_args.user_domain) + user_domain = common.find_domain( + client_manager.identity, parsed_args.user_domain + ) if parsed_args.user: if user_domain is not None: - user = utils.find_resource(client_manager.identity.users, - parsed_args.user, - domain_id=user_domain.id).id - else: user = utils.find_resource( client_manager.identity.users, - parsed_args.user).id + parsed_args.user, + domain_id=user_domain.id, + ).id + else: + user = utils.find_resource( + client_manager.identity.users, parsed_args.user + ).id else: # Get the user from the current auth user = client_manager.auth_ref.user_id @@ -61,14 +64,18 @@ class CreateEC2Creds(command.ShowOne): parser.add_argument( '--project', metavar='<project>', - help=_('Create credentials in project ' - '(name or ID; default: current authenticated project)'), + help=_( + 'Create credentials in project ' + '(name or ID; default: current authenticated project)' + ), ) parser.add_argument( '--user', metavar='<user>', - help=_('Create credentials for user ' - '(name or ID; default: current authenticated user)'), + help=_( + 'Create credentials for user ' + '(name or ID; default: current authenticated user)' + ), ) common.add_user_domain_option_to_parser(parser) common.add_project_domain_option_to_parser(parser) @@ -81,18 +88,21 @@ class CreateEC2Creds(command.ShowOne): project_domain = None if parsed_args.project_domain: - project_domain = common.find_domain(identity_client, - parsed_args.project_domain) + project_domain = common.find_domain( + identity_client, parsed_args.project_domain + ) if parsed_args.project: if project_domain is not None: - project = utils.find_resource(identity_client.projects, - parsed_args.project, - domain_id=project_domain.id).id - else: project = utils.find_resource( identity_client.projects, - parsed_args.project).id + parsed_args.project, + domain_id=project_domain.id, + ).id + else: + project = utils.find_resource( + identity_client.projects, parsed_args.project + ).id else: # Get the project from the current auth project = self.app.client_manager.auth_ref.project_id @@ -103,9 +113,7 @@ class CreateEC2Creds(command.ShowOne): info.update(creds._info) if 'tenant_id' in info: - info.update( - {'project_id': info.pop('tenant_id')} - ) + info.update({'project_id': info.pop('tenant_id')}) return zip(*sorted(info.items())) @@ -138,14 +146,19 @@ class DeleteEC2Creds(command.Command): client_manager.identity.ec2.delete(user, i) except Exception as e: result += 1 - LOG.error(_("Failed to delete EC2 credentials with " - "access key '%(access_key)s': %(e)s"), - {'access_key': i, 'e': e}) + LOG.error( + _( + "Failed to delete EC2 credentials with " + "access key '%(access_key)s': %(e)s" + ), + {'access_key': i, 'e': e}, + ) if result > 0: total = len(parsed_args.access_key) - msg = (_("%(result)s of %(total)s EC2 keys failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s EC2 keys failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -170,11 +183,17 @@ class ListEC2Creds(command.Lister): column_headers = ('Access', 'Secret', 'Project ID', 'User ID') data = client_manager.identity.ec2.list(user) - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ShowEC2Creds(command.ShowOne): @@ -204,8 +223,6 @@ class ShowEC2Creds(command.ShowOne): info.update(creds._info) if 'tenant_id' in info: - info.update( - {'project_id': info.pop('tenant_id')} - ) + info.update({'project_id': info.pop('tenant_id')}) return zip(*sorted(info.items())) diff --git a/openstackclient/identity/v3/endpoint.py b/openstackclient/identity/v3/endpoint.py index a3bd2683..7d954ce1 100644 --- a/openstackclient/identity/v3/endpoint.py +++ b/openstackclient/identity/v3/endpoint.py @@ -39,19 +39,20 @@ class AddProjectToEndpoint(command.Command): _description = _("Associate a project to an endpoint") def get_parser(self, prog_name): - parser = super( - AddProjectToEndpoint, self).get_parser(prog_name) + parser = super(AddProjectToEndpoint, self).get_parser(prog_name) parser.add_argument( 'endpoint', metavar='<endpoint>', - help=_('Endpoint to associate with ' - 'specified project (name or ID)'), + help=_( + 'Endpoint to associate with ' 'specified project (name or ID)' + ), ) parser.add_argument( 'project', metavar='<project>', - help=_('Project to associate with ' - 'specified endpoint name or ID)'), + help=_( + 'Project to associate with ' 'specified endpoint name or ID)' + ), ) common.add_project_domain_option_to_parser(parser) return parser @@ -59,16 +60,15 @@ class AddProjectToEndpoint(command.Command): def take_action(self, parsed_args): client = self.app.client_manager.identity - endpoint = utils.find_resource(client.endpoints, - parsed_args.endpoint) + endpoint = utils.find_resource(client.endpoints, parsed_args.endpoint) - project = common.find_project(client, - parsed_args.project, - parsed_args.project_domain) + project = common.find_project( + client, parsed_args.project, parsed_args.project_domain + ) client.endpoint_filter.add_endpoint_to_project( - project=project.id, - endpoint=endpoint.id) + project=project.id, endpoint=endpoint.id + ) class CreateEndpoint(command.ShowOne): @@ -122,7 +122,7 @@ class CreateEndpoint(command.ShowOne): url=parsed_args.url, interface=parsed_args.interface, region=parsed_args.region, - enabled=parsed_args.enabled + enabled=parsed_args.enabled, ) info = {} @@ -152,17 +152,24 @@ class DeleteEndpoint(command.Command): for i in parsed_args.endpoint: try: endpoint_id = utils.find_resource( - identity_client.endpoints, i).id + identity_client.endpoints, i + ).id identity_client.endpoints.delete(endpoint_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete endpoint with " - "ID '%(endpoint)s': %(e)s"), {'endpoint': i, 'e': e}) + LOG.error( + _( + "Failed to delete endpoint with " + "ID '%(endpoint)s': %(e)s" + ), + {'endpoint': i, 'e': e}, + ) if result > 0: total = len(parsed_args.endpoint) - msg = (_("%(result)s of %(total)s endpoints failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s endpoints failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -206,27 +213,37 @@ class ListEndpoint(command.Lister): endpoint = None if parsed_args.endpoint: - endpoint = utils.find_resource(identity_client.endpoints, - parsed_args.endpoint) + endpoint = utils.find_resource( + identity_client.endpoints, parsed_args.endpoint + ) project = None if parsed_args.project: - project = common.find_project(identity_client, - parsed_args.project, - parsed_args.project_domain) + project = common.find_project( + identity_client, + parsed_args.project, + parsed_args.project_domain, + ) if endpoint: columns = ('ID', 'Name') - data = ( - identity_client.endpoint_filter - .list_projects_for_endpoint(endpoint=endpoint.id) + data = identity_client.endpoint_filter.list_projects_for_endpoint( + endpoint=endpoint.id ) else: - columns = ('ID', 'Region', 'Service Name', 'Service Type', - 'Enabled', 'Interface', 'URL') + columns = ( + 'ID', + 'Region', + 'Service Name', + 'Service Type', + 'Enabled', + 'Interface', + 'URL', + ) kwargs = {} if parsed_args.service: - service = common.find_service(identity_client, - parsed_args.service) + service = common.find_service( + identity_client, parsed_args.service + ) kwargs['service'] = service.id if parsed_args.interface: kwargs['interface'] = parsed_args.interface @@ -235,8 +252,9 @@ class ListEndpoint(command.Lister): if project: data = ( - identity_client.endpoint_filter - .list_endpoints_for_project(project=project.id) + identity_client.endpoint_filter.list_endpoints_for_project( + project=project.id + ) ) else: data = identity_client.endpoints.list(**kwargs) @@ -244,35 +262,43 @@ class ListEndpoint(command.Lister): service_list = identity_client.services.list() for ep in data: - service = common.find_service_in_list(service_list, - ep.service_id) + service = common.find_service_in_list( + service_list, ep.service_id + ) ep.service_name = get_service_name(service) ep.service_type = service.type - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class RemoveProjectFromEndpoint(command.Command): _description = _("Dissociate a project from an endpoint") def get_parser(self, prog_name): - parser = super( - RemoveProjectFromEndpoint, self).get_parser(prog_name) + parser = super(RemoveProjectFromEndpoint, self).get_parser(prog_name) parser.add_argument( 'endpoint', metavar='<endpoint>', - help=_('Endpoint to dissociate from ' - 'specified project (name or ID)'), + help=_( + 'Endpoint to dissociate from ' 'specified project (name or ID)' + ), ) parser.add_argument( 'project', metavar='<project>', - help=_('Project to dissociate from ' - 'specified endpoint name or ID)'), + help=_( + 'Project to dissociate from ' 'specified endpoint name or ID)' + ), ) common.add_project_domain_option_to_parser(parser) return parser @@ -280,16 +306,15 @@ class RemoveProjectFromEndpoint(command.Command): def take_action(self, parsed_args): client = self.app.client_manager.identity - endpoint = utils.find_resource(client.endpoints, - parsed_args.endpoint) + endpoint = utils.find_resource(client.endpoints, parsed_args.endpoint) - project = common.find_project(client, - parsed_args.project, - parsed_args.project_domain) + project = common.find_project( + client, parsed_args.project, parsed_args.project_domain + ) client.endpoint_filter.delete_endpoint_from_project( - project=project.id, - endpoint=endpoint.id) + project=project.id, endpoint=endpoint.id + ) class SetEndpoint(command.Command): @@ -340,8 +365,9 @@ class SetEndpoint(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - endpoint = utils.find_resource(identity_client.endpoints, - parsed_args.endpoint) + endpoint = utils.find_resource( + identity_client.endpoints, parsed_args.endpoint + ) service_id = None if parsed_args.service: @@ -359,7 +385,7 @@ class SetEndpoint(command.Command): url=parsed_args.url, interface=parsed_args.interface, region=parsed_args.region, - enabled=enabled + enabled=enabled, ) @@ -371,15 +397,18 @@ class ShowEndpoint(command.ShowOne): parser.add_argument( 'endpoint', metavar='<endpoint>', - help=_('Endpoint to display (endpoint ID, service ID,' - ' service name, service type)'), + help=_( + 'Endpoint to display (endpoint ID, service ID,' + ' service name, service type)' + ), ) return parser def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - endpoint = utils.find_resource(identity_client.endpoints, - parsed_args.endpoint) + endpoint = utils.find_resource( + identity_client.endpoints, parsed_args.endpoint + ) service = common.find_service(identity_client, endpoint.service_id) diff --git a/openstackclient/identity/v3/endpoint_group.py b/openstackclient/identity/v3/endpoint_group.py index 9bb026a9..1d3e5ddd 100644 --- a/openstackclient/identity/v3/endpoint_group.py +++ b/openstackclient/identity/v3/endpoint_group.py @@ -50,8 +50,10 @@ class _FiltersReader(object): try: rules = json.loads(blob) except ValueError as e: - msg = _("An error occurred when reading filters from file " - "%(path)s: %(error)s") % {"path": path, "error": e} + msg = _( + "An error occurred when reading filters from file " + "%(path)s: %(error)s" + ) % {"path": path, "error": e} raise exceptions.CommandError(msg) else: return rules @@ -61,8 +63,7 @@ class AddProjectToEndpointGroup(command.Command): _description = _("Add a project to an endpoint group") def get_parser(self, prog_name): - parser = super( - AddProjectToEndpointGroup, self).get_parser(prog_name) + parser = super(AddProjectToEndpointGroup, self).get_parser(prog_name) parser.add_argument( 'endpointgroup', metavar='<endpoint-group>', @@ -79,16 +80,17 @@ class AddProjectToEndpointGroup(command.Command): def take_action(self, parsed_args): client = self.app.client_manager.identity - endpointgroup = utils.find_resource(client.endpoint_groups, - parsed_args.endpointgroup) + endpointgroup = utils.find_resource( + client.endpoint_groups, parsed_args.endpointgroup + ) - project = common.find_project(client, - parsed_args.project, - parsed_args.project_domain) + project = common.find_project( + client, parsed_args.project, parsed_args.project_domain + ) client.endpoint_filter.add_endpoint_group_to_project( - endpoint_group=endpointgroup.id, - project=project.id) + endpoint_group=endpointgroup.id, project=project.id + ) class CreateEndpointGroup(command.ShowOne, _FiltersReader): @@ -122,7 +124,7 @@ class CreateEndpointGroup(command.ShowOne, _FiltersReader): endpoint_group = identity_client.endpoint_groups.create( name=parsed_args.name, filters=filters, - description=parsed_args.description + description=parsed_args.description, ) info = {} @@ -150,18 +152,24 @@ class DeleteEndpointGroup(command.Command): for i in parsed_args.endpointgroup: try: endpoint_id = utils.find_resource( - identity_client.endpoint_groups, i).id + identity_client.endpoint_groups, i + ).id identity_client.endpoint_groups.delete(endpoint_id) except Exception as e: result += 1 - LOG.error(_("Failed to delete endpoint group with " - "ID '%(endpointgroup)s': %(e)s"), - {'endpointgroup': i, 'e': e}) + LOG.error( + _( + "Failed to delete endpoint group with " + "ID '%(endpointgroup)s': %(e)s" + ), + {'endpointgroup': i, 'e': e}, + ) if result > 0: total = len(parsed_args.endpointgroup) - msg = (_("%(result)s of %(total)s endpointgroups failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s endpointgroups failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -193,40 +201,50 @@ class ListEndpointGroup(command.Lister): endpointgroup = None if parsed_args.endpointgroup: - endpointgroup = utils.find_resource(client.endpoint_groups, - parsed_args.endpointgroup) + endpointgroup = utils.find_resource( + client.endpoint_groups, parsed_args.endpointgroup + ) project = None if parsed_args.project: - project = common.find_project(client, - parsed_args.project, - parsed_args.domain) + project = common.find_project( + client, parsed_args.project, parsed_args.domain + ) if endpointgroup: # List projects associated to the endpoint group columns = ('ID', 'Name', 'Description') data = client.endpoint_filter.list_projects_for_endpoint_group( - endpoint_group=endpointgroup.id) + endpoint_group=endpointgroup.id + ) elif project: columns = ('ID', 'Name', 'Description') data = client.endpoint_filter.list_endpoint_groups_for_project( - project=project.id) + project=project.id + ) else: columns = ('ID', 'Name', 'Description') data = client.endpoint_groups.list() - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class RemoveProjectFromEndpointGroup(command.Command): _description = _("Remove project from endpoint group") def get_parser(self, prog_name): - parser = super( - RemoveProjectFromEndpointGroup, self).get_parser(prog_name) + parser = super(RemoveProjectFromEndpointGroup, self).get_parser( + prog_name + ) parser.add_argument( 'endpointgroup', metavar='<endpoint-group>', @@ -243,16 +261,17 @@ class RemoveProjectFromEndpointGroup(command.Command): def take_action(self, parsed_args): client = self.app.client_manager.identity - endpointgroup = utils.find_resource(client.endpoint_groups, - parsed_args.endpointgroup) + endpointgroup = utils.find_resource( + client.endpoint_groups, parsed_args.endpointgroup + ) - project = common.find_project(client, - parsed_args.project, - parsed_args.project_domain) + project = common.find_project( + client, parsed_args.project, parsed_args.project_domain + ) client.endpoint_filter.delete_endpoint_group_from_project( - endpoint_group=endpointgroup.id, - project=project.id) + endpoint_group=endpointgroup.id, project=project.id + ) class SetEndpointGroup(command.Command, _FiltersReader): @@ -285,8 +304,9 @@ class SetEndpointGroup(command.Command, _FiltersReader): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - endpointgroup = utils.find_resource(identity_client.endpoint_groups, - parsed_args.endpointgroup) + endpointgroup = utils.find_resource( + identity_client.endpoint_groups, parsed_args.endpointgroup + ) filters = None if parsed_args.filters: @@ -296,7 +316,7 @@ class SetEndpointGroup(command.Command, _FiltersReader): endpointgroup.id, name=parsed_args.name, filters=filters, - description=parsed_args.description + description=parsed_args.description, ) @@ -314,8 +334,9 @@ class ShowEndpointGroup(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - endpoint_group = utils.find_resource(identity_client.endpoint_groups, - parsed_args.endpointgroup) + endpoint_group = utils.find_resource( + identity_client.endpoint_groups, parsed_args.endpointgroup + ) info = {} endpoint_group._info.pop('links') diff --git a/openstackclient/identity/v3/federation_protocol.py b/openstackclient/identity/v3/federation_protocol.py index 0929469e..ae62390d 100644 --- a/openstackclient/identity/v3/federation_protocol.py +++ b/openstackclient/identity/v3/federation_protocol.py @@ -34,15 +34,19 @@ class CreateProtocol(command.ShowOne): parser.add_argument( 'federation_protocol', metavar='<name>', - help=_('New federation protocol name (must be unique ' - 'per identity provider)'), + help=_( + 'New federation protocol name (must be unique ' + 'per identity provider)' + ), ) parser.add_argument( '--identity-provider', metavar='<identity-provider>', required=True, - help=_('Identity provider that will support the new federation ' - ' protocol (name or ID) (required)'), + help=_( + 'Identity provider that will support the new federation ' + ' protocol (name or ID) (required)' + ), ) parser.add_argument( '--mapping', @@ -58,7 +62,8 @@ class CreateProtocol(command.ShowOne): protocol = identity_client.federation.protocols.create( protocol_id=parsed_args.federation_protocol, identity_provider=parsed_args.identity_provider, - mapping=parsed_args.mapping) + mapping=parsed_args.mapping, + ) info = dict(protocol._info) # NOTE(marek-denis): Identity provider is not included in a response # from Keystone, however it should be listed to the user. Add it @@ -85,8 +90,10 @@ class DeleteProtocol(command.Command): '--identity-provider', metavar='<identity-provider>', required=True, - help=_('Identity provider that supports <federation-protocol> ' - '(name or ID) (required)'), + help=_( + 'Identity provider that supports <federation-protocol> ' + '(name or ID) (required)' + ), ) return parser @@ -97,17 +104,24 @@ class DeleteProtocol(command.Command): for i in parsed_args.federation_protocol: try: identity_client.federation.protocols.delete( - parsed_args.identity_provider, i) + parsed_args.identity_provider, i + ) except Exception as e: result += 1 - LOG.error(_("Failed to delete federation protocol " - "with name or ID '%(protocol)s': %(e)s"), - {'protocol': i, 'e': e}) + LOG.error( + _( + "Failed to delete federation protocol " + "with name or ID '%(protocol)s': %(e)s" + ), + {'protocol': i, 'e': e}, + ) if result > 0: total = len(parsed_args.federation_protocol) - msg = (_("%(result)s of %(total)s federation protocols failed" - " to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s federation protocols failed" + " to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -129,11 +143,14 @@ class ListProtocols(command.Lister): identity_client = self.app.client_manager.identity protocols = identity_client.federation.protocols.list( - parsed_args.identity_provider) + parsed_args.identity_provider + ) columns = ('id', 'mapping') response_attributes = ('id', 'mapping_id') - items = [utils.get_item_properties(s, response_attributes) - for s in protocols] + items = [ + utils.get_item_properties(s, response_attributes) + for s in protocols + ] return (columns, items) @@ -151,8 +168,10 @@ class SetProtocol(command.Command): '--identity-provider', metavar='<identity-provider>', required=True, - help=_('Identity provider that supports <federation-protocol> ' - '(name or ID) (required)'), + help=_( + 'Identity provider that supports <federation-protocol> ' + '(name or ID) (required)' + ), ) parser.add_argument( '--mapping', @@ -165,8 +184,10 @@ class SetProtocol(command.Command): identity_client = self.app.client_manager.identity protocol = identity_client.federation.protocols.update( - parsed_args.identity_provider, parsed_args.federation_protocol, - parsed_args.mapping) + parsed_args.identity_provider, + parsed_args.federation_protocol, + parsed_args.mapping, + ) info = dict(protocol._info) # NOTE(marek-denis): Identity provider is not included in a response # from Keystone, however it should be listed to the user. Add it @@ -191,8 +212,10 @@ class ShowProtocol(command.ShowOne): '--identity-provider', metavar='<identity-provider>', required=True, - help=_('Identity provider that supports <federation-protocol> ' - '(name or ID) (required)'), + help=_( + 'Identity provider that supports <federation-protocol> ' + '(name or ID) (required)' + ), ) return parser @@ -200,7 +223,8 @@ class ShowProtocol(command.ShowOne): identity_client = self.app.client_manager.identity protocol = identity_client.federation.protocols.get( - parsed_args.identity_provider, parsed_args.federation_protocol) + parsed_args.identity_provider, parsed_args.federation_protocol + ) info = dict(protocol._info) info['mapping'] = info.pop('mapping_id') info.pop('links', None) diff --git a/openstackclient/identity/v3/group.py b/openstackclient/identity/v3/group.py index 46c3142c..65eb261a 100644 --- a/openstackclient/identity/v3/group.py +++ b/openstackclient/identity/v3/group.py @@ -43,8 +43,10 @@ class AddUserToGroup(command.Command): 'user', metavar='<user>', nargs='+', - help=_('User(s) to add to <group> (name or ID) ' - '(repeat option to add multiple users)'), + help=_( + 'User(s) to add to <group> (name or ID) ' + '(repeat option to add multiple users)' + ), ) common.add_group_domain_option_to_parser(parser) common.add_user_domain_option_to_parser(parser) @@ -53,16 +55,16 @@ class AddUserToGroup(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - group_id = common.find_group(identity_client, - parsed_args.group, - parsed_args.group_domain).id + group_id = common.find_group( + identity_client, parsed_args.group, parsed_args.group_domain + ).id result = 0 for i in parsed_args.user: try: - user_id = common.find_user(identity_client, - i, - parsed_args.user_domain).id + user_id = common.find_user( + identity_client, i, parsed_args.user_domain + ).id identity_client.users.add_to_group(user_id, group_id) except Exception as e: result += 1 @@ -74,8 +76,12 @@ class AddUserToGroup(command.Command): LOG.error(msg) if result > 0: total = len(parsed_args.user) - msg = (_("%(result)s of %(total)s users not added to group " - "%(group)s.")) % { + msg = ( + _( + "%(result)s of %(total)s users not added to group " + "%(group)s." + ) + ) % { 'result': result, 'total': total, 'group': parsed_args.group, @@ -105,12 +111,12 @@ class CheckUserInGroup(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - user_id = common.find_user(identity_client, - parsed_args.user, - parsed_args.user_domain).id - group_id = common.find_group(identity_client, - parsed_args.group, - parsed_args.group_domain).id + user_id = common.find_user( + identity_client, parsed_args.user, parsed_args.user_domain + ).id + group_id = common.find_group( + identity_client, parsed_args.group, parsed_args.group_domain + ).id try: identity_client.users.check_in_group(user_id, group_id) @@ -163,19 +169,19 @@ class CreateGroup(command.ShowOne): domain = None if parsed_args.domain: - domain = common.find_domain(identity_client, - parsed_args.domain).id + domain = common.find_domain(identity_client, parsed_args.domain).id try: group = identity_client.groups.create( name=parsed_args.name, domain=domain, - description=parsed_args.description) + description=parsed_args.description, + ) except ks_exc.Conflict: if parsed_args.or_show: - group = utils.find_resource(identity_client.groups, - parsed_args.name, - domain_id=domain) + group = utils.find_resource( + identity_client.groups, parsed_args.name, domain_id=domain + ) LOG.info(_('Returning existing group %s'), group.name) else: raise @@ -208,20 +214,26 @@ class DeleteGroup(command.Command): errors = 0 for group in parsed_args.groups: try: - group_obj = common.find_group(identity_client, - group, - parsed_args.domain) + group_obj = common.find_group( + identity_client, group, parsed_args.domain + ) identity_client.groups.delete(group_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete group with " - "name or ID '%(group)s': %(e)s"), - {'group': group, 'e': e}) + LOG.error( + _( + "Failed to delete group with " + "name or ID '%(group)s': %(e)s" + ), + {'group': group, 'e': e}, + ) if errors > 0: total = len(parsed_args.groups) - msg = (_("%(errors)s of %(total)s groups failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s groups failed " "to delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) @@ -254,8 +266,7 @@ class ListGroup(command.Lister): domain = None if parsed_args.domain: - domain = common.find_domain(identity_client, - parsed_args.domain).id + domain = common.find_domain(identity_client, parsed_args.domain).id if parsed_args.user: user = common.find_user( @@ -278,10 +289,14 @@ class ListGroup(command.Lister): return ( columns, - (utils.get_item_properties( - s, columns, - formatters={}, - ) for s in data) + ( + utils.get_item_properties( + s, + columns, + formatters={}, + ) + for s in data + ), ) @@ -299,8 +314,10 @@ class RemoveUserFromGroup(command.Command): 'user', metavar='<user>', nargs='+', - help=_('User(s) to remove from <group> (name or ID) ' - '(repeat option to remove multiple users)'), + help=_( + 'User(s) to remove from <group> (name or ID) ' + '(repeat option to remove multiple users)' + ), ) common.add_group_domain_option_to_parser(parser) common.add_user_domain_option_to_parser(parser) @@ -309,16 +326,16 @@ class RemoveUserFromGroup(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - group_id = common.find_group(identity_client, - parsed_args.group, - parsed_args.group_domain).id + group_id = common.find_group( + identity_client, parsed_args.group, parsed_args.group_domain + ).id result = 0 for i in parsed_args.user: try: - user_id = common.find_user(identity_client, - i, - parsed_args.user_domain).id + user_id = common.find_user( + identity_client, i, parsed_args.user_domain + ).id identity_client.users.remove_from_group(user_id, group_id) except Exception as e: result += 1 @@ -330,8 +347,12 @@ class RemoveUserFromGroup(command.Command): LOG.error(msg) if result > 0: total = len(parsed_args.user) - msg = (_("%(result)s of %(total)s users not removed from group " - "%(group)s.")) % { + msg = ( + _( + "%(result)s of %(total)s users not removed from group " + "%(group)s." + ) + ) % { 'result': result, 'total': total, 'group': parsed_args.group, @@ -368,8 +389,9 @@ class SetGroup(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - group = common.find_group(identity_client, parsed_args.group, - parsed_args.domain) + group = common.find_group( + identity_client, parsed_args.group, parsed_args.domain + ) kwargs = {} if parsed_args.name: kwargs['name'] = parsed_args.name @@ -399,9 +421,11 @@ class ShowGroup(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - group = common.find_group(identity_client, - parsed_args.group, - domain_name_or_id=parsed_args.domain) + group = common.find_group( + identity_client, + parsed_args.group, + domain_name_or_id=parsed_args.domain, + ) group._info.pop('links') return zip(*sorted(group._info.items())) diff --git a/openstackclient/identity/v3/identity_provider.py b/openstackclient/identity/v3/identity_provider.py index 19a62144..230f8198 100644 --- a/openstackclient/identity/v3/identity_provider.py +++ b/openstackclient/identity/v3/identity_provider.py @@ -42,14 +42,18 @@ class CreateIdentityProvider(command.ShowOne): '--remote-id', metavar='<remote-id>', action='append', - help=_('Remote IDs to associate with the Identity Provider ' - '(repeat option to provide multiple values)'), + help=_( + 'Remote IDs to associate with the Identity Provider ' + '(repeat option to provide multiple values)' + ), ) identity_remote_id_provider.add_argument( '--remote-id-file', metavar='<file-name>', - help=_('Name of a file that contains many remote IDs to associate ' - 'with the identity provider, one per line'), + help=_( + 'Name of a file that contains many remote IDs to associate ' + 'with the identity provider, one per line' + ), ) parser.add_argument( '--description', @@ -59,19 +63,23 @@ class CreateIdentityProvider(command.ShowOne): parser.add_argument( '--domain', metavar='<domain>', - help=_('Domain to associate with the identity provider. If not ' - 'specified, a domain will be created automatically. ' - '(Name or ID)'), + help=_( + 'Domain to associate with the identity provider. If not ' + '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).'), + 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( @@ -93,25 +101,29 @@ class CreateIdentityProvider(command.ShowOne): identity_client = self.app.client_manager.identity if parsed_args.remote_id_file: file_content = utils.read_blob_file_contents( - parsed_args.remote_id_file) + parsed_args.remote_id_file + ) remote_ids = file_content.splitlines() remote_ids = list(map(str.strip, remote_ids)) else: - remote_ids = (parsed_args.remote_id - if parsed_args.remote_id else None) + remote_ids = ( + parsed_args.remote_id if parsed_args.remote_id else None + ) domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + 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"}) + msg = _("%(param)s must be positive integer or zero.") % { + "param": "authorization-ttl" + } raise exceptions.CommandError(msg) kwargs['authorization_ttl'] = auth_ttl @@ -121,7 +133,8 @@ class CreateIdentityProvider(command.ShowOne): description=parsed_args.description, domain_id=domain_id, enabled=parsed_args.enabled, - **kwargs) + **kwargs + ) idp._info.pop('links', None) remote_ids = format_columns.ListColumn(idp._info.pop('remote_ids', [])) @@ -150,14 +163,20 @@ class DeleteIdentityProvider(command.Command): identity_client.federation.identity_providers.delete(i) except Exception as e: result += 1 - LOG.error(_("Failed to delete identity providers with " - "name or ID '%(provider)s': %(e)s"), - {'provider': i, 'e': e}) + LOG.error( + _( + "Failed to delete identity providers with " + "name or ID '%(provider)s': %(e)s" + ), + {'provider': i, 'e': e}, + ) if result > 0: total = len(parsed_args.identity_provider) - msg = (_("%(result)s of %(total)s identity providers failed" - " to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s identity providers failed" + " to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -190,11 +209,17 @@ class ListIdentityProvider(command.Lister): kwargs['enabled'] = True data = identity_client.federation.identity_providers.list(**kwargs) - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetIdentityProvider(command.Command): @@ -217,22 +242,28 @@ class SetIdentityProvider(command.Command): '--remote-id', metavar='<remote-id>', action='append', - help=_('Remote IDs to associate with the Identity Provider ' - '(repeat option to provide multiple values)'), + help=_( + 'Remote IDs to associate with the Identity Provider ' + '(repeat option to provide multiple values)' + ), ) identity_remote_id_provider.add_argument( '--remote-id-file', metavar='<file-name>', - help=_('Name of a file that contains many remote IDs to associate ' - 'with the identity provider, one per line'), + 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).'), + 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( @@ -253,7 +284,8 @@ class SetIdentityProvider(command.Command): # Always set remote_ids if either is passed in if parsed_args.remote_id_file: file_content = utils.read_blob_file_contents( - parsed_args.remote_id_file) + parsed_args.remote_id_file + ) remote_ids = file_content.splitlines() remote_ids = list(map(str.strip, remote_ids)) elif parsed_args.remote_id: @@ -279,14 +311,14 @@ class SetIdentityProvider(command.Command): 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"}) + 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 + parsed_args.identity_provider, **kwargs ) @@ -307,7 +339,8 @@ class ShowIdentityProvider(command.ShowOne): idp = utils.find_resource( identity_client.federation.identity_providers, parsed_args.identity_provider, - id=parsed_args.identity_provider) + id=parsed_args.identity_provider, + ) idp._info.pop('links', None) remote_ids = format_columns.ListColumn(idp._info.pop('remote_ids', [])) diff --git a/openstackclient/identity/v3/implied_role.py b/openstackclient/identity/v3/implied_role.py index 054f3028..9d26ccd3 100644 --- a/openstackclient/identity/v3/implied_role.py +++ b/openstackclient/identity/v3/implied_role.py @@ -48,7 +48,6 @@ def _get_role_ids(identity_client, parsed_args): class CreateImpliedRole(command.ShowOne): - _description = _("Creates an association between prior and implied roles") def get_parser(self, prog_name): @@ -69,16 +68,16 @@ class CreateImpliedRole(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity (prior_role_id, implied_role_id) = _get_role_ids( - identity_client, parsed_args) + identity_client, parsed_args + ) response = identity_client.inference_rules.create( - prior_role_id, implied_role_id) + prior_role_id, implied_role_id + ) response._info.pop('links', None) - return zip(*sorted([(k, v['id']) - for k, v in response._info.items()])) + return zip(*sorted([(k, v['id']) for k, v in response._info.items()])) class DeleteImpliedRole(command.Command): - _description = _("Deletes an association between prior and implied roles") def get_parser(self, prog_name): @@ -99,16 +98,19 @@ class DeleteImpliedRole(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity (prior_role_id, implied_role_id) = _get_role_ids( - identity_client, parsed_args) - identity_client.inference_rules.delete( - prior_role_id, implied_role_id) + identity_client, parsed_args + ) + identity_client.inference_rules.delete(prior_role_id, implied_role_id) class ListImpliedRole(command.Lister): - _description = _("List implied roles") - _COLUMNS = ['Prior Role ID', 'Prior Role Name', - 'Implied Role ID', 'Implied Role Name'] + _COLUMNS = [ + 'Prior Role ID', + 'Prior Role Name', + 'Implied Role ID', + 'Implied Role Name', + ] def get_parser(self, prog_name): parser = super(ListImpliedRole, self).get_parser(prog_name) @@ -118,10 +120,12 @@ class ListImpliedRole(command.Lister): def _list_implied(response): for rule in response: for implies in rule.implies: - yield (rule.prior_role['id'], - rule.prior_role['name'], - implies['id'], - implies['name']) + yield ( + rule.prior_role['id'], + rule.prior_role['name'], + implies['id'], + implies['name'], + ) identity_client = self.app.client_manager.identity response = identity_client.inference_rules.list_inference_roles() diff --git a/openstackclient/identity/v3/limit.py b/openstackclient/identity/v3/limit.py index b155cbd8..1610b68d 100644 --- a/openstackclient/identity/v3/limit.py +++ b/openstackclient/identity/v3/limit.py @@ -97,7 +97,7 @@ class CreateLimit(command.ShowOne): parsed_args.resource_name, parsed_args.resource_limit, description=parsed_args.description, - region=region + region=region, ) limit._info.pop('links', None) @@ -168,12 +168,17 @@ class ListLimit(command.Lister): service=service, resource_name=parsed_args.resource_name, region=region, - project=project + project=project, ) columns = ( - 'ID', 'Project ID', 'Service ID', 'Resource Name', - 'Resource Limit', 'Description', 'Region ID' + 'ID', + 'Project ID', + 'Service ID', + 'Resource Name', + 'Resource Limit', + 'Description', + 'Region ID', ) return ( columns, @@ -230,7 +235,7 @@ class SetLimit(command.ShowOne): limit = identity_client.limits.update( parsed_args.limit_id, description=parsed_args.description, - resource_limit=parsed_args.resource_limit + resource_limit=parsed_args.resource_limit, ) limit._info.pop('links', None) @@ -260,12 +265,15 @@ class DeleteLimit(command.Command): identity_client.limits.delete(limit_id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete limit with ID " - "'%(id)s': %(e)s"), - {'id': limit_id, 'e': e}) + LOG.error( + _("Failed to delete limit with ID " "'%(id)s': %(e)s"), + {'id': limit_id, 'e': e}, + ) if errors > 0: total = len(parsed_args.limit_id) - msg = (_("%(errors)s of %(total)s limits failed to " - "delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s limits failed to " "delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) diff --git a/openstackclient/identity/v3/mapping.py b/openstackclient/identity/v3/mapping.py index 7d40a2b7..0a5925de 100644 --- a/openstackclient/identity/v3/mapping.py +++ b/openstackclient/identity/v3/mapping.py @@ -73,8 +73,10 @@ class _RulesReader(object): try: rules = json.loads(blob) except ValueError as e: - msg = _("An error occurred when reading rules from file " - "%(path)s: %(error)s") % {"path": path, "error": e} + msg = _( + "An error occurred when reading rules from file " + "%(path)s: %(error)s" + ) % {"path": path, "error": e} raise exceptions.CommandError(msg) else: return rules @@ -92,7 +94,8 @@ class CreateMapping(command.ShowOne, _RulesReader): ) parser.add_argument( '--rules', - metavar='<filename>', required=True, + metavar='<filename>', + required=True, help=_('Filename that contains a set of mapping rules (required)'), ) return parser @@ -102,8 +105,8 @@ class CreateMapping(command.ShowOne, _RulesReader): rules = self._read_rules(parsed_args.rules) mapping = identity_client.federation.mappings.create( - mapping_id=parsed_args.mapping, - rules=rules) + mapping_id=parsed_args.mapping, rules=rules + ) mapping._info.pop('links', None) return zip(*sorted(mapping._info.items())) @@ -130,13 +133,19 @@ class DeleteMapping(command.Command): identity_client.federation.mappings.delete(i) except Exception as e: result += 1 - LOG.error(_("Failed to delete mapping with name or " - "ID '%(mapping)s': %(e)s"), {'mapping': i, 'e': e}) + LOG.error( + _( + "Failed to delete mapping with name or " + "ID '%(mapping)s': %(e)s" + ), + {'mapping': i, 'e': e}, + ) if result > 0: total = len(parsed_args.mapping) - msg = (_("%(result)s of %(total)s mappings failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s mappings failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -177,8 +186,8 @@ class SetMapping(command.Command, _RulesReader): rules = self._read_rules(parsed_args.rules) mapping = identity_client.federation.mappings.update( - mapping=parsed_args.mapping, - rules=rules) + mapping=parsed_args.mapping, rules=rules + ) mapping._info.pop('links', None) diff --git a/openstackclient/identity/v3/policy.py b/openstackclient/identity/v3/policy.py index 45674210..2504a467 100644 --- a/openstackclient/identity/v3/policy.py +++ b/openstackclient/identity/v3/policy.py @@ -36,8 +36,10 @@ class CreatePolicy(command.ShowOne): '--type', metavar='<type>', default="application/json", - help=_('New MIME type of the policy rules file ' - '(defaults to application/json)'), + help=_( + 'New MIME type of the policy rules file ' + '(defaults to application/json)' + ), ) parser.add_argument( 'rules', @@ -80,13 +82,20 @@ class DeletePolicy(command.Command): identity_client.policies.delete(i) except Exception as e: result += 1 - LOG.error(_("Failed to delete policy with name or " - "ID '%(policy)s': %(e)s"), {'policy': i, 'e': e}) + LOG.error( + _( + "Failed to delete policy with name or " + "ID '%(policy)s': %(e)s" + ), + {'policy': i, 'e': e}, + ) if result > 0: total = len(parsed_args.policy) - msg = (_("%(result)s of %(total)s policys failed " - "to delete.") % {'result': result, 'total': total}) + msg = _("%(result)s of %(total)s policys failed " "to delete.") % { + 'result': result, + 'total': total, + } raise exceptions.CommandError(msg) @@ -111,11 +120,17 @@ class ListPolicy(command.Lister): columns = ('ID', 'Type') column_headers = columns data = self.app.client_manager.identity.policies.list() - return (column_headers, - (utils.get_item_properties( - s, columns, + return ( + column_headers, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetPolicy(command.Command): @@ -170,8 +185,9 @@ class ShowPolicy(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - policy = utils.find_resource(identity_client.policies, - parsed_args.policy) + policy = utils.find_resource( + identity_client.policies, parsed_args.policy + ) policy._info.pop('links') policy._info.update({'rules': policy._info.pop('blob')}) diff --git a/openstackclient/identity/v3/project.py b/openstackclient/identity/v3/project.py index 5e8ce829..6ff264ae 100644 --- a/openstackclient/identity/v3/project.py +++ b/openstackclient/identity/v3/project.py @@ -70,8 +70,10 @@ class CreateProject(command.ShowOne): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Add a property to <name> ' - '(repeat option to set multiple properties)'), + help=_( + 'Add a property to <name> ' + '(repeat option to set multiple properties)' + ), ) parser.add_argument( '--or-show', @@ -87,8 +89,7 @@ class CreateProject(command.ShowOne): domain = None if parsed_args.domain: - domain = common.find_domain(identity_client, - parsed_args.domain).id + domain = common.find_domain(identity_client, parsed_args.domain).id parent = None if parsed_args.parent: @@ -128,9 +129,11 @@ class CreateProject(command.ShowOne): ) except ks_exc.Conflict: if parsed_args.or_show: - project = utils.find_resource(identity_client.projects, - parsed_args.name, - domain_id=domain) + project = utils.find_resource( + identity_client.projects, + parsed_args.name, + domain_id=domain, + ) LOG.info(_('Returning existing project %s'), project.name) else: raise @@ -167,23 +170,29 @@ class DeleteProject(command.Command): for project in parsed_args.projects: try: if domain is not None: - project_obj = utils.find_resource(identity_client.projects, - project, - domain_id=domain.id) + project_obj = utils.find_resource( + identity_client.projects, project, domain_id=domain.id + ) else: - project_obj = utils.find_resource(identity_client.projects, - project) + project_obj = utils.find_resource( + identity_client.projects, project + ) identity_client.projects.delete(project_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete project with " - "name or ID '%(project)s': %(e)s"), - {'project': project, 'e': e}) + LOG.error( + _( + "Failed to delete project with " + "name or ID '%(project)s': %(e)s" + ), + {'project': project, 'e': e}, + ) if errors > 0: total = len(parsed_args.projects) - msg = (_("%(errors)s of %(total)s projects failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _( + "%(errors)s of %(total)s projects failed " "to delete." + ) % {'errors': errors, 'total': total} raise exceptions.CommandError(msg) @@ -210,8 +219,10 @@ class ListProject(command.Lister): parser.add_argument( '--my-projects', action='store_true', - help=_('List projects for the authenticated user. ' - 'Supersedes other filters.'), + help=_( + 'List projects for the authenticated user. ' + 'Supersedes other filters.' + ), ) parser.add_argument( '--long', @@ -222,9 +233,11 @@ class ListProject(command.Lister): parser.add_argument( '--sort', metavar='<key>[:<direction>]', - help=_('Sort output by selected keys and directions (asc or desc) ' - '(default: asc), repeat this option to specify multiple ' - 'keys and directions.'), + help=_( + 'Sort output by selected keys and directions (asc or desc) ' + '(default: asc), repeat this option to specify multiple ' + 'keys and directions.' + ), ) tag.add_tag_filtering_option_to_parser(parser, _('projects')) return parser @@ -239,23 +252,28 @@ class ListProject(command.Lister): domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain( + identity_client, parsed_args.domain + ).id kwargs['domain'] = domain_id if parsed_args.parent: - parent_id = common.find_project(identity_client, - parsed_args.parent).id + parent_id = common.find_project( + identity_client, parsed_args.parent + ).id kwargs['parent'] = parent_id if parsed_args.user: if parsed_args.domain: - user_id = utils.find_resource(identity_client.users, - parsed_args.user, - domain_id=domain_id).id + user_id = utils.find_resource( + identity_client.users, + parsed_args.user, + domain_id=domain_id, + ).id else: - user_id = utils.find_resource(identity_client.users, - parsed_args.user).id + user_id = utils.find_resource( + identity_client.users, parsed_args.user + ).id kwargs['user'] = user_id @@ -272,19 +290,24 @@ class ListProject(command.Lister): # wanting their own project list. if not kwargs: user = self.app.client_manager.auth_ref.user_id - data = identity_client.projects.list( - user=user) + data = identity_client.projects.list(user=user) else: raise if parsed_args.sort: data = utils.sort_items(data, parsed_args.sort) - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetProject(command.Command): @@ -327,8 +350,10 @@ class SetProject(command.Command): '--property', metavar='<key=value>', action=parseractions.KeyValueAction, - help=_('Set a property on <project> ' - '(repeat option to set multiple properties)'), + help=_( + 'Set a property on <project> ' + '(repeat option to set multiple properties)' + ), ) common.add_resource_option_to_parser(parser) tag.add_tag_option_to_parser_for_set(parser, _('project')) @@ -337,9 +362,9 @@ class SetProject(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - project = common.find_project(identity_client, - parsed_args.project, - parsed_args.domain) + project = common.find_project( + identity_client, parsed_args.project, parsed_args.domain + ) kwargs = {} if parsed_args.name: @@ -392,20 +417,19 @@ class ShowProject(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - project_str = common._get_token_resource(identity_client, 'project', - parsed_args.project, - parsed_args.domain) + project_str = common._get_token_resource( + identity_client, 'project', parsed_args.project, parsed_args.domain + ) if parsed_args.domain: domain = common.find_domain(identity_client, parsed_args.domain) project = utils.find_resource( - identity_client.projects, - project_str, - domain_id=domain.id) + identity_client.projects, project_str, domain_id=domain.id + ) else: project = utils.find_resource( - identity_client.projects, - project_str) + identity_client.projects, project_str + ) if parsed_args.parents or parsed_args.children: # NOTE(RuiChen): utils.find_resource() can't pass kwargs, @@ -414,7 +438,8 @@ class ShowProject(command.ShowOne): project = identity_client.projects.get( project.id, parents_as_ids=parsed_args.parents, - subtree_as_ids=parsed_args.children) + subtree_as_ids=parsed_args.children, + ) project._info.pop('links') return zip(*sorted(project._info.items())) diff --git a/openstackclient/identity/v3/region.py b/openstackclient/identity/v3/region.py index 20ee073c..21a80b94 100644 --- a/openstackclient/identity/v3/region.py +++ b/openstackclient/identity/v3/region.py @@ -85,13 +85,20 @@ class DeleteRegion(command.Command): identity_client.regions.delete(i) except Exception as e: result += 1 - LOG.error(_("Failed to delete region with " - "ID '%(region)s': %(e)s"), {'region': i, 'e': e}) + LOG.error( + _( + "Failed to delete region with " + "ID '%(region)s': %(e)s" + ), + {'region': i, 'e': e}, + ) if result > 0: total = len(parsed_args.region) - msg = (_("%(result)s of %(total)s regions failed " - "to delete.") % {'result': result, 'total': total}) + msg = _("%(result)s of %(total)s regions failed " "to delete.") % { + 'result': result, + 'total': total, + } raise exceptions.CommandError(msg) @@ -118,11 +125,17 @@ class ListRegion(command.Lister): columns = ('ID', 'Parent Region Id', 'Description') data = identity_client.regions.list(**kwargs) - return (columns_headers, - (utils.get_item_properties( - s, columns, + return ( + columns_headers, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetRegion(command.Command): @@ -174,8 +187,9 @@ class ShowRegion(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - region = utils.find_resource(identity_client.regions, - parsed_args.region) + region = utils.find_resource( + identity_client.regions, parsed_args.region + ) region._info['region'] = region._info.pop('id') region._info['parent_region'] = region._info.pop('parent_region_id') diff --git a/openstackclient/identity/v3/registered_limit.py b/openstackclient/identity/v3/registered_limit.py index 53117c71..251eb2db 100644 --- a/openstackclient/identity/v3/registered_limit.py +++ b/openstackclient/identity/v3/registered_limit.py @@ -87,7 +87,7 @@ class CreateRegisteredLimit(command.ShowOne): parsed_args.resource_name, parsed_args.default_limit, description=parsed_args.description, - region=region + region=region, ) registered_limit._info.pop('links', None) @@ -117,15 +117,22 @@ class DeleteRegisteredLimit(command.Command): except Exception as e: errors += 1 from pprint import pprint + pprint(type(e)) - LOG.error(_("Failed to delete registered limit with ID " - "'%(id)s': %(e)s"), - {'id': registered_limit_id, 'e': e}) + LOG.error( + _( + "Failed to delete registered limit with ID " + "'%(id)s': %(e)s" + ), + {'id': registered_limit_id, 'e': e}, + ) if errors > 0: total = len(parsed_args.registered_limit_id) - msg = (_("%(errors)s of %(total)s registered limits failed to " - "delete.") % {'errors': errors, 'total': total}) + msg = _( + "%(errors)s of %(total)s registered limits failed to " + "delete." + ) % {'errors': errors, 'total': total} raise exceptions.CommandError(msg) @@ -179,12 +186,16 @@ class ListRegisteredLimit(command.Lister): registered_limits = identity_client.registered_limits.list( service=service, resource_name=parsed_args.resource_name, - region=region + region=region, ) columns = ( - 'ID', 'Service ID', 'Resource Name', 'Default Limit', - 'Description', 'Region ID' + 'ID', + 'Service ID', + 'Resource Name', + 'Default Limit', + 'Description', + 'Region ID', ) return ( columns, @@ -205,18 +216,22 @@ class SetRegisteredLimit(command.ShowOne): parser.add_argument( '--service', metavar='<service>', - help=_('Service to be updated responsible for the resource to ' - 'limit. Either --service, --resource-name or --region must ' - 'be different than existing value otherwise it will be ' - 'duplicate entry') + help=_( + 'Service to be updated responsible for the resource to ' + 'limit. Either --service, --resource-name or --region must ' + 'be different than existing value otherwise it will be ' + 'duplicate entry' + ), ) parser.add_argument( '--resource-name', metavar='<resource-name>', - help=_('Resource to be updated responsible for the resource to ' - 'limit. Either --service, --resource-name or --region must ' - 'be different than existing value otherwise it will be ' - 'duplicate entry'), + help=_( + 'Resource to be updated responsible for the resource to ' + 'limit. Either --service, --resource-name or --region must ' + 'be different than existing value otherwise it will be ' + 'duplicate entry' + ), ) parser.add_argument( '--default-limit', @@ -232,10 +247,12 @@ class SetRegisteredLimit(command.ShowOne): parser.add_argument( '--region', metavar='<region>', - help=_('Region for the registered limit to affect. Either ' - '--service, --resource-name or --region must be ' - 'different than existing value otherwise it will be ' - 'duplicate entry'), + help=_( + 'Region for the registered limit to affect. Either ' + '--service, --resource-name or --region must be ' + 'different than existing value otherwise it will be ' + 'duplicate entry' + ), ) return parser @@ -270,7 +287,7 @@ class SetRegisteredLimit(command.ShowOne): resource_name=parsed_args.resource_name, default_limit=parsed_args.default_limit, description=parsed_args.description, - region=region + region=region, ) registered_limit._info.pop('links', None) diff --git a/openstackclient/identity/v3/role.py b/openstackclient/identity/v3/role.py index a674564f..4c435885 100644 --- a/openstackclient/identity/v3/role.py +++ b/openstackclient/identity/v3/role.py @@ -63,16 +63,15 @@ def _add_identity_and_resource_options_to_parser(parser): common.add_inherited_option_to_parser(parser) -def _process_identity_and_resource_options(parsed_args, - identity_client_manager, - validate_actor_existence=True): - +def _process_identity_and_resource_options( + parsed_args, identity_client_manager, validate_actor_existence=True +): def _find_user(): try: return common.find_user( identity_client_manager, parsed_args.user, - parsed_args.user_domain + parsed_args.user_domain, ).id except exceptions.CommandError: if not validate_actor_existence: @@ -84,7 +83,7 @@ def _process_identity_and_resource_options(parsed_args, return common.find_group( identity_client_manager, parsed_args.group, - parsed_args.group_domain + parsed_args.group_domain, ).id except exceptions.CommandError: if not validate_actor_existence: @@ -129,8 +128,10 @@ def _process_identity_and_resource_options(parsed_args, class AddRole(command.Command): - _description = _("Adds a role assignment to a user or group on the " - "system, a domain, or a project") + _description = _( + "Adds a role assignment to a user or group on the " + "system, a domain, or a project" + ) def get_parser(self, prog_name): parser = super(AddRole, self).get_parser(prog_name) @@ -146,24 +147,30 @@ class AddRole(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - if (not parsed_args.user and not parsed_args.domain and - not parsed_args.group and not parsed_args.project): - msg = _("Role not added, incorrect set of arguments " - "provided. See openstack --help for more details") + if ( + not parsed_args.user + and not parsed_args.domain + and not parsed_args.group + and not parsed_args.project + ): + msg = _( + "Role not added, incorrect set of arguments " + "provided. See openstack --help for more details" + ) raise exceptions.CommandError(msg) domain_id = None if parsed_args.role_domain: - domain_id = common.find_domain(identity_client, - parsed_args.role_domain).id + domain_id = common.find_domain( + identity_client, parsed_args.role_domain + ).id role = utils.find_resource( - identity_client.roles, - parsed_args.role, - domain_id=domain_id + identity_client.roles, parsed_args.role, domain_id=domain_id ) kwargs = _process_identity_and_resource_options( - parsed_args, self.app.client_manager.identity) + parsed_args, self.app.client_manager.identity + ) identity_client.roles.grant(role.id, **kwargs) @@ -201,21 +208,27 @@ class CreateRole(command.ShowOne): domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain( + identity_client, parsed_args.domain + ).id options = common.get_immutable_options(parsed_args) try: role = identity_client.roles.create( - name=parsed_args.name, domain=domain_id, - description=parsed_args.description, options=options) + name=parsed_args.name, + domain=domain_id, + description=parsed_args.description, + options=options, + ) except ks_exc.Conflict: if parsed_args.or_show: - role = utils.find_resource(identity_client.roles, - parsed_args.name, - domain_id=domain_id) + role = utils.find_resource( + identity_client.roles, + parsed_args.name, + domain_id=domain_id, + ) LOG.info(_('Returning existing role %s'), role.name) else: raise @@ -247,27 +260,32 @@ class DeleteRole(command.Command): domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain( + identity_client, parsed_args.domain + ).id errors = 0 for role in parsed_args.roles: try: role_obj = utils.find_resource( - identity_client.roles, - role, - domain_id=domain_id + identity_client.roles, role, domain_id=domain_id ) identity_client.roles.delete(role_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete role with " - "name or ID '%(role)s': %(e)s"), - {'role': role, 'e': e}) + LOG.error( + _( + "Failed to delete role with " + "name or ID '%(role)s': %(e)s" + ), + {'role': role, 'e': e}, + ) if errors > 0: total = len(parsed_args.roles) - msg = (_("%(errors)s of %(total)s roles failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s roles failed " "to delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) @@ -299,16 +317,23 @@ class ListRole(command.Lister): columns = ('ID', 'Name') data = identity_client.roles.list() - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class RemoveRole(command.Command): - _description = _("Removes a role assignment from system/domain/project : " - "user/group") + _description = _( + "Removes a role assignment from system/domain/project : " "user/group" + ) def get_parser(self, prog_name): parser = super(RemoveRole, self).get_parser(prog_name) @@ -325,25 +350,31 @@ class RemoveRole(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - if (not parsed_args.user and not parsed_args.domain and - not parsed_args.group and not parsed_args.project): - msg = _("Incorrect set of arguments provided. " - "See openstack --help for more details") + if ( + not parsed_args.user + and not parsed_args.domain + and not parsed_args.group + and not parsed_args.project + ): + msg = _( + "Incorrect set of arguments provided. " + "See openstack --help for more details" + ) raise exceptions.CommandError(msg) domain_id = None if parsed_args.role_domain: - domain_id = common.find_domain(identity_client, - parsed_args.role_domain).id + domain_id = common.find_domain( + identity_client, parsed_args.role_domain + ).id role = utils.find_resource( - identity_client.roles, - parsed_args.role, - domain_id=domain_id + identity_client.roles, parsed_args.role, domain_id=domain_id ) kwargs = _process_identity_and_resource_options( - parsed_args, self.app.client_manager.identity, - validate_actor_existence=False + parsed_args, + self.app.client_manager.identity, + validate_actor_existence=False, ) identity_client.roles.revoke(role.id, **kwargs) @@ -381,17 +412,21 @@ class SetRole(command.Command): domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain( + identity_client, parsed_args.domain + ).id options = common.get_immutable_options(parsed_args) - role = utils.find_resource(identity_client.roles, - parsed_args.role, - domain_id=domain_id) + role = utils.find_resource( + identity_client.roles, parsed_args.role, domain_id=domain_id + ) - identity_client.roles.update(role.id, name=parsed_args.name, - description=parsed_args.description, - options=options) + identity_client.roles.update( + role.id, + name=parsed_args.name, + description=parsed_args.description, + options=options, + ) class ShowRole(command.ShowOne): @@ -416,12 +451,13 @@ class ShowRole(command.ShowOne): domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain( + identity_client, parsed_args.domain + ).id - role = utils.find_resource(identity_client.roles, - parsed_args.role, - domain_id=domain_id) + role = utils.find_resource( + identity_client.roles, parsed_args.role, domain_id=domain_id + ) role._info.pop('links') return zip(*sorted(role._info.items())) diff --git a/openstackclient/identity/v3/role_assignment.py b/openstackclient/identity/v3/role_assignment.py index 9c2f3d24..0be6aafb 100644 --- a/openstackclient/identity/v3/role_assignment.py +++ b/openstackclient/identity/v3/role_assignment.py @@ -84,14 +84,20 @@ class ListRoleAssignment(command.Lister): action="store_true", dest='authproject', help='Only list assignments for the project to which the ' - 'authenticated user\'s token is scoped', + 'authenticated user\'s token is scoped', ) return parser def _as_tuple(self, assignment): - return (assignment.role, assignment.user, assignment.group, - assignment.project, assignment.domain, assignment.system, - assignment.inherited) + return ( + assignment.role, + assignment.user, + assignment.group, + assignment.project, + assignment.domain, + assignment.system, + assignment.inherited, + ) def take_action(self, parsed_args): identity_client = self.app.client_manager.identity @@ -100,13 +106,14 @@ class ListRoleAssignment(command.Lister): role = None role_domain_id = None if parsed_args.role_domain: - role_domain_id = common.find_domain(identity_client, - parsed_args.role_domain).id + role_domain_id = common.find_domain( + identity_client, parsed_args.role_domain + ).id if parsed_args.role: role = utils.find_resource( identity_client.roles, parsed_args.role, - domain_id=role_domain_id + domain_id=role_domain_id, ) user = None @@ -118,10 +125,7 @@ class ListRoleAssignment(command.Lister): ) elif parsed_args.authuser: if auth_ref: - user = common.find_user( - identity_client, - auth_ref.user_id - ) + user = common.find_user(identity_client, auth_ref.user_id) system = None if parsed_args.system: @@ -138,15 +142,15 @@ class ListRoleAssignment(command.Lister): if parsed_args.project: project = common.find_project( identity_client, - common._get_token_resource(identity_client, 'project', - parsed_args.project), + common._get_token_resource( + identity_client, 'project', parsed_args.project + ), parsed_args.project_domain, ) elif parsed_args.authproject: if auth_ref: project = common.find_project( - identity_client, - auth_ref.project_id + identity_client, auth_ref.project_id ) group = None @@ -160,7 +164,13 @@ class ListRoleAssignment(command.Lister): include_names = True if parsed_args.names else False effective = True if parsed_args.effective else False columns = ( - 'Role', 'User', 'Group', 'Project', 'Domain', 'System', 'Inherited' + 'Role', + 'User', + 'Group', + 'Project', + 'Domain', + 'System', + 'Inherited', ) inherited_to = 'projects' if parsed_args.inherited else None @@ -173,7 +183,8 @@ class ListRoleAssignment(command.Lister): role=role, effective=effective, os_inherit_extension_inherited_to=inherited_to, - include_names=include_names) + include_names=include_names, + ) data_parsed = [] for assignment in data: @@ -181,8 +192,12 @@ class ListRoleAssignment(command.Lister): scope = assignment.scope if 'project' in scope: if include_names: - prj = '@'.join([scope['project']['name'], - scope['project']['domain']['name']]) + prj = '@'.join( + [ + scope['project']['name'], + scope['project']['domain']['name'], + ] + ) setattr(assignment, 'project', prj) else: setattr(assignment, 'project', scope['project']['id']) @@ -215,16 +230,24 @@ class ListRoleAssignment(command.Lister): if hasattr(assignment, 'user'): if include_names: - usr = '@'.join([assignment.user['name'], - assignment.user['domain']['name']]) + usr = '@'.join( + [ + assignment.user['name'], + assignment.user['domain']['name'], + ] + ) setattr(assignment, 'user', usr) else: setattr(assignment, 'user', assignment.user['id']) assignment.group = '' elif hasattr(assignment, 'group'): if include_names: - grp = '@'.join([assignment.group['name'], - assignment.group['domain']['name']]) + grp = '@'.join( + [ + assignment.group['name'], + assignment.group['domain']['name'], + ] + ) setattr(assignment, 'group', grp) else: setattr(assignment, 'group', assignment.group['id']) diff --git a/openstackclient/identity/v3/service.py b/openstackclient/identity/v3/service.py index 9dc66962..fde1799c 100644 --- a/openstackclient/identity/v3/service.py +++ b/openstackclient/identity/v3/service.py @@ -101,14 +101,19 @@ class DeleteService(command.Command): identity_client.services.delete(service.id) except Exception as e: result += 1 - LOG.error(_("Failed to delete consumer with type, " - "name or ID '%(service)s': %(e)s"), - {'service': i, 'e': e}) + LOG.error( + _( + "Failed to delete consumer with type, " + "name or ID '%(service)s': %(e)s" + ), + {'service': i, 'e': e}, + ) if result > 0: total = len(parsed_args.service) - msg = (_("%(result)s of %(total)s services failed " - "to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s services failed " "to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -126,7 +131,6 @@ class ListService(command.Lister): return parser def take_action(self, parsed_args): - if parsed_args.long: columns = ('ID', 'Name', 'Type', 'Description', 'Enabled') else: @@ -179,8 +183,7 @@ class SetService(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - service = common.find_service(identity_client, - parsed_args.service) + service = common.find_service(identity_client, parsed_args.service) kwargs = {} if parsed_args.type: kwargs['type'] = parsed_args.type @@ -193,10 +196,7 @@ class SetService(command.Command): if parsed_args.disable: kwargs['enabled'] = False - identity_client.services.update( - service.id, - **kwargs - ) + identity_client.services.update(service.id, **kwargs) class ShowService(command.ShowOne): diff --git a/openstackclient/identity/v3/service_provider.py b/openstackclient/identity/v3/service_provider.py index e106c787..e5af7492 100644 --- a/openstackclient/identity/v3/service_provider.py +++ b/openstackclient/identity/v3/service_provider.py @@ -39,8 +39,10 @@ class CreateServiceProvider(command.ShowOne): '--auth-url', metavar='<auth-url>', required=True, - help=_('Authentication URL of remote federated service provider ' - '(required)'), + help=_( + 'Authentication URL of remote federated service provider ' + '(required)' + ), ) parser.add_argument( '--description', @@ -51,8 +53,10 @@ class CreateServiceProvider(command.ShowOne): '--service-provider-url', metavar='<sp-url>', required=True, - help=_('A service URL where SAML assertions are being sent ' - '(required)'), + help=_( + 'A service URL where SAML assertions are being sent ' + '(required)' + ), ) enable_service_provider = parser.add_mutually_exclusive_group() @@ -79,7 +83,8 @@ class CreateServiceProvider(command.ShowOne): auth_url=parsed_args.auth_url, description=parsed_args.description, enabled=parsed_args.enabled, - sp_url=parsed_args.service_provider_url) + sp_url=parsed_args.service_provider_url, + ) sp._info.pop('links', None) return zip(*sorted(sp._info.items())) @@ -106,14 +111,20 @@ class DeleteServiceProvider(command.Command): service_client.federation.service_providers.delete(i) except Exception as e: result += 1 - LOG.error(_("Failed to delete service provider with " - "name or ID '%(provider)s': %(e)s"), - {'provider': i, 'e': e}) + LOG.error( + _( + "Failed to delete service provider with " + "name or ID '%(provider)s': %(e)s" + ), + {'provider': i, 'e': e}, + ) if result > 0: total = len(parsed_args.service_provider) - msg = (_("%(result)s of %(total)s service providers failed" - " to delete.") % {'result': result, 'total': total}) + msg = _( + "%(result)s of %(total)s service providers failed" + " to delete." + ) % {'result': result, 'total': total} raise exceptions.CommandError(msg) @@ -125,11 +136,17 @@ class ListServiceProvider(command.Lister): data = service_client.federation.service_providers.list() column_headers = ('ID', 'Enabled', 'Description', 'Auth URL') - return (column_headers, - (utils.get_item_properties( - s, column_headers, + return ( + column_headers, + ( + utils.get_item_properties( + s, + column_headers, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class SetServiceProvider(command.Command): @@ -145,8 +162,10 @@ class SetServiceProvider(command.Command): parser.add_argument( '--auth-url', metavar='<auth-url>', - help=_('New Authentication URL of remote ' - 'federated service provider'), + help=_( + 'New Authentication URL of remote ' + 'federated service provider' + ), ) parser.add_argument( @@ -207,7 +226,8 @@ class ShowServiceProvider(command.ShowOne): service_provider = utils.find_resource( service_client.federation.service_providers, parsed_args.service_provider, - id=parsed_args.service_provider) + id=parsed_args.service_provider, + ) service_provider._info.pop('links', None) return zip(*sorted(service_provider._info.items())) diff --git a/openstackclient/identity/v3/tag.py b/openstackclient/identity/v3/tag.py index abf022d4..60cfb4be 100644 --- a/openstackclient/identity/v3/tag.py +++ b/openstackclient/identity/v3/tag.py @@ -16,7 +16,6 @@ from openstackclient.i18n import _ class _CommaListAction(argparse.Action): - def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, values.split(',')) @@ -26,29 +25,41 @@ def add_tag_filtering_option_to_parser(parser, collection_name): '--tags', metavar='<tag>[,<tag>,...]', action=_CommaListAction, - help=_('List %s which have all given tag(s) ' - '(Comma-separated list of tags)') % collection_name + help=_( + 'List %s which have all given tag(s) ' + '(Comma-separated list of tags)' + ) + % collection_name, ) parser.add_argument( '--tags-any', metavar='<tag>[,<tag>,...]', action=_CommaListAction, - help=_('List %s which have any given tag(s) ' - '(Comma-separated list of tags)') % collection_name + help=_( + 'List %s which have any given tag(s) ' + '(Comma-separated list of tags)' + ) + % collection_name, ) parser.add_argument( '--not-tags', metavar='<tag>[,<tag>,...]', action=_CommaListAction, - help=_('Exclude %s which have all given tag(s) ' - '(Comma-separated list of tags)') % collection_name + help=_( + 'Exclude %s which have all given tag(s) ' + '(Comma-separated list of tags)' + ) + % collection_name, ) parser.add_argument( '--not-tags-any', metavar='<tag>[,<tag>,...]', action=_CommaListAction, - help=_('Exclude %s which have any given tag(s) ' - '(Comma-separated list of tags)') % collection_name + help=_( + 'Exclude %s which have any given tag(s) ' + '(Comma-separated list of tags)' + ) + % collection_name, ) @@ -71,8 +82,10 @@ def add_tag_option_to_parser_for_create(parser, resource_name): dest='tags', metavar='<tag>', default=[], - help=_('Tag to be added to the %s ' - '(repeat option to set multiple tags)') % resource_name + help=_( + 'Tag to be added to the %s ' '(repeat option to set multiple tags)' + ) + % resource_name, ) @@ -83,22 +96,30 @@ def add_tag_option_to_parser_for_set(parser, resource_name): dest='tags', metavar='<tag>', default=[], - help=_('Tag to be added to the %s ' - '(repeat option to set multiple tags)') % resource_name + help=_( + 'Tag to be added to the %s ' '(repeat option to set multiple tags)' + ) + % resource_name, ) parser.add_argument( '--clear-tags', action='store_true', - help=_('Clear tags associated with the %s. Specify ' - 'both --tag and --clear-tags to overwrite ' - 'current tags') % resource_name + help=_( + 'Clear tags associated with the %s. Specify ' + 'both --tag and --clear-tags to overwrite ' + 'current tags' + ) + % resource_name, ) parser.add_argument( '--remove-tag', metavar='<tag>', default=[], - help=_('Tag to be deleted from the %s ' - '(repeat option to delete multiple tags)') % resource_name + help=_( + 'Tag to be deleted from the %s ' + '(repeat option to delete multiple tags)' + ) + % resource_name, ) @@ -112,5 +133,4 @@ def update_tags_in_args(parsed_args, obj, args): args['tags'] = list(set(obj.tags)) return if parsed_args.tags: - args['tags'] = list(set(obj.tags).union( - set(parsed_args.tags))) + args['tags'] = list(set(obj.tags).union(set(parsed_args.tags))) diff --git a/openstackclient/identity/v3/token.py b/openstackclient/identity/v3/token.py index f14dd8bc..c11de358 100644 --- a/openstackclient/identity/v3/token.py +++ b/openstackclient/identity/v3/token.py @@ -40,8 +40,10 @@ class AuthorizeRequestToken(command.ShowOne): action='append', default=[], required=True, - help=_('Roles to authorize (name or ID) ' - '(repeat option to set multiple values) (required)'), + help=_( + 'Roles to authorize (name or ID) ' + '(repeat option to set multiple values) (required)' + ), ) return parser @@ -58,8 +60,8 @@ class AuthorizeRequestToken(command.ShowOne): roles.append(role_id) verifier_pin = identity_client.oauth1.request_tokens.authorize( - parsed_args.request_key, - roles) + parsed_args.request_key, roles + ) return zip(*sorted(verifier_pin._info.items())) @@ -73,40 +75,43 @@ class CreateAccessToken(command.ShowOne): '--consumer-key', metavar='<consumer-key>', help=_('Consumer key (required)'), - required=True + required=True, ) parser.add_argument( '--consumer-secret', metavar='<consumer-secret>', help=_('Consumer secret (required)'), - required=True + required=True, ) parser.add_argument( '--request-key', metavar='<request-key>', help=_('Request token to exchange for access token (required)'), - required=True + required=True, ) parser.add_argument( '--request-secret', metavar='<request-secret>', help=_('Secret associated with <request-key> (required)'), - required=True + required=True, ) parser.add_argument( '--verifier', metavar='<verifier>', help=_('Verifier associated with <request-key> (required)'), - required=True + required=True, ) return parser def take_action(self, parsed_args): token_client = self.app.client_manager.identity.oauth1.access_tokens access_token = token_client.create( - parsed_args.consumer_key, parsed_args.consumer_secret, - parsed_args.request_key, parsed_args.request_secret, - parsed_args.verifier) + parsed_args.consumer_key, + parsed_args.consumer_secret, + parsed_args.request_key, + parsed_args.request_secret, + parsed_args.verifier, + ) return zip(*sorted(access_token._info.items())) @@ -119,20 +124,22 @@ class CreateRequestToken(command.ShowOne): '--consumer-key', metavar='<consumer-key>', help=_('Consumer key (required)'), - required=True + required=True, ) parser.add_argument( '--consumer-secret', metavar='<consumer-secret>', help=_('Consumer secret (required)'), - required=True + required=True, ) parser.add_argument( '--project', metavar='<project>', - help=_('Project that consumer wants to access (name or ID)' - ' (required)'), - required=True + help=_( + 'Project that consumer wants to access (name or ID)' + ' (required)' + ), + required=True, ) parser.add_argument( '--domain', @@ -146,19 +153,21 @@ class CreateRequestToken(command.ShowOne): if parsed_args.domain: domain = common.find_domain(identity_client, parsed_args.domain) - project = utils.find_resource(identity_client.projects, - parsed_args.project, - domain_id=domain.id) + project = utils.find_resource( + identity_client.projects, + parsed_args.project, + domain_id=domain.id, + ) else: - project = utils.find_resource(identity_client.projects, - parsed_args.project) + project = utils.find_resource( + identity_client.projects, parsed_args.project + ) token_client = identity_client.oauth1.request_tokens request_token = token_client.create( - parsed_args.consumer_key, - parsed_args.consumer_secret, - project.id) + parsed_args.consumer_key, parsed_args.consumer_secret, project.id + ) return zip(*sorted(request_token._info.items())) @@ -176,7 +185,8 @@ class IssueToken(command.ShowOne): auth_ref = self.app.client_manager.auth_ref if not auth_ref: raise exceptions.AuthorizationFailure( - _("Only an authorized user may issue a new token.")) + _("Only an authorized user may issue a new token.") + ) data = {} if auth_ref.auth_token: diff --git a/openstackclient/identity/v3/trust.py b/openstackclient/identity/v3/trust.py index 61273f41..f2899d59 100644 --- a/openstackclient/identity/v3/trust.py +++ b/openstackclient/identity/v3/trust.py @@ -54,23 +54,29 @@ class CreateTrust(command.ShowOne): metavar='<role>', action='append', default=[], - help=_('Roles to authorize (name or ID) ' - '(repeat option to set multiple values, required)'), - required=True + help=_( + 'Roles to authorize (name or ID) ' + '(repeat option to set multiple values, required)' + ), + required=True, ) parser.add_argument( '--impersonate', dest='impersonate', action='store_true', default=False, - help=_('Tokens generated from the trust will represent <trustor>' - ' (defaults to False)'), + help=_( + 'Tokens generated from the trust will represent <trustor>' + ' (defaults to False)' + ), ) parser.add_argument( '--expiration', metavar='<expiration>', - help=_('Sets an expiration date for the trust' - ' (format of YYYY-mm-ddTHH:MM:SS)'), + help=_( + 'Sets an expiration date for the trust' + ' (format of YYYY-mm-ddTHH:MM:SS)' + ), ) common.add_project_domain_option_to_parser(parser) parser.add_argument( @@ -93,15 +99,15 @@ class CreateTrust(command.ShowOne): # trustee, project and role are optional, but that makes the trust # pointless, and trusts are immutable, so let's enforce it at the # client level. - trustor_id = common.find_user(identity_client, - parsed_args.trustor, - parsed_args.trustor_domain).id - trustee_id = common.find_user(identity_client, - parsed_args.trustee, - parsed_args.trustee_domain).id - project_id = common.find_project(identity_client, - parsed_args.project, - parsed_args.project_domain).id + trustor_id = common.find_user( + identity_client, parsed_args.trustor, parsed_args.trustor_domain + ).id + trustee_id = common.find_user( + identity_client, parsed_args.trustee, parsed_args.trustee_domain + ).id + project_id = common.find_project( + identity_client, parsed_args.project, parsed_args.project_domain + ).id role_ids = [] for role in parsed_args.role: @@ -116,11 +122,13 @@ class CreateTrust(command.ShowOne): expires_at = None if parsed_args.expiration: - expires_at = datetime.datetime.strptime(parsed_args.expiration, - '%Y-%m-%dT%H:%M:%S') + expires_at = datetime.datetime.strptime( + parsed_args.expiration, '%Y-%m-%dT%H:%M:%S' + ) trust = identity_client.trusts.create( - trustee_id, trustor_id, + trustee_id, + trustor_id, impersonation=parsed_args.impersonate, project=project_id, role_ids=role_ids, @@ -157,19 +165,24 @@ class DeleteTrust(command.Command): errors = 0 for trust in parsed_args.trust: try: - trust_obj = utils.find_resource(identity_client.trusts, - trust) + trust_obj = utils.find_resource(identity_client.trusts, trust) identity_client.trusts.delete(trust_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete trust with " - "name or ID '%(trust)s': %(e)s"), - {'trust': trust, 'e': e}) + LOG.error( + _( + "Failed to delete trust with " + "name or ID '%(trust)s': %(e)s" + ), + {'trust': trust, 'e': e}, + ) if errors > 0: total = len(parsed_args.trust) - msg = (_("%(errors)s of %(total)s trusts failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s trusts failed " "to delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) @@ -210,12 +223,14 @@ class ListTrust(command.Lister): 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, - ]): + 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) @@ -229,10 +244,7 @@ class ListTrust(command.Lister): if parsed_args.authuser: if auth_ref: - user = common.find_user( - identity_client, - auth_ref.user_id - ) + 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 @@ -262,14 +274,26 @@ class ListTrust(command.Lister): trustee_user=trustee, ) - columns = ('ID', 'Expires At', 'Impersonation', 'Project ID', - 'Trustee User ID', 'Trustor User ID') + columns = ( + 'ID', + 'Expires At', + 'Impersonation', + 'Project ID', + 'Trustee User ID', + 'Trustor User ID', + ) - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ShowTrust(command.ShowOne): @@ -286,8 +310,7 @@ class ShowTrust(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - trust = utils.find_resource(identity_client.trusts, - parsed_args.trust) + trust = utils.find_resource(identity_client.trusts, parsed_args.trust) trust._info.pop('roles_links', None) trust._info.pop('links', None) diff --git a/openstackclient/identity/v3/unscoped_saml.py b/openstackclient/identity/v3/unscoped_saml.py index f7598f17..d26035d3 100644 --- a/openstackclient/identity/v3/unscoped_saml.py +++ b/openstackclient/identity/v3/unscoped_saml.py @@ -30,11 +30,17 @@ class ListAccessibleDomains(command.Lister): columns = ('ID', 'Enabled', 'Name', 'Description') identity_client = self.app.client_manager.identity data = identity_client.federation.domains.list() - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) class ListAccessibleProjects(command.Lister): @@ -44,8 +50,14 @@ class ListAccessibleProjects(command.Lister): columns = ('ID', 'Domain ID', 'Enabled', 'Name') identity_client = self.app.client_manager.identity data = identity_client.federation.projects.list() - return (columns, - (utils.get_item_properties( - s, columns, + return ( + columns, + ( + utils.get_item_properties( + s, + columns, formatters={}, - ) for s in data)) + ) + for s in data + ), + ) diff --git a/openstackclient/identity/v3/user.py b/openstackclient/identity/v3/user.py index cbc112a0..dfc66b3d 100644 --- a/openstackclient/identity/v3/user.py +++ b/openstackclient/identity/v3/user.py @@ -53,8 +53,9 @@ def _get_options_for_user(identity_client, parsed_args): if parsed_args.disable_multi_factor_auth: options['multi_factor_auth_enabled'] = False if parsed_args.multi_factor_auth_rule: - auth_rules = [rule.split(",") for rule in - parsed_args.multi_factor_auth_rule] + auth_rules = [ + rule.split(",") for rule in parsed_args.multi_factor_auth_rule + ] if auth_rules: options['multi_factor_auth_rules'] = auth_rules return options @@ -66,54 +67,70 @@ def _add_user_options(parser): parser.add_argument( '--ignore-lockout-failure-attempts', action="store_true", - help=_('Opt into ignoring the number of times a user has ' - 'authenticated and locking out the user as a result'), + help=_( + 'Opt into ignoring the number of times a user has ' + 'authenticated and locking out the user as a result' + ), ) parser.add_argument( '--no-ignore-lockout-failure-attempts', action="store_true", - help=_('Opt out of ignoring the number of times a user has ' - 'authenticated and locking out the user as a result'), + help=_( + 'Opt out of ignoring the number of times a user has ' + 'authenticated and locking out the user as a result' + ), ) parser.add_argument( '--ignore-password-expiry', action="store_true", - help=_('Opt into allowing user to continue using passwords that ' - 'may be expired'), + help=_( + 'Opt into allowing user to continue using passwords that ' + 'may be expired' + ), ) parser.add_argument( '--no-ignore-password-expiry', action="store_true", - help=_('Opt out of allowing user to continue using passwords ' - 'that may be expired'), + help=_( + 'Opt out of allowing user to continue using passwords ' + 'that may be expired' + ), ) parser.add_argument( '--ignore-change-password-upon-first-use', action="store_true", - help=_('Control if a user should be forced to change their password ' - 'immediately after they log into keystone for the first time. ' - 'Opt into ignoring the user to change their password during ' - 'first time login in keystone'), + help=_( + 'Control if a user should be forced to change their password ' + 'immediately after they log into keystone for the first time. ' + 'Opt into ignoring the user to change their password during ' + 'first time login in keystone' + ), ) parser.add_argument( '--no-ignore-change-password-upon-first-use', action="store_true", - help=_('Control if a user should be forced to change their password ' - 'immediately after they log into keystone for the first time. ' - 'Opt out of ignoring the user to change their password during ' - 'first time login in keystone'), + help=_( + 'Control if a user should be forced to change their password ' + 'immediately after they log into keystone for the first time. ' + 'Opt out of ignoring the user to change their password during ' + 'first time login in keystone' + ), ) parser.add_argument( '--enable-lock-password', action="store_true", - help=_('Disables the ability for a user to change its password ' - 'through self-service APIs'), + help=_( + 'Disables the ability for a user to change its password ' + 'through self-service APIs' + ), ) parser.add_argument( '--disable-lock-password', action="store_true", - help=_('Enables the ability for a user to change its password ' - 'through self-service APIs'), + help=_( + 'Enables the ability for a user to change its password ' + 'through self-service APIs' + ), ) parser.add_argument( '--enable-multi-factor-auth', @@ -130,11 +147,13 @@ def _add_user_options(parser): metavar='<rule>', action="append", default=[], - help=_('Set multi-factor auth rules. For example, to set a rule ' - 'requiring the "password" and "totp" auth methods to be ' - 'provided, use: "--multi-factor-auth-rule password,totp". ' - 'May be provided multiple times to set different rule ' - 'combinations.') + help=_( + 'Set multi-factor auth rules. For example, to set a rule ' + 'requiring the "password" and "totp" auth methods to be ' + 'provided, use: "--multi-factor-auth-rule password,totp". ' + 'May be provided multiple times to set different rule ' + 'combinations.' + ), ) @@ -205,14 +224,17 @@ class CreateUser(command.ShowOne): project_id = None if parsed_args.project: - project_id = common.find_project(identity_client, - parsed_args.project, - parsed_args.project_domain).id + project_id = common.find_project( + identity_client, + parsed_args.project, + parsed_args.project_domain, + ).id domain_id = None if parsed_args.domain: - domain_id = common.find_domain(identity_client, - parsed_args.domain).id + domain_id = common.find_domain( + identity_client, parsed_args.domain + ).id enabled = True if parsed_args.disable: @@ -221,8 +243,12 @@ class CreateUser(command.ShowOne): parsed_args.password = utils.get_password(self.app.stdin) if not parsed_args.password: - LOG.warning(_("No password was supplied, authentication will fail " - "when a user does not have a password.")) + LOG.warning( + _( + "No password was supplied, authentication will fail " + "when a user does not have a password." + ) + ) options = _get_options_for_user(identity_client, parsed_args) try: @@ -238,9 +264,11 @@ class CreateUser(command.ShowOne): ) except ks_exc.Conflict: if parsed_args.or_show: - user = utils.find_resource(identity_client.users, - parsed_args.name, - domain_id=domain_id) + user = utils.find_resource( + identity_client.users, + parsed_args.name, + domain_id=domain_id, + ) LOG.info(_('Returning existing user %s'), user.name) else: raise @@ -277,23 +305,28 @@ class DeleteUser(command.Command): for user in parsed_args.users: try: if domain is not None: - user_obj = utils.find_resource(identity_client.users, - user, - domain_id=domain.id) + user_obj = utils.find_resource( + identity_client.users, user, domain_id=domain.id + ) else: - user_obj = utils.find_resource(identity_client.users, - user) + user_obj = utils.find_resource(identity_client.users, user) identity_client.users.delete(user_obj.id) except Exception as e: errors += 1 - LOG.error(_("Failed to delete user with " - "name or ID '%(user)s': %(e)s"), - {'user': user, 'e': e}) + LOG.error( + _( + "Failed to delete user with " + "name or ID '%(user)s': %(e)s" + ), + {'user': user, 'e': e}, + ) if errors > 0: total = len(parsed_args.users) - msg = (_("%(errors)s of %(total)s users failed " - "to delete.") % {'errors': errors, 'total': total}) + msg = _("%(errors)s of %(total)s users failed " "to delete.") % { + 'errors': errors, + 'total': total, + } raise exceptions.CommandError(msg) @@ -331,21 +364,20 @@ class ListUser(command.Lister): domain = None if parsed_args.domain: - domain = common.find_domain(identity_client, - parsed_args.domain).id + domain = common.find_domain(identity_client, parsed_args.domain).id group = None if parsed_args.group: - group = common.find_group(identity_client, - parsed_args.group, - parsed_args.domain).id + group = common.find_group( + identity_client, parsed_args.group, parsed_args.domain + ).id if parsed_args.project: if domain is not None: project = utils.find_resource( identity_client.projects, parsed_args.project, - domain_id=domain + domain_id=domain, ).id else: project = utils.find_resource( @@ -354,7 +386,8 @@ class ListUser(command.Lister): ).id assignments = identity_client.role_assignments.list( - project=project) + project=project + ) # NOTE(stevemar): If a user has more than one role on a project # then they will have two entries in the returned data. Since we @@ -379,8 +412,15 @@ class ListUser(command.Lister): # Column handling if parsed_args.long: - columns = ['ID', 'Name', 'Default Project Id', 'Domain Id', - 'Description', 'Email', 'Enabled'] + columns = [ + 'ID', + 'Name', + 'Default Project Id', + 'Domain Id', + 'Description', + 'Email', + 'Enabled', + ] column_headers = copy.deepcopy(columns) column_headers[2] = 'Project' column_headers[3] = 'Domain' @@ -390,10 +430,14 @@ class ListUser(command.Lister): return ( column_headers, - (utils.get_item_properties( - s, columns, - formatters={}, - ) for s in data) + ( + utils.get_item_properties( + s, + columns, + formatters={}, + ) + for s in data + ), ) @@ -415,8 +459,10 @@ class SetUser(command.Command): parser.add_argument( '--domain', metavar='<domain>', - help=_('Domain the user belongs to (name or ID). This can be ' - 'used in case collisions between user names exist.'), + help=_( + 'Domain the user belongs to (name or ID). This can be ' + 'used in case collisions between user names exist.' + ), ) parser.add_argument( '--project', @@ -467,17 +513,21 @@ class SetUser(command.Command): parsed_args.password = utils.get_password(self.app.stdin) if '' == parsed_args.password: - LOG.warning(_("No password was supplied, authentication will fail " - "when a user does not have a password.")) + LOG.warning( + _( + "No password was supplied, authentication will fail " + "when a user does not have a password." + ) + ) - user_str = common._get_token_resource(identity_client, 'user', - parsed_args.user, - parsed_args.domain) + user_str = common._get_token_resource( + identity_client, 'user', parsed_args.user, parsed_args.domain + ) if parsed_args.domain: domain = common.find_domain(identity_client, parsed_args.domain) - user = utils.find_resource(identity_client.users, - user_str, - domain_id=domain.id) + user = utils.find_resource( + identity_client.users, user_str, domain_id=domain.id + ) else: user = utils.find_resource( identity_client.users, @@ -494,9 +544,11 @@ class SetUser(command.Command): if parsed_args.description: kwargs['description'] = parsed_args.description if parsed_args.project: - project_id = common.find_project(identity_client, - parsed_args.project, - parsed_args.project_domain).id + project_id = common.find_project( + identity_client, + parsed_args.project, + parsed_args.project_domain, + ).id kwargs['default_project'] = project_id kwargs['enabled'] = user.enabled if parsed_args.enable: @@ -556,16 +608,22 @@ class SetPasswordUser(command.Command): current_password = parsed_args.original_password if current_password is None: current_password = utils.get_password( - self.app.stdin, prompt="Current Password:", confirm=False) + self.app.stdin, prompt="Current Password:", confirm=False + ) password = parsed_args.password if password is None: password = utils.get_password( - self.app.stdin, prompt="New Password:") + self.app.stdin, prompt="New Password:" + ) if '' == password: - LOG.warning(_("No password was supplied, authentication will fail " - "when a user does not have a password.")) + LOG.warning( + _( + "No password was supplied, authentication will fail " + "when a user does not have a password." + ) + ) identity_client.users.update_password(current_password, password) @@ -590,17 +648,16 @@ class ShowUser(command.ShowOne): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - user_str = common._get_token_resource(identity_client, 'user', - parsed_args.user, - parsed_args.domain) + user_str = common._get_token_resource( + identity_client, 'user', parsed_args.user, parsed_args.domain + ) if parsed_args.domain: domain = common.find_domain(identity_client, parsed_args.domain) - user = utils.find_resource(identity_client.users, - user_str, - domain_id=domain.id) + user = utils.find_resource( + identity_client.users, user_str, domain_id=domain.id + ) else: - user = utils.find_resource(identity_client.users, - user_str) + user = utils.find_resource(identity_client.users, user_str) user._info.pop('links') return zip(*sorted(user._info.items())) |