From 2711745614162d5c97e1d2ef157e2abdef38d63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Fri, 4 Jun 2021 20:01:34 +0200 Subject: [PATCH] Fix codacy issues * add codacy config file * fix security relevant issues --- .codacy.yml | 8 ++++++++ click_types/__init__.py | 2 +- click_types/ansible.py | 14 +++++++------- click_types/coding.py | 2 +- click_types/net.py | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .codacy.yml diff --git a/.codacy.yml b/.codacy.yml new file mode 100644 index 0000000..e09cd9e --- /dev/null +++ b/.codacy.yml @@ -0,0 +1,8 @@ +--- +exclude_paths: + - '.github/**' + - '.vscode/**' + - 'CHANGELOG.md' + - 'CONTRIBUTING.md' + - 'docs/**' + - 'README.md' diff --git a/click_types/__init__.py b/click_types/__init__.py index 80a338a..c69633b 100644 --- a/click_types/__init__.py +++ b/click_types/__init__.py @@ -1 +1 @@ -"""Python package that provides custom click types""" +"""Python package that provides custom click types.""" diff --git a/click_types/ansible.py b/click_types/ansible.py index 19dddaf..b40ce6b 100644 --- a/click_types/ansible.py +++ b/click_types/ansible.py @@ -1,4 +1,4 @@ -"""Module for custom click types regarding to ansible""" +"""Module for custom click types regarding to ansible.""" import click import os @@ -64,7 +64,7 @@ def convert(self, value, param, ctx): data = self.v.load(open(self.vault).read()) except AnsibleError as e: if 'not vault encrypted data' in str(e): - data = yaml.load(open(self.vault).read(), SafeLoader) or {} + data = yaml.safe_load(open(self.vault).read(), SafeLoader) or {} except Exception as e: self.fail('Decryption failed: {0}'.format(str(e)), param, ctx) @@ -74,18 +74,18 @@ def convert(self, value, param, ctx): try: self.v.dump(data, open(self.vault, 'w')) - except: # noqa: E722 + except Exception: self.fail('Error while encrypting data', param, ctx) return self.path - def _populate_data(self, input={}, keys=[], value=None): + def _populate_data(self, origin: dict = None, keys: list = None, value: str = None): """Save value at the desired position in vault. This method takes vault data, a list of keys where to store the value. - :param input: The dictionary of vault data, defaults to {} - :type input: dict, optional + :param origin: The dictionary of vault data, defaults to {} + :type origin: dict, optional :param keys: List of keys that describe the desired position in vault, defaults to [] :type keys: list, optional :param value: The value to store in vault, defaults to None @@ -93,7 +93,7 @@ def _populate_data(self, input={}, keys=[], value=None): :return: The vault data extended by `value` at the desired position. :rtype: dict """ - data = input.copy() + data = origin.copy() if keys: key = keys[0] diff --git a/click_types/coding.py b/click_types/coding.py index 8257d86..5ca3781 100644 --- a/click_types/coding.py +++ b/click_types/coding.py @@ -1,4 +1,4 @@ -"""Module for custom click types regarding to development""" +"""Module for custom click types regarding to development.""" import semver diff --git a/click_types/net.py b/click_types/net.py index 504b8ad..e006089 100644 --- a/click_types/net.py +++ b/click_types/net.py @@ -1,4 +1,4 @@ -"""Module for custom click types regarding to network""" +"""Module for custom click types regarding to network.""" import click import ipaddress