From fc6852cd94973c45b7e8c6453178e6ab46472d5e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 12 Sep 2024 18:00:48 +0100 Subject: [PATCH] pre-commit: Migrate bandit to ruff The name of the errors change and we need to move things around a little, but it's otherwise a straight swap. Change-Id: I0a19765ebeaa14c0534faa1542165b76ed2bf4e2 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 5 ----- openstackclient/common/clientmanager.py | 2 +- openstackclient/common/module.py | 4 ++-- openstackclient/compute/v2/server.py | 18 +++++++++--------- openstackclient/compute/v2/usage.py | 4 ++-- openstackclient/identity/v2_0/user.py | 4 ++-- openstackclient/volume/v1/volume.py | 4 ++-- openstackclient/volume/v1/volume_backup.py | 4 ++-- openstackclient/volume/v1/volume_snapshot.py | 4 ++-- openstackclient/volume/v2/volume.py | 4 ++-- openstackclient/volume/v2/volume_backup.py | 4 ++-- openstackclient/volume/v2/volume_snapshot.py | 4 ++-- openstackclient/volume/v3/volume.py | 4 ++-- openstackclient/volume/v3/volume_backup.py | 4 ++-- pyproject.toml | 6 ++++++ 15 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 838177bd9d..738f7d1920 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,11 +25,6 @@ repos: - id: ruff args: ['--fix'] - id: ruff-format - - repo: https://github.com/PyCQA/bandit - rev: 1.7.9 - hooks: - - id: bandit - args: ['-x', 'tests'] - repo: https://opendev.org/openstack/hacking rev: 7.0.0 hooks: diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index 2e990985b9..d1b470d9e5 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -101,7 +101,7 @@ class ClientManager(clientmanager.ClientManager): # expect, delete fake token and endpoint, then try to # load auth plugin again with user specified options. # We know it looks ugly, but it's necessary. - if self._cli_options.config['auth']['token'] == 'x': + if self._cli_options.config['auth']['token'] == 'x': # noqa: S105 # restore original auth_type self._cli_options.config['auth_type'] = self._original_auth_type del self._cli_options.config['auth']['token'] diff --git a/openstackclient/common/module.py b/openstackclient/common/module.py index e9102561e6..d4a5b955a0 100644 --- a/openstackclient/common/module.py +++ b/openstackclient/common/module.py @@ -111,8 +111,8 @@ class ListModule(command.ShowOne): data[k] = mods[k].version.__version__ else: data[k] = mods[k].__version__ - except Exception: + except Exception: # noqa: S110 # Catch all exceptions, just skip it - pass # nosec: B110 + pass return zip(*sorted(data.items())) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 661453b65a..293e010a72 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -2915,10 +2915,10 @@ class ListServer(command.Lister): for image_id in image_ids: try: images[image_id] = image_client.get_image(image_id) - except Exception: + except Exception: # noqa: S110 # retrieving image names is not crucial, so we swallow # any exceptions - pass # nosec: B110 + pass else: try: # some deployments can have *loads* of images so we only @@ -2936,10 +2936,10 @@ class ListServer(command.Lister): ) for i in images_list: images[i.id] = i - except Exception: + except Exception: # noqa: S110 # retrieving image names is not crucial, so we swallow any # exceptions - pass # nosec: B110 + pass # create a dict that maps flavor_id to flavor object, which is used # to display the "Flavor Name" column. Note that 'flavor.id' is not @@ -2955,19 +2955,19 @@ class ListServer(command.Lister): flavors[f_id] = compute_client.find_flavor( f_id, ignore_missing=False ) - except Exception: + except Exception: # noqa: S110 # retrieving flavor names is not crucial, so we swallow # any exceptions - pass # nosec: B110 + pass else: try: flavors_list = compute_client.flavors(is_public=None) for i in flavors_list: flavors[i.id] = i - except Exception: + except Exception: # noqa: S110 # retrieving flavor names is not crucial, so we swallow any # exceptions - pass # nosec: B110 + pass # Populate image_name, image_id, flavor_name and flavor_id attributes # of server objects so that we can display those columns. @@ -4872,7 +4872,7 @@ class SshServer(command.Command): LOG.debug(f"ssh command: {cmd}") # we intentionally pass through user-provided arguments and run this in # the user's shell - os.system(cmd) # nosec: B605 + os.system(cmd) # noqa: S605 class StartServer(command.Command): diff --git a/openstackclient/compute/v2/usage.py b/openstackclient/compute/v2/usage.py index 84118b9d97..2b3fa6a3f8 100644 --- a/openstackclient/compute/v2/usage.py +++ b/openstackclient/compute/v2/usage.py @@ -180,9 +180,9 @@ class ListUsage(command.Lister): try: for p in self.app.client_manager.identity.projects.list(): project_cache[p.id] = p - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass if parsed_args.formatter == 'table' and len(usage_list) > 0: self.app.stdout.write( diff --git a/openstackclient/identity/v2_0/user.py b/openstackclient/identity/v2_0/user.py index 745a48d117..3625adc7c6 100644 --- a/openstackclient/identity/v2_0/user.py +++ b/openstackclient/identity/v2_0/user.py @@ -250,9 +250,9 @@ class ListUser(command.Lister): try: for p in identity_client.tenants.list(): project_cache[p.id] = p - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass formatters['tenantId'] = functools.partial( ProjectColumn, project_cache=project_cache ) diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py index c60625ee91..3ec995961c 100644 --- a/openstackclient/volume/v1/volume.py +++ b/openstackclient/volume/v1/volume.py @@ -422,9 +422,9 @@ class ListVolume(command.Lister): compute_client = self.app.client_manager.sdk_connection.compute for s in compute_client.servers(): server_cache[s.id] = s - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass AttachmentsColumnWithCache = functools.partial( AttachmentsColumn, server_cache=server_cache ) diff --git a/openstackclient/volume/v1/volume_backup.py b/openstackclient/volume/v1/volume_backup.py index 99d5838099..77aa81dc56 100644 --- a/openstackclient/volume/v1/volume_backup.py +++ b/openstackclient/volume/v1/volume_backup.py @@ -215,9 +215,9 @@ class ListVolumeBackup(command.Lister): try: for s in volume_client.volumes.list(): volume_cache[s.id] = s - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass VolumeIdColumnWithCache = functools.partial( VolumeIdColumn, volume_cache=volume_cache ) diff --git a/openstackclient/volume/v1/volume_snapshot.py b/openstackclient/volume/v1/volume_snapshot.py index 18d8c3d621..4953db1294 100644 --- a/openstackclient/volume/v1/volume_snapshot.py +++ b/openstackclient/volume/v1/volume_snapshot.py @@ -242,9 +242,9 @@ class ListVolumeSnapshot(command.Lister): try: for s in volume_client.volumes.list(): volume_cache[s.id] = s - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass VolumeIdColumnWithCache = functools.partial( VolumeIdColumn, volume_cache=volume_cache ) diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index b5a4a1ffc9..179da19601 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -511,9 +511,9 @@ class ListVolume(command.Lister): compute_client = self.app.client_manager.sdk_connection.compute for s in compute_client.servers(): server_cache[s.id] = s - except sdk_exceptions.SDKException: + except sdk_exceptions.SDKException: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass AttachmentsColumnWithCache = functools.partial( AttachmentsColumn, server_cache=server_cache ) diff --git a/openstackclient/volume/v2/volume_backup.py b/openstackclient/volume/v2/volume_backup.py index e3ac5930df..fd59c0cefd 100644 --- a/openstackclient/volume/v2/volume_backup.py +++ b/openstackclient/volume/v2/volume_backup.py @@ -267,9 +267,9 @@ class ListVolumeBackup(command.Lister): try: for s in volume_client.volumes(): volume_cache[s.id] = s - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass _VolumeIdColumn = functools.partial( VolumeIdColumn, volume_cache=volume_cache diff --git a/openstackclient/volume/v2/volume_snapshot.py b/openstackclient/volume/v2/volume_snapshot.py index 3398f502a0..797fdc8537 100644 --- a/openstackclient/volume/v2/volume_snapshot.py +++ b/openstackclient/volume/v2/volume_snapshot.py @@ -287,9 +287,9 @@ class ListVolumeSnapshot(command.Lister): try: for s in volume_client.volumes.list(): volume_cache[s.id] = s - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass _VolumeIdColumn = functools.partial( VolumeIdColumn, volume_cache=volume_cache ) diff --git a/openstackclient/volume/v3/volume.py b/openstackclient/volume/v3/volume.py index 2a3f13d956..6f705ad6f9 100644 --- a/openstackclient/volume/v3/volume.py +++ b/openstackclient/volume/v3/volume.py @@ -526,9 +526,9 @@ class ListVolume(command.Lister): compute_client = self.app.client_manager.sdk_connection.compute for s in compute_client.servers(): server_cache[s.id] = s - except sdk_exceptions.SDKException: + except sdk_exceptions.SDKException: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass AttachmentsColumnWithCache = functools.partial( AttachmentsColumn, server_cache=server_cache ) diff --git a/openstackclient/volume/v3/volume_backup.py b/openstackclient/volume/v3/volume_backup.py index 7052f608a4..471b4cee14 100644 --- a/openstackclient/volume/v3/volume_backup.py +++ b/openstackclient/volume/v3/volume_backup.py @@ -323,9 +323,9 @@ class ListVolumeBackup(command.Lister): try: for s in volume_client.volumes(): volume_cache[s.id] = s - except Exception: + except Exception: # noqa: S110 # Just forget it if there's any trouble - pass # nosec: B110 + pass _VolumeIdColumn = functools.partial( VolumeIdColumn, volume_cache=volume_cache diff --git a/pyproject.toml b/pyproject.toml index 3ab847ac01..6b13ff2461 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,9 @@ line-length = 79 [tool.ruff.format] quote-style = "preserve" docstring-code-format = true + +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F", "S"] + +[tool.ruff.lint.per-file-ignores] +"openstackclient/tests/*" = ["S"]