Merge "pre-commit: Migrate bandit to ruff"

This commit is contained in:
Zuul 2024-09-13 17:35:52 +00:00 committed by Gerrit Code Review
commit eaec72e2ba
15 changed files with 38 additions and 37 deletions

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

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

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

@ -2912,10 +2912,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
@ -2933,10 +2933,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
@ -2952,19 +2952,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.
@ -4869,7 +4869,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):

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

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

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

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

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

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

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

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

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

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

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