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 - id: ruff
args: ['--fix'] args: ['--fix']
- id: ruff-format - 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 - repo: https://opendev.org/openstack/hacking
rev: 7.0.0 rev: 7.0.0
hooks: hooks:

@ -101,7 +101,7 @@ class ClientManager(clientmanager.ClientManager):
# expect, delete fake token and endpoint, then try to # expect, delete fake token and endpoint, then try to
# load auth plugin again with user specified options. # load auth plugin again with user specified options.
# We know it looks ugly, but it's necessary. # 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 # restore original auth_type
self._cli_options.config['auth_type'] = self._original_auth_type self._cli_options.config['auth_type'] = self._original_auth_type
del self._cli_options.config['auth']['token'] del self._cli_options.config['auth']['token']

@ -111,8 +111,8 @@ class ListModule(command.ShowOne):
data[k] = mods[k].version.__version__ data[k] = mods[k].version.__version__
else: else:
data[k] = mods[k].__version__ data[k] = mods[k].__version__
except Exception: except Exception: # noqa: S110
# Catch all exceptions, just skip it # Catch all exceptions, just skip it
pass # nosec: B110 pass
return zip(*sorted(data.items())) return zip(*sorted(data.items()))

@ -2912,10 +2912,10 @@ class ListServer(command.Lister):
for image_id in image_ids: for image_id in image_ids:
try: try:
images[image_id] = image_client.get_image(image_id) images[image_id] = image_client.get_image(image_id)
except Exception: except Exception: # noqa: S110
# retrieving image names is not crucial, so we swallow # retrieving image names is not crucial, so we swallow
# any exceptions # any exceptions
pass # nosec: B110 pass
else: else:
try: try:
# some deployments can have *loads* of images so we only # some deployments can have *loads* of images so we only
@ -2933,10 +2933,10 @@ class ListServer(command.Lister):
) )
for i in images_list: for i in images_list:
images[i.id] = i images[i.id] = i
except Exception: except Exception: # noqa: S110
# retrieving image names is not crucial, so we swallow any # retrieving image names is not crucial, so we swallow any
# exceptions # exceptions
pass # nosec: B110 pass
# create a dict that maps flavor_id to flavor object, which is used # 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 # 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( flavors[f_id] = compute_client.find_flavor(
f_id, ignore_missing=False f_id, ignore_missing=False
) )
except Exception: except Exception: # noqa: S110
# retrieving flavor names is not crucial, so we swallow # retrieving flavor names is not crucial, so we swallow
# any exceptions # any exceptions
pass # nosec: B110 pass
else: else:
try: try:
flavors_list = compute_client.flavors(is_public=None) flavors_list = compute_client.flavors(is_public=None)
for i in flavors_list: for i in flavors_list:
flavors[i.id] = i flavors[i.id] = i
except Exception: except Exception: # noqa: S110
# retrieving flavor names is not crucial, so we swallow any # retrieving flavor names is not crucial, so we swallow any
# exceptions # exceptions
pass # nosec: B110 pass
# Populate image_name, image_id, flavor_name and flavor_id attributes # Populate image_name, image_id, flavor_name and flavor_id attributes
# of server objects so that we can display those columns. # of server objects so that we can display those columns.
@ -4869,7 +4869,7 @@ class SshServer(command.Command):
LOG.debug(f"ssh command: {cmd}") LOG.debug(f"ssh command: {cmd}")
# we intentionally pass through user-provided arguments and run this in # we intentionally pass through user-provided arguments and run this in
# the user's shell # the user's shell
os.system(cmd) # nosec: B605 os.system(cmd) # noqa: S605
class StartServer(command.Command): class StartServer(command.Command):

@ -180,9 +180,9 @@ class ListUsage(command.Lister):
try: try:
for p in self.app.client_manager.identity.projects.list(): for p in self.app.client_manager.identity.projects.list():
project_cache[p.id] = p project_cache[p.id] = p
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
if parsed_args.formatter == 'table' and len(usage_list) > 0: if parsed_args.formatter == 'table' and len(usage_list) > 0:
self.app.stdout.write( self.app.stdout.write(

@ -250,9 +250,9 @@ class ListUser(command.Lister):
try: try:
for p in identity_client.tenants.list(): for p in identity_client.tenants.list():
project_cache[p.id] = p project_cache[p.id] = p
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
formatters['tenantId'] = functools.partial( formatters['tenantId'] = functools.partial(
ProjectColumn, project_cache=project_cache ProjectColumn, project_cache=project_cache
) )

@ -422,9 +422,9 @@ class ListVolume(command.Lister):
compute_client = self.app.client_manager.sdk_connection.compute compute_client = self.app.client_manager.sdk_connection.compute
for s in compute_client.servers(): for s in compute_client.servers():
server_cache[s.id] = s server_cache[s.id] = s
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
AttachmentsColumnWithCache = functools.partial( AttachmentsColumnWithCache = functools.partial(
AttachmentsColumn, server_cache=server_cache AttachmentsColumn, server_cache=server_cache
) )

@ -215,9 +215,9 @@ class ListVolumeBackup(command.Lister):
try: try:
for s in volume_client.volumes.list(): for s in volume_client.volumes.list():
volume_cache[s.id] = s volume_cache[s.id] = s
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
VolumeIdColumnWithCache = functools.partial( VolumeIdColumnWithCache = functools.partial(
VolumeIdColumn, volume_cache=volume_cache VolumeIdColumn, volume_cache=volume_cache
) )

@ -242,9 +242,9 @@ class ListVolumeSnapshot(command.Lister):
try: try:
for s in volume_client.volumes.list(): for s in volume_client.volumes.list():
volume_cache[s.id] = s volume_cache[s.id] = s
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
VolumeIdColumnWithCache = functools.partial( VolumeIdColumnWithCache = functools.partial(
VolumeIdColumn, volume_cache=volume_cache VolumeIdColumn, volume_cache=volume_cache
) )

@ -511,9 +511,9 @@ class ListVolume(command.Lister):
compute_client = self.app.client_manager.sdk_connection.compute compute_client = self.app.client_manager.sdk_connection.compute
for s in compute_client.servers(): for s in compute_client.servers():
server_cache[s.id] = s server_cache[s.id] = s
except sdk_exceptions.SDKException: except sdk_exceptions.SDKException: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
AttachmentsColumnWithCache = functools.partial( AttachmentsColumnWithCache = functools.partial(
AttachmentsColumn, server_cache=server_cache AttachmentsColumn, server_cache=server_cache
) )

@ -267,9 +267,9 @@ class ListVolumeBackup(command.Lister):
try: try:
for s in volume_client.volumes(): for s in volume_client.volumes():
volume_cache[s.id] = s volume_cache[s.id] = s
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
_VolumeIdColumn = functools.partial( _VolumeIdColumn = functools.partial(
VolumeIdColumn, volume_cache=volume_cache VolumeIdColumn, volume_cache=volume_cache

@ -287,9 +287,9 @@ class ListVolumeSnapshot(command.Lister):
try: try:
for s in volume_client.volumes.list(): for s in volume_client.volumes.list():
volume_cache[s.id] = s volume_cache[s.id] = s
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
_VolumeIdColumn = functools.partial( _VolumeIdColumn = functools.partial(
VolumeIdColumn, volume_cache=volume_cache VolumeIdColumn, volume_cache=volume_cache
) )

@ -526,9 +526,9 @@ class ListVolume(command.Lister):
compute_client = self.app.client_manager.sdk_connection.compute compute_client = self.app.client_manager.sdk_connection.compute
for s in compute_client.servers(): for s in compute_client.servers():
server_cache[s.id] = s server_cache[s.id] = s
except sdk_exceptions.SDKException: except sdk_exceptions.SDKException: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
AttachmentsColumnWithCache = functools.partial( AttachmentsColumnWithCache = functools.partial(
AttachmentsColumn, server_cache=server_cache AttachmentsColumn, server_cache=server_cache
) )

@ -323,9 +323,9 @@ class ListVolumeBackup(command.Lister):
try: try:
for s in volume_client.volumes(): for s in volume_client.volumes():
volume_cache[s.id] = s volume_cache[s.id] = s
except Exception: except Exception: # noqa: S110
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass
_VolumeIdColumn = functools.partial( _VolumeIdColumn = functools.partial(
VolumeIdColumn, volume_cache=volume_cache VolumeIdColumn, volume_cache=volume_cache

@ -4,3 +4,9 @@ line-length = 79
[tool.ruff.format] [tool.ruff.format]
quote-style = "preserve" quote-style = "preserve"
docstring-code-format = true docstring-code-format = true
[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "S"]
[tool.ruff.lint.per-file-ignores]
"openstackclient/tests/*" = ["S"]