mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-07 13:53:06 +00:00
Remove Python 2 specific code (#877)
* Get rid of Python 2 special handling. * Get rid of more Python 2 specific handling. * Stop using six. * ipaddress is part of the standard library since Python 3. * Add changelog. * Fix import. * Remove unneeded imports.
This commit is contained in:
@@ -41,7 +41,6 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.gnupg.cli import (
|
||||
GPGError,
|
||||
get_fingerprint_from_bytes,
|
||||
@@ -52,7 +51,7 @@ from ansible_collections.community.crypto.plugins.plugin_utils.gnupg import (
|
||||
|
||||
|
||||
def gpg_fingerprint(input):
|
||||
if not isinstance(input, string_types):
|
||||
if not isinstance(input, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type(input)} instead"
|
||||
)
|
||||
|
||||
@@ -276,7 +276,6 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -290,11 +289,11 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
|
||||
def openssl_csr_info_filter(data, name_encoding="ignore"):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The community.crypto.openssl_csr_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if not isinstance(name_encoding, string_types):
|
||||
if not isinstance(name_encoding, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||
)
|
||||
|
||||
@@ -148,7 +148,6 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -165,11 +164,11 @@ def openssl_privatekey_info_filter(
|
||||
data, passphrase=None, return_private_key_data=False
|
||||
):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The community.crypto.openssl_privatekey_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if passphrase is not None and not isinstance(passphrase, string_types):
|
||||
if passphrase is not None and not isinstance(passphrase, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The passphrase option must be a text type, not {type(passphrase)}"
|
||||
)
|
||||
|
||||
@@ -125,7 +125,6 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -140,7 +139,7 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
|
||||
def openssl_publickey_info_filter(data):
|
||||
"""Extract information from OpenSSL PEM public key."""
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The community.crypto.openssl_publickey_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
|
||||
@@ -41,14 +41,13 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.serial import (
|
||||
parse_serial,
|
||||
)
|
||||
|
||||
|
||||
def parse_serial_filter(input):
|
||||
if not isinstance(input, string_types):
|
||||
if not isinstance(input, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The input for the community.crypto.parse_serial filter must be a string; got {type(input)} instead"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,6 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.pem import (
|
||||
split_pem_list,
|
||||
)
|
||||
@@ -48,7 +47,7 @@ from ansible_collections.community.crypto.plugins.module_utils.crypto.pem import
|
||||
|
||||
def split_pem_filter(data):
|
||||
"""Split PEM file."""
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The community.crypto.split_pem input must be a text type, not {type(data)}"
|
||||
)
|
||||
|
||||
@@ -41,12 +41,11 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.six import integer_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.serial import to_serial
|
||||
|
||||
|
||||
def to_serial_filter(input):
|
||||
if not isinstance(input, integer_types):
|
||||
if not isinstance(input, int):
|
||||
raise AnsibleFilterError(
|
||||
f"The input for the community.crypto.to_serial filter must be an integer; got {type(input)} instead"
|
||||
)
|
||||
|
||||
@@ -310,7 +310,6 @@ _value:
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -324,11 +323,11 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
|
||||
def x509_certificate_info_filter(data, name_encoding="ignore"):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The community.crypto.x509_certificate_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if not isinstance(name_encoding, string_types):
|
||||
if not isinstance(name_encoding, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||
)
|
||||
|
||||
@@ -158,7 +158,6 @@ import binascii
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -175,11 +174,11 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
|
||||
def x509_crl_info_filter(data, name_encoding="ignore", list_revoked_certificates=True):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The community.crypto.x509_crl_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if not isinstance(name_encoding, string_types):
|
||||
if not isinstance(name_encoding, (str, bytes)):
|
||||
raise AnsibleFilterError(
|
||||
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user