mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 21:33:00 +00:00
Work on issues found by pylint (#896)
* Look at possibly-used-before-assignment. * Use latest beta releases of ansible-core 2.19 for mypy and pylint. * Look at unsupported-*. * Look at unknown-option-value. * Look at redefined-builtin. * Look at superfluous-parens. * Look at unspecified-encoding. * Adjust to new cryptography version and to ansible-core 2.17's pylint. * Look at super-with-arguments. * Look at no-else-*. * Look at try-except-raise. * Look at inconsistent-return-statements. * Look at redefined-outer-name. * Look at redefined-argument-from-local. * Look at attribute-defined-outside-init. * Look at unused-variable. * Look at protected-access. * Look at raise-missing-from. * Look at arguments-differ. * Look at useless-suppression and use-symbolic-message-instead. * Look at consider-using-dict-items. * Look at consider-using-in. * Look at consider-using-set-comprehension. * Look at consider-using-with. * Look at use-dict-literal.
This commit is contained in:
@@ -52,16 +52,18 @@ from ansible_collections.community.crypto.plugins.plugin_utils._gnupg import (
|
||||
)
|
||||
|
||||
|
||||
def gpg_fingerprint(input: str | bytes) -> str:
|
||||
if not isinstance(input, (str, bytes)):
|
||||
def gpg_fingerprint(gpg_key_content: str | bytes) -> str:
|
||||
if not isinstance(gpg_key_content, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type(input)} instead"
|
||||
f"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type(gpg_key_content)} instead"
|
||||
)
|
||||
try:
|
||||
gpg = PluginGPGRunner()
|
||||
return get_fingerprint_from_bytes(gpg_runner=gpg, content=to_bytes(input))
|
||||
return get_fingerprint_from_bytes(
|
||||
gpg_runner=gpg, content=to_bytes(gpg_key_content)
|
||||
)
|
||||
except GPGError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -313,7 +313,7 @@ def openssl_csr_info_filter(
|
||||
module=module, content=to_bytes(data), validate_signature=True
|
||||
)
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -193,9 +193,9 @@ def openssl_privatekey_info_filter(
|
||||
result.pop("key_is_consistent", None)
|
||||
return result
|
||||
except PrivateKeyParseError as exc:
|
||||
raise AnsibleFilterError(exc.error_message)
|
||||
raise AnsibleFilterError(exc.error_message) from exc
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -150,9 +150,9 @@ def openssl_publickey_info_filter(data: str | bytes) -> dict[str, t.Any]:
|
||||
try:
|
||||
return get_publickey_info(module=module, content=to_bytes(data))
|
||||
except PublicKeyParseError as exc:
|
||||
raise AnsibleFilterError(exc.error_message)
|
||||
raise AnsibleFilterError(exc.error_message) from exc
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -48,15 +48,15 @@ from ansible_collections.community.crypto.plugins.module_utils._serial import (
|
||||
)
|
||||
|
||||
|
||||
def parse_serial_filter(input: str | bytes) -> int:
|
||||
if not isinstance(input, (str, bytes)):
|
||||
def parse_serial_filter(serial_str: str | bytes) -> int:
|
||||
if not isinstance(serial_str, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The input for the community.crypto.parse_serial filter must be a string; got {type(input)} instead"
|
||||
f"The input for the community.crypto.parse_serial filter must be a string; got {type(serial_str)} instead"
|
||||
)
|
||||
try:
|
||||
return parse_serial(to_native(input))
|
||||
return parse_serial(to_native(serial_str))
|
||||
except ValueError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -45,19 +45,19 @@ from ansible.errors import AnsibleFilterError
|
||||
from ansible_collections.community.crypto.plugins.module_utils._serial import to_serial
|
||||
|
||||
|
||||
def to_serial_filter(input: int) -> str:
|
||||
if not isinstance(input, int):
|
||||
def to_serial_filter(serial_int: int) -> str:
|
||||
if not isinstance(serial_int, int):
|
||||
raise AnsibleFilterError(
|
||||
f"The input for the community.crypto.to_serial filter must be an integer; got {type(input)} instead"
|
||||
f"The input for the community.crypto.to_serial filter must be an integer; got {type(serial_int)} instead"
|
||||
)
|
||||
if input < 0:
|
||||
if serial_int < 0:
|
||||
raise AnsibleFilterError(
|
||||
"The input for the community.crypto.to_serial filter must not be negative"
|
||||
)
|
||||
try:
|
||||
return to_serial(input)
|
||||
return to_serial(serial_int)
|
||||
except ValueError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -345,7 +345,7 @@ def x509_certificate_info_filter(
|
||||
try:
|
||||
return get_certificate_info(module=module, content=to_bytes(data))
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
@@ -212,7 +212,7 @@ def x509_crl_info_filter(
|
||||
list_revoked_certificates=list_revoked_certificates,
|
||||
)
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
||||
raise AnsibleFilterError(str(exc)) from exc
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
Reference in New Issue
Block a user