diff --git a/changelogs/fragments/1375-lint.yml b/changelogs/fragments/1375-lint.yml new file mode 100644 index 00000000000..cd78796ebc3 --- /dev/null +++ b/changelogs/fragments/1375-lint.yml @@ -0,0 +1,2 @@ +trivial: +- plugins/plugin_utils - minor dark / pylint cleanup (https://github.com/ansible-collections/amazon.aws/pull/1375). diff --git a/plugins/plugin_utils/base.py b/plugins/plugin_utils/base.py index 38919823c0f..e7effb289ab 100644 --- a/plugins/plugin_utils/base.py +++ b/plugins/plugin_utils/base.py @@ -18,7 +18,6 @@ class AWSPluginBase: - def warn(self, message): display.warning(message) @@ -40,14 +39,14 @@ def client(self, service, retry_decorator=None, **extra_params): region, endpoint_url, aws_connect_kwargs = get_aws_connection_info(self) kw_args = dict(region=region, endpoint=endpoint_url, **aws_connect_kwargs) kw_args.update(extra_params) - conn = boto3_conn(self, conn_type='client', resource=service, **kw_args) + conn = boto3_conn(self, conn_type="client", resource=service, **kw_args) return conn if retry_decorator is None else RetryingBotoClientWrapper(conn, retry_decorator) def resource(self, service, **extra_params): region, endpoint_url, aws_connect_kwargs = get_aws_connection_info(self) kw_args = dict(region=region, endpoint=endpoint_url, **aws_connect_kwargs) kw_args.update(extra_params) - return boto3_conn(self, conn_type='resource', resource=service, **kw_args) + return boto3_conn(self, conn_type="resource", resource=service, **kw_args) @property def region(self): @@ -55,7 +54,5 @@ def region(self): def require_aws_sdk(self, botocore_version=None, boto3_version=None): return check_sdk_version_supported( - botocore_version=botocore_version, - boto3_version=boto3_version, - warn=self.warn + botocore_version=botocore_version, boto3_version=boto3_version, warn=self.warn ) diff --git a/plugins/plugin_utils/botocore.py b/plugins/plugin_utils/botocore.py index 203f1fd1af5..a3ca9d88603 100644 --- a/plugins/plugin_utils/botocore.py +++ b/plugins/plugin_utils/botocore.py @@ -29,20 +29,23 @@ def boto3_conn(plugin, conn_type=None, resource=None, region=None, endpoint=None try: return _boto3_conn(conn_type=conn_type, resource=resource, region=region, endpoint=endpoint, **params) except ValueError as e: - plugin.fail_aws("Couldn't connect to AWS: {0}".format(to_native(e))) - except (botocore.exceptions.ProfileNotFound, botocore.exceptions.PartialCredentialsError, - botocore.exceptions.NoCredentialsError, botocore.exceptions.ConfigParseError) as e: + plugin.fail_aws(f"Couldn't connect to AWS: {to_native(e)}") + except ( + botocore.exceptions.ProfileNotFound, + botocore.exceptions.PartialCredentialsError, + botocore.exceptions.NoCredentialsError, + botocore.exceptions.ConfigParseError, + ) as e: plugin.fail_aws(to_native(e)) except botocore.exceptions.NoRegionError: # ansible_name is added in 2.14 - if hasattr(plugin, 'ansible_name'): + if hasattr(plugin, "ansible_name"): plugin.fail_aws( - "The {0} plugin requires a region and none was found in configuration, " - "environment variables or module parameters".format(plugin.ansible_name) + f"The {plugin.ansible_name} plugin requires a region and none was found in configuration, " + "environment variables or module parameters" ) plugin.fail_aws( - "A region is required and none was found in configuration, " - "environment variables or module parameters" + "A region is required and none was found in configuration, environment variables or module parameters" ) diff --git a/plugins/plugin_utils/connection.py b/plugins/plugin_utils/connection.py index 880c900f4c8..eb8e4ec6a04 100644 --- a/plugins/plugin_utils/connection.py +++ b/plugins/plugin_utils/connection.py @@ -10,7 +10,6 @@ class AWSConnectionBase(AWSPluginBase, ConnectionBase): - def _do_fail(self, message): raise AnsibleConnectionFailure(message) diff --git a/plugins/plugin_utils/inventory.py b/plugins/plugin_utils/inventory.py index ba3044f9055..96ef259b6d7 100644 --- a/plugins/plugin_utils/inventory.py +++ b/plugins/plugin_utils/inventory.py @@ -1,9 +1,6 @@ # Copyright: (c) 2022, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - try: import boto3 import botocore @@ -26,12 +23,15 @@ def _boto3_session(profile_name=None): class AWSInventoryBase(BaseInventoryPlugin, Constructable, Cacheable, AWSPluginBase): - class TemplatedOptions: # When someone looks up the TEMPLATABLE_OPTIONS using get() any templates # will be templated using the loader passed to parse. TEMPLATABLE_OPTIONS = ( - "access_key", "secret_key", "session_token", "profile", "iam_role_name", + "access_key", + "secret_key", + "session_token", + "profile", + "iam_role_name", ) def __init__(self, templar, options): @@ -65,6 +65,7 @@ def __init__(self): super().__init__() self._frozen_credentials = {} + # pylint: disable=too-many-arguments def parse(self, inventory, loader, path, cache=True, botocore_version=None, boto3_version=None): super().parse(inventory, loader, path) self.require_aws_sdk(botocore_version=botocore_version, boto3_version=boto3_version) @@ -145,24 +146,26 @@ def _boto3_regions(self, service): return regions # fallback to local list hardcoded in boto3 if still no regions - session = _boto3_session(options.get('profile')) + session = _boto3_session(options.get("profile")) regions = session.get_available_regions(service) if not regions: # I give up, now you MUST give me regions - self.fail_aws('Unable to get regions list from available methods, you must specify the "regions" option to continue.') + self.fail_aws( + "Unable to get regions list from available methods, you must specify the 'regions' option to continue." + ) return regions def all_clients(self, service): """ - Generator that yields a boto3 client and the region + Generator that yields a boto3 client and the region - :param service: The boto3 service to connect to. + :param service: The boto3 service to connect to. - Note: For services which don't support 'DescribeRegions' this may include bad - endpoints, and as such EndpointConnectionError should be cleanly handled as a non-fatal - error. + Note: For services which don't support 'DescribeRegions' this may include bad + endpoints, and as such EndpointConnectionError should be cleanly handled as a non-fatal + error. """ regions = self._boto3_regions(service=service) @@ -202,8 +205,8 @@ def update_cached_result(self, path, cache, result): def verify_file(self, path): """ - :param path: the path to the inventory config file - :return the contents of the config file + :param path: the path to the inventory config file + :return the contents of the config file """ if not super().verify_file(path): return False diff --git a/plugins/plugin_utils/lookup.py b/plugins/plugin_utils/lookup.py index 18b152bd326..8dc431a10d7 100644 --- a/plugins/plugin_utils/lookup.py +++ b/plugins/plugin_utils/lookup.py @@ -10,7 +10,6 @@ class AWSLookupBase(AWSPluginBase, LookupBase): - def _do_fail(self, message): raise AnsibleLookupError(message)