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 <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-09-12 18:00:48 +01:00
parent e60ca0f898
commit fc6852cd94
15 changed files with 38 additions and 37 deletions

View File

@ -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:

View File

@ -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']

View File

@ -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()))

View File

@ -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):

View File

@ -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(

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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

View File

@ -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
)

View File

@ -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
)

View File

@ -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

View File

@ -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"]