From 86db56119357d768ccb794561bebdecb60807ccf Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 2 May 2025 15:58:39 +0200 Subject: [PATCH] Get rid of some to_native and to_text calls. (#880) --- changelogs/fragments/refactoring.yml | 1 + plugins/action/openssl_privatekey_pipe.py | 4 +- plugins/filter/gpg_fingerprint.py | 4 +- plugins/filter/openssl_csr_info.py | 2 +- plugins/filter/openssl_privatekey_info.py | 4 +- plugins/filter/openssl_publickey_info.py | 4 +- plugins/filter/parse_serial.py | 2 +- plugins/filter/to_serial.py | 3 +- plugins/filter/x509_certificate_info.py | 2 +- plugins/filter/x509_crl_info.py | 2 +- plugins/lookup/gpg_fingerprint.py | 3 +- .../module_utils/acme/backend_openssl_cli.py | 18 ++++----- plugins/module_utils/acme/backends.py | 3 +- plugins/module_utils/acme/io.py | 3 +- plugins/module_utils/acme/utils.py | 13 ++++--- .../crypto/cryptography_support.py | 10 ++--- .../module_backends/certificate_acme.py | 4 +- .../module_backends/certificate_info.py | 4 +- .../crypto/module_backends/csr.py | 4 +- .../crypto/module_backends/csr_info.py | 4 +- .../crypto/module_backends/privatekey_info.py | 2 +- .../crypto/module_backends/publickey_info.py | 3 +- plugins/module_utils/ecs/api.py | 38 ++++++------------- .../module_utils/openssh/backends/common.py | 3 +- .../openssh/backends/keypair_backend.py | 16 ++++---- plugins/modules/ecs_certificate.py | 5 +-- plugins/modules/ecs_domain.py | 5 +-- plugins/modules/openssh_cert.py | 11 ++---- plugins/modules/openssl_csr.py | 3 +- plugins/modules/openssl_csr_info.py | 3 +- plugins/modules/openssl_csr_pipe.py | 3 +- plugins/modules/openssl_dhparam.py | 8 ++-- plugins/modules/openssl_pkcs12.py | 2 +- plugins/modules/openssl_privatekey.py | 3 +- plugins/modules/openssl_privatekey_convert.py | 3 +- plugins/modules/openssl_privatekey_info.py | 3 +- plugins/modules/openssl_publickey.py | 3 +- plugins/modules/openssl_publickey_info.py | 3 +- plugins/modules/openssl_signature.py | 3 +- plugins/modules/openssl_signature_info.py | 3 +- plugins/modules/x509_certificate.py | 3 +- plugins/modules/x509_certificate_convert.py | 4 +- plugins/modules/x509_certificate_info.py | 3 +- plugins/modules/x509_certificate_pipe.py | 4 +- plugins/modules/x509_crl.py | 6 +-- plugins/modules/x509_crl_info.py | 3 +- 46 files changed, 100 insertions(+), 140 deletions(-) diff --git a/changelogs/fragments/refactoring.yml b/changelogs/fragments/refactoring.yml index 6db0ade2..424fde2e 100644 --- a/changelogs/fragments/refactoring.yml +++ b/changelogs/fragments/refactoring.yml @@ -3,3 +3,4 @@ minor_changes: - "Python code modernization: update ``__future__`` imports, remove Python 2 specific boilerplates (https://github.com/ansible-collections/community.crypto/pull/876)." - "Python code modernization: use ``unittest.mock`` instead of ``ansible_collections.community.internal_test_tools.tests.unit.compat.mock`` (https://github.com/ansible-collections/community.crypto/pull/881)." - "Python code modernization: remove Python 3 specific code (https://github.com/ansible-collections/community.crypto/pull/877)." + - "Python code modernization: avoid unnecessary string conversion (https://github.com/ansible-collections/community.crypto/pull/880)." diff --git a/plugins/action/openssl_privatekey_pipe.py b/plugins/action/openssl_privatekey_pipe.py index e46b05ed..047ded38 100644 --- a/plugins/action/openssl_privatekey_pipe.py +++ b/plugins/action/openssl_privatekey_pipe.py @@ -6,7 +6,7 @@ from __future__ import annotations import base64 -from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -102,4 +102,4 @@ class ActionModule(ActionModuleBase): module.params["content"] = "ANSIBLE_NO_LOG_VALUE" module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) diff --git a/plugins/filter/gpg_fingerprint.py b/plugins/filter/gpg_fingerprint.py index a34531b4..2bc02d4b 100644 --- a/plugins/filter/gpg_fingerprint.py +++ b/plugins/filter/gpg_fingerprint.py @@ -40,7 +40,7 @@ _value: """ from ansible.errors import AnsibleFilterError -from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.crypto.plugins.module_utils.gnupg.cli import ( GPGError, get_fingerprint_from_bytes, @@ -59,7 +59,7 @@ def gpg_fingerprint(input): gpg = PluginGPGRunner() return get_fingerprint_from_bytes(gpg, to_bytes(input)) except GPGError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/openssl_csr_info.py b/plugins/filter/openssl_csr_info.py index ea63590c..1bec6944 100644 --- a/plugins/filter/openssl_csr_info.py +++ b/plugins/filter/openssl_csr_info.py @@ -309,7 +309,7 @@ def openssl_csr_info_filter(data, name_encoding="ignore"): module, "cryptography", content=to_bytes(data), validate_signature=True ) except OpenSSLObjectError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/openssl_privatekey_info.py b/plugins/filter/openssl_privatekey_info.py index 50eef31c..5322cf1d 100644 --- a/plugins/filter/openssl_privatekey_info.py +++ b/plugins/filter/openssl_privatekey_info.py @@ -147,7 +147,7 @@ _value: """ from ansible.errors import AnsibleFilterError -from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -192,7 +192,7 @@ def openssl_privatekey_info_filter( except PrivateKeyParseError as exc: raise AnsibleFilterError(exc.error_message) except OpenSSLObjectError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/openssl_publickey_info.py b/plugins/filter/openssl_publickey_info.py index 33647b67..88d26edf 100644 --- a/plugins/filter/openssl_publickey_info.py +++ b/plugins/filter/openssl_publickey_info.py @@ -124,7 +124,7 @@ _value: """ from ansible.errors import AnsibleFilterError -from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -150,7 +150,7 @@ def openssl_publickey_info_filter(data): except PublicKeyParseError as exc: raise AnsibleFilterError(exc.error_message) except OpenSSLObjectError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/parse_serial.py b/plugins/filter/parse_serial.py index fd814dbf..6bfc4f72 100644 --- a/plugins/filter/parse_serial.py +++ b/plugins/filter/parse_serial.py @@ -54,7 +54,7 @@ def parse_serial_filter(input): try: return parse_serial(to_native(input)) except ValueError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/to_serial.py b/plugins/filter/to_serial.py index 9675218c..1f5b00fb 100644 --- a/plugins/filter/to_serial.py +++ b/plugins/filter/to_serial.py @@ -40,7 +40,6 @@ _value: """ from ansible.errors import AnsibleFilterError -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.serial import to_serial @@ -56,7 +55,7 @@ def to_serial_filter(input): try: return to_serial(input) except ValueError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/x509_certificate_info.py b/plugins/filter/x509_certificate_info.py index 0a832483..2c188d63 100644 --- a/plugins/filter/x509_certificate_info.py +++ b/plugins/filter/x509_certificate_info.py @@ -341,7 +341,7 @@ def x509_certificate_info_filter(data, name_encoding="ignore"): try: return get_certificate_info(module, "cryptography", content=to_bytes(data)) except OpenSSLObjectError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/filter/x509_crl_info.py b/plugins/filter/x509_crl_info.py index 3a4e6100..40960d16 100644 --- a/plugins/filter/x509_crl_info.py +++ b/plugins/filter/x509_crl_info.py @@ -205,7 +205,7 @@ def x509_crl_info_filter(data, name_encoding="ignore", list_revoked_certificates module, content=data, list_revoked_certificates=list_revoked_certificates ) except OpenSSLObjectError as exc: - raise AnsibleFilterError(to_native(exc)) + raise AnsibleFilterError(str(exc)) class FilterModule: diff --git a/plugins/lookup/gpg_fingerprint.py b/plugins/lookup/gpg_fingerprint.py index 57350a70..8393d3f9 100644 --- a/plugins/lookup/gpg_fingerprint.py +++ b/plugins/lookup/gpg_fingerprint.py @@ -43,7 +43,6 @@ _value: """ from ansible.errors import AnsibleLookupError -from ansible.module_utils.common.text.converters import to_native from ansible.plugins.lookup import LookupBase from ansible_collections.community.crypto.plugins.module_utils.gnupg.cli import ( GPGError, @@ -65,4 +64,4 @@ class LookupModule(LookupBase): result.append(get_fingerprint_from_file(gpg, path)) return result except GPGError as exc: - raise AnsibleLookupError(to_native(exc)) + raise AnsibleLookupError(str(exc)) diff --git a/plugins/module_utils/acme/backend_openssl_cli.py b/plugins/module_utils/acme/backend_openssl_cli.py index 069ce350..3efcffee 100644 --- a/plugins/module_utils/acme/backend_openssl_cli.py +++ b/plugins/module_utils/acme/backend_openssl_cli.py @@ -14,7 +14,7 @@ import re import tempfile import traceback -from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text +from ansible.module_utils.common.text.converters import to_bytes, to_text from ansible_collections.community.crypto.plugins.module_utils.acme.backends import ( CertificateInformation, CryptoBackend, @@ -140,7 +140,7 @@ class OpenSSLCLIBackend(CryptoBackend): ) if rc != 0: raise BackendException( - f"Error while running {' '.join(openssl_keydump_cmd)}: {to_text(err)}" + f"Error while running {' '.join(openssl_keydump_cmd)}: {err}" ) out_text = to_text(out, errors="surrogate_or_strict") @@ -227,9 +227,9 @@ class OpenSSLCLIBackend(CryptoBackend): def sign(self, payload64, protected64, key_data): sign_payload = f"{protected64}.{payload64}".encode("utf8") if key_data["type"] == "hmac": - hex_key = to_native( + hex_key = ( binascii.hexlify(base64.urlsafe_b64decode(key_data["jwk"]["k"])) - ) + ).decode("ascii") cmd_postfix = [ "-mac", "hmac", @@ -254,7 +254,7 @@ class OpenSSLCLIBackend(CryptoBackend): ) if rc != 0: raise BackendException( - f"Error while running {' '.join(openssl_sign_cmd)}: {to_text(err)}" + f"Error while running {' '.join(openssl_sign_cmd)}: {err}" ) if key_data["type"] == "ec": @@ -317,7 +317,7 @@ class OpenSSLCLIBackend(CryptoBackend): @staticmethod def _normalize_ip(ip): try: - return to_native(ipaddress.ip_address(to_text(ip)).compressed) + return ipaddress.ip_address(to_text(ip)).compressed except ValueError: # We do not want to error out on something IPAddress() cannot parse return ip @@ -354,7 +354,7 @@ class OpenSSLCLIBackend(CryptoBackend): ) if rc != 0: raise BackendException( - f"Error while running {' '.join(openssl_csr_cmd)}: {to_text(err)}" + f"Error while running {' '.join(openssl_csr_cmd)}: {err}" ) identifiers = set() @@ -439,7 +439,7 @@ class OpenSSLCLIBackend(CryptoBackend): ) if rc != 0: raise BackendException( - f"Error while running {' '.join(openssl_cert_cmd)}: {to_text(err)}" + f"Error while running {' '.join(openssl_cert_cmd)}: {err}" ) out_text = to_text(out, errors="surrogate_or_strict") @@ -490,7 +490,7 @@ class OpenSSLCLIBackend(CryptoBackend): ) if rc != 0: raise BackendException( - f"Error while running {' '.join(openssl_cert_cmd)}: {to_text(err)}" + f"Error while running {' '.join(openssl_cert_cmd)}: {err}" ) out_text = to_text(out, errors="surrogate_or_strict") diff --git a/plugins/module_utils/acme/backends.py b/plugins/module_utils/acme/backends.py index fb8a2cf2..20a4bf75 100644 --- a/plugins/module_utils/acme/backends.py +++ b/plugins/module_utils/acme/backends.py @@ -11,7 +11,6 @@ import re from collections import namedtuple from ansible.module_utils import six -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ( BackendException, ) @@ -106,7 +105,7 @@ class CryptoBackend: value, name, backend="cryptography", with_timezone=self._with_timezone ) except OpenSSLObjectError as exc: - raise BackendException(to_native(exc)) + raise BackendException(str(exc)) def interpolate_timestamp(self, timestamp_start, timestamp_end, percentage): start = get_epoch_seconds(timestamp_start) diff --git a/plugins/module_utils/acme/io.py b/plugins/module_utils/acme/io.py index d2fb7fb2..687315df 100644 --- a/plugins/module_utils/acme/io.py +++ b/plugins/module_utils/acme/io.py @@ -11,7 +11,6 @@ import shutil import tempfile import traceback -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ( ModuleFailException, ) @@ -83,7 +82,7 @@ def write_file(module, dest, content): except Exception as err: os.remove(tmpsrc) raise ModuleFailException( - f"failed to copy {tmpsrc} to {dest}: {to_native(err)}", + f"failed to copy {tmpsrc} to {dest}: {err}", exception=traceback.format_exc(), ) os.remove(tmpsrc) diff --git a/plugins/module_utils/acme/utils.py b/plugins/module_utils/acme/utils.py index 23a7caa1..5b7e39c0 100644 --- a/plugins/module_utils/acme/utils.py +++ b/plugins/module_utils/acme/utils.py @@ -12,7 +12,6 @@ import textwrap import traceback from urllib.parse import unquote -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.acme.errors import ( ModuleFailException, ) @@ -51,7 +50,7 @@ def pem_to_der(pem_filename=None, pem_content=None): lines = list(f) except Exception as err: raise ModuleFailException( - f"cannot load PEM file {pem_filename}: {to_native(err)}", + f"cannot load PEM file {pem_filename}: {err}", exception=traceback.format_exc(), ) else: @@ -126,15 +125,17 @@ def compute_cert_id( raise ModuleFailException( "Certificate has no Authority Key Identifier extension" ) - aki = to_native( - base64.urlsafe_b64encode(cert_info.authority_key_identifier) - ).replace("=", "") + aki = ( + (base64.urlsafe_b64encode(cert_info.authority_key_identifier)) + .decode("ascii") + .replace("=", "") + ) # Convert serial number to string serial_bytes = convert_int_to_bytes(cert_info.serial_number) if ord(serial_bytes[:1]) >= 128: serial_bytes = b"\x00" + serial_bytes - serial = to_native(base64.urlsafe_b64encode(serial_bytes)).replace("=", "") + serial = (base64.urlsafe_b64encode(serial_bytes)).decode("ascii").replace("=", "") # Compose cert ID return f"{aki}.{serial}" diff --git a/plugins/module_utils/crypto/cryptography_support.py b/plugins/module_utils/crypto/cryptography_support.py index 62216e63..95981dbb 100644 --- a/plugins/module_utils/crypto/cryptography_support.py +++ b/plugins/module_utils/crypto/cryptography_support.py @@ -15,7 +15,7 @@ from urllib.parse import ( urlunparse, ) -from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text +from ansible.module_utils.common.text.converters import to_bytes, to_text from ansible_collections.community.crypto.plugins.module_utils.version import ( LooseVersion, ) @@ -95,7 +95,7 @@ def cryptography_get_extensions_from_cert(cert): for ext in cert.extensions: result[ext.oid.dotted_string] = dict( critical=ext.critical, - value=to_native(base64.b64encode(ext.value.public_bytes())), + value=base64.b64encode(ext.value.public_bytes()).decode("ascii"), ) else: # Since cryptography will not give us the DER value for an extension @@ -120,7 +120,7 @@ def cryptography_get_extensions_from_cert(cert): der = backend._ffi.buffer(data.data, data.length)[:] entry = dict( critical=(crit == 1), - value=to_native(base64.b64encode(der)), + value=base64.b64encode(der).decode("ascii"), ) try: oid = obj2txt( @@ -142,7 +142,7 @@ def cryptography_get_extensions_from_csr(csr): for ext in csr.extensions: result[ext.oid.dotted_string] = dict( critical=ext.critical, - value=to_native(base64.b64encode(ext.value.public_bytes())), + value=base64.b64encode(ext.value.public_bytes()).decode("ascii"), ) else: @@ -178,7 +178,7 @@ def cryptography_get_extensions_from_csr(csr): der = backend._ffi.buffer(data.data, data.length)[:] entry = dict( critical=(crit == 1), - value=to_native(base64.b64encode(der)), + value=base64.b64encode(der).decode("ascii"), ) try: oid = obj2txt( diff --git a/plugins/module_utils/crypto/module_backends/certificate_acme.py b/plugins/module_utils/crypto/module_backends/certificate_acme.py index 0c13e644..0608ad1e 100644 --- a/plugins/module_utils/crypto/module_backends/certificate_acme.py +++ b/plugins/module_utils/crypto/module_backends/certificate_acme.py @@ -9,7 +9,7 @@ import os import tempfile import traceback -from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.crypto.plugins.module_utils.crypto.module_backends.certificate import ( CertificateBackend, CertificateError, @@ -66,7 +66,7 @@ class AcmeCertificateBackend(CertificateBackend): except Exception: pass self.module.fail_json( - msg=f"failed to create temporary CSR file: {to_native(err)}", + msg=f"failed to create temporary CSR file: {err}", exception=traceback.format_exc(), ) f.close() diff --git a/plugins/module_utils/crypto/module_backends/certificate_info.py b/plugins/module_utils/crypto/module_backends/certificate_info.py index 3dc17704..c18476a2 100644 --- a/plugins/module_utils/crypto/module_backends/certificate_info.py +++ b/plugins/module_utils/crypto/module_backends/certificate_info.py @@ -208,13 +208,13 @@ class CertificateInfoRetrieval: ski = self._get_subject_key_identifier() if ski is not None: - ski = to_native(binascii.hexlify(ski)) + ski = binascii.hexlify(ski).decode("ascii") ski = ":".join([ski[i : i + 2] for i in range(0, len(ski), 2)]) result["subject_key_identifier"] = ski aki, aci, acsn = self._get_authority_key_identifier() if aki is not None: - aki = to_native(binascii.hexlify(aki)) + aki = binascii.hexlify(aki).decode("ascii") aki = ":".join([aki[i : i + 2] for i in range(0, len(aki), 2)]) result["authority_key_identifier"] = aki result["authority_cert_issuer"] = aci diff --git a/plugins/module_utils/crypto/module_backends/csr.py b/plugins/module_utils/crypto/module_backends/csr.py index 31706b02..671a2d50 100644 --- a/plugins/module_utils/crypto/module_backends/csr.py +++ b/plugins/module_utils/crypto/module_backends/csr.py @@ -11,7 +11,7 @@ import traceback from ansible.module_utils import six from ansible.module_utils.basic import missing_required_lib -from ansible.module_utils.common.text.converters import to_native, to_text +from ansible.module_utils.common.text.converters import to_text from ansible_collections.community.crypto.plugins.module_utils.argspec import ( ArgumentSpec, ) @@ -157,7 +157,7 @@ class CertificateSigningRequestBackend: ) self.ordered_subject = True except ValueError as exc: - raise CertificateSigningRequestError(to_native(exc)) + raise CertificateSigningRequestError(str(exc)) self.using_common_name_for_san = False if not self.subjectAltName and module.params["use_common_name_for_san"]: diff --git a/plugins/module_utils/crypto/module_backends/csr_info.py b/plugins/module_utils/crypto/module_backends/csr_info.py index f009286a..8779aa59 100644 --- a/plugins/module_utils/crypto/module_backends/csr_info.py +++ b/plugins/module_utils/crypto/module_backends/csr_info.py @@ -157,13 +157,13 @@ class CSRInfoRetrieval: ski = self._get_subject_key_identifier() if ski is not None: - ski = to_native(binascii.hexlify(ski)) + ski = binascii.hexlify(ski).decode("ascii") ski = ":".join([ski[i : i + 2] for i in range(0, len(ski), 2)]) result["subject_key_identifier"] = ski aki, aci, acsn = self._get_authority_key_identifier() if aki is not None: - aki = to_native(binascii.hexlify(aki)) + aki = binascii.hexlify(aki).decode("ascii") aki = ":".join([aki[i : i + 2] for i in range(0, len(aki), 2)]) result["authority_key_identifier"] = aki result["authority_cert_issuer"] = aci diff --git a/plugins/module_utils/crypto/module_backends/privatekey_info.py b/plugins/module_utils/crypto/module_backends/privatekey_info.py index c4e17e87..d67be31c 100644 --- a/plugins/module_utils/crypto/module_backends/privatekey_info.py +++ b/plugins/module_utils/crypto/module_backends/privatekey_info.py @@ -229,7 +229,7 @@ class PrivateKeyInfoRetrieval: ) result["can_parse_key"] = True except OpenSSLObjectError as exc: - raise PrivateKeyParseError(to_native(exc), result) + raise PrivateKeyParseError(str(exc), result) result["public_key"] = to_native(self._get_public_key(binary=False)) pk = self._get_public_key(binary=True) diff --git a/plugins/module_utils/crypto/module_backends/publickey_info.py b/plugins/module_utils/crypto/module_backends/publickey_info.py index 64fed8ad..f3f7c5e2 100644 --- a/plugins/module_utils/crypto/module_backends/publickey_info.py +++ b/plugins/module_utils/crypto/module_backends/publickey_info.py @@ -9,7 +9,6 @@ import traceback from ansible.module_utils import six from ansible.module_utils.basic import missing_required_lib -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -116,7 +115,7 @@ class PublicKeyInfoRetrieval: try: self.key = load_publickey(content=self.content, backend=self.backend) except OpenSSLObjectError as e: - raise PublicKeyParseError(to_native(e), {}) + raise PublicKeyParseError(str(e), {}) pk = self._get_public_key(binary=True) result["fingerprints"] = ( diff --git a/plugins/module_utils/ecs/api.py b/plugins/module_utils/ecs/api.py index e43d581e..7523df28 100644 --- a/plugins/module_utils/ecs/api.py +++ b/plugins/module_utils/ecs/api.py @@ -59,7 +59,7 @@ class RestOperationException(Exception): def __init__(self, error): self.status = to_native(error.get("status", None)) self.errors = [to_native(err.get("message")) for err in error.get("errors", {})] - self.message = to_native(" ".join(self.errors)) + self.message = " ".join(self.errors) def generate_docstring(operation_spec): @@ -197,7 +197,7 @@ class Resource: operation_name = "Patch" else: raise SessionConfigurationException( - to_native(f"Invalid REST method type {method}") + f"Invalid REST method type {method}" ) # Get the non-parameter parts of the URL and append to the operation name @@ -242,7 +242,7 @@ class ECSSession: if self._config: break if self._config is None: - raise SessionConfigurationException(to_native("No Configuration Found.")) + raise SessionConfigurationException("No Configuration Found.") # set up auth if passed entrust_api_user = self.get_config("entrust_api_user") @@ -251,9 +251,7 @@ class ECSSession: self.request.url_username = entrust_api_user self.request.url_password = entrust_api_key else: - raise SessionConfigurationException( - to_native("User and key must be provided.") - ) + raise SessionConfigurationException("User and key must be provided.") # set up client certificate if passed (support all-in one or cert + key) entrust_api_cert = self.get_config("entrust_api_cert") @@ -264,9 +262,7 @@ class ECSSession: self.request.client_key = entrust_api_cert_key else: raise SessionConfigurationException( - to_native( - "Client certificate for authentication to the API must be provided." - ) + "Client certificate for authentication to the API must be provided." ) # set up the spec @@ -278,15 +274,11 @@ class ECSSession: entrust_api_specification_path ): raise SessionConfigurationException( - to_native( - f"OpenAPI specification was not found at location {entrust_api_specification_path}." - ) + f"OpenAPI specification was not found at location {entrust_api_specification_path}." ) if not valid_file_format.match(entrust_api_specification_path): raise SessionConfigurationException( - to_native( - "OpenAPI specification filename must end in .json, .yml or .yaml" - ) + "OpenAPI specification filename must end in .json, .yml or .yaml" ) self.verify = True @@ -305,9 +297,7 @@ class ECSSession: self._spec = yaml.safe_load(http_response_contents) except HTTPError as e: raise SessionConfigurationException( - to_native( - f"Error downloading specification from address '{entrust_api_specification_path}', received error code '{e.getcode()}'" - ) + f"Error downloading specification from address '{entrust_api_specification_path}', received error code '{e.getcode()}'" ) else: with open(entrust_api_specification_path) as f: @@ -332,25 +322,21 @@ class ECSSession: and not os.path.isfile(entrust_api_specification_path) ): raise SessionConfigurationException( - to_native( - f"Parameter provided for entrust_api_specification_path of value '{entrust_api_specification_path}'" - " was not a valid file path or HTTPS address." - ) + f"Parameter provided for entrust_api_specification_path of value '{entrust_api_specification_path}'" + " was not a valid file path or HTTPS address." ) for required_file in ["entrust_api_cert", "entrust_api_cert_key"]: file_path = kwargs.get(required_file) if not file_path or not os.path.isfile(file_path): raise SessionConfigurationException( - to_native( - f"Parameter provided for {required_file} of value '{file_path}' was not a valid file path." - ) + f"Parameter provided for {required_file} of value '{file_path}' was not a valid file path." ) for required_var in ["entrust_api_user", "entrust_api_key"]: if not kwargs.get(required_var): raise SessionConfigurationException( - to_native(f"Parameter provided for {required_var} was missing.") + f"Parameter provided for {required_var} was missing." ) config["entrust_api_cert"] = kwargs.get("entrust_api_cert") diff --git a/plugins/module_utils/openssh/backends/common.py b/plugins/module_utils/openssh/backends/common.py index 2d48b880..b7592ce1 100644 --- a/plugins/module_utils/openssh/backends/common.py +++ b/plugins/module_utils/openssh/backends/common.py @@ -10,7 +10,6 @@ import stat import traceback from ansible.module_utils import six -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.openssh.utils import ( parse_openssh_version, ) @@ -73,7 +72,7 @@ class OpensshModule: self._execute() except Exception as e: self.module.fail_json( - msg=f"unexpected error occurred: {to_native(e)}", + msg=f"unexpected error occurred: {e}", exception=traceback.format_exc(), ) diff --git a/plugins/module_utils/openssh/backends/keypair_backend.py b/plugins/module_utils/openssh/backends/keypair_backend.py index 948701e4..9979ec1f 100644 --- a/plugins/module_utils/openssh/backends/keypair_backend.py +++ b/plugins/module_utils/openssh/backends/keypair_backend.py @@ -10,7 +10,7 @@ import os from ansible.module_utils import six from ansible.module_utils.basic import missing_required_lib -from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text +from ansible.module_utils.common.text.converters import to_bytes, to_text from ansible_collections.community.crypto.plugins.module_utils.openssh.backends.common import ( KeygenCommand, OpensshModule, @@ -216,7 +216,7 @@ class KeypairBackend(OpensshModule): ] ) except OSError as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) def _generate_temp_keypair(self): temp_private_key = os.path.join( @@ -227,7 +227,7 @@ class KeypairBackend(OpensshModule): try: self._generate_keypair(temp_private_key) except (IOError, OSError) as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) for f in (temp_private_key, temp_public_key): self.module.add_cleanup_file(f) @@ -283,7 +283,7 @@ class KeypairBackend(OpensshModule): to_bytes(content), ) except (IOError, OSError) as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) self.module.add_cleanup_file(temp_public_key) return temp_public_key @@ -304,7 +304,7 @@ class KeypairBackend(OpensshModule): if self._public_key_exists(): os.remove(self.public_key_path) except (IOError, OSError) as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) @property def _result(self): @@ -396,7 +396,7 @@ class KeypairBackendOpensshBin(KeypairBackend): check_rc=True, ) except (IOError, OSError) as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) def _private_key_valid_backend(self): return True @@ -520,13 +520,13 @@ class KeypairBackendCryptography(KeypairBackend): try: keypair.comment = self.comment except InvalidCommentError as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) try: temp_public_key = self._create_temp_public_key(keypair.public_key + b"\n") self._safe_secure_move([(temp_public_key, self.public_key_path)]) except (IOError, OSError) as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) def _private_key_valid_backend(self): # avoids breaking behavior and prevents diff --git a/plugins/modules/ecs_certificate.py b/plugins/modules/ecs_certificate.py index 44f4579d..06721b07 100644 --- a/plugins/modules/ecs_certificate.py +++ b/plugins/modules/ecs_certificate.py @@ -554,7 +554,7 @@ import time import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible.module_utils.common.text.converters import to_bytes from ansible_collections.community.crypto.plugins.module_utils.crypto.support import ( load_certificate, ) @@ -760,8 +760,7 @@ class EcsCertificate: self.cert_days = calculate_cert_days(self.cert_details.get("expiresAfter")) except RestOperationException as e: module.fail_json( - f'Failed to get details of certificate with tracking_id="{self.tracking_id}", Error: ', - to_native(e.message), + msg=f'Failed to get details of certificate with tracking_id="{self.tracking_id}", Error: {e.message}' ) def check(self, module): diff --git a/plugins/modules/ecs_domain.py b/plugins/modules/ecs_domain.py index be4ab3a7..ff014d2f 100644 --- a/plugins/modules/ecs_domain.py +++ b/plugins/modules/ecs_domain.py @@ -220,7 +220,6 @@ import datetime import time from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.ecs.api import ( ECSClient, RestOperationException, @@ -274,9 +273,7 @@ class EcsDomain: ], ) except SessionConfigurationException as e: - module.fail_json( - msg=f"Failed to initialize Entrust Provider: {to_native(e)}" - ) + module.fail_json(msg=f"Failed to initialize Entrust Provider: {e}") try: self.ecs_client.GetAppVersion() except RestOperationException as e: diff --git a/plugins/modules/openssh_cert.py b/plugins/modules/openssh_cert.py index ec97b3be..6cd1b91d 100644 --- a/plugins/modules/openssh_cert.py +++ b/plugins/modules/openssh_cert.py @@ -286,7 +286,6 @@ info: import os from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.openssh.backends.common import ( KeygenCommand, OpensshModule, @@ -381,7 +380,7 @@ class Certificate(OpensshModule): valid_to=self.module.params["valid_to"], ) except ValueError as e: - self.module.fail_json(msg=to_native(e)) + self.module.fail_json(msg=str(e)) def _execute(self): if self.state == "present": @@ -447,7 +446,7 @@ class Certificate(OpensshModule): valid_to=self.original_data.valid_before, ) except ValueError as e: - return self.module.fail_json(msg=to_native(e)) + return self.module.fail_json(msg=str(e)) if self.ignore_timestamps: return original_time_parameters.within_range(self.valid_at) @@ -463,7 +462,7 @@ class Certificate(OpensshModule): try: critical_options, extensions = parse_option_list(self.options) except ValueError as e: - return self.module.fail_json(msg=to_native(e)) + return self.module.fail_json(msg=str(e)) return all( [ @@ -528,9 +527,7 @@ class Certificate(OpensshModule): try: os.remove(self.path) except OSError as e: - self.module.fail_json( - msg=f"Unable to remove existing certificate: {to_native(e)}" - ) + self.module.fail_json(msg=f"Unable to remove existing certificate: {e}") @property def _result(self): diff --git a/plugins/modules/openssl_csr.py b/plugins/modules/openssl_csr.py index 20f69bb8..c1cc3e76 100644 --- a/plugins/modules/openssl_csr.py +++ b/plugins/modules/openssl_csr.py @@ -240,7 +240,6 @@ csr: import os -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -353,7 +352,7 @@ def main(): result = csr.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_csr_info.py b/plugins/modules/openssl_csr_info.py index 4ec51618..cf180746 100644 --- a/plugins/modules/openssl_csr_info.py +++ b/plugins/modules/openssl_csr_info.py @@ -308,7 +308,6 @@ authority_cert_serial_number: from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -351,7 +350,7 @@ def main(): result = module_backend.get_info() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_csr_pipe.py b/plugins/modules/openssl_csr_pipe.py index 9e413839..4208499c 100644 --- a/plugins/modules/openssl_csr_pipe.py +++ b/plugins/modules/openssl_csr_pipe.py @@ -127,7 +127,6 @@ csr: type: str """ -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -183,7 +182,7 @@ def main(): result = csr.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_dhparam.py b/plugins/modules/openssl_dhparam.py index 8b17a56b..6245397e 100644 --- a/plugins/modules/openssl_dhparam.py +++ b/plugins/modules/openssl_dhparam.py @@ -212,7 +212,7 @@ class DHParameterBase: os.remove(self.path) self.changed = True except OSError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) def check(self, module): """Ensure the resource is in its desired state.""" @@ -279,7 +279,7 @@ class DHParameterOpenSSL(DHParameterBase): command = [self.openssl_bin, "dhparam", "-out", tmpsrc, str(self.size)] rc, dummy, err = module.run_command(command, check_rc=False) if rc != 0: - raise DHParameterError(to_native(err)) + raise DHParameterError(str(err)) if self.backup: self.backup_file = module.backup_local(self.path) try: @@ -429,7 +429,7 @@ def main(): try: dhparam.generate(module) except DHParameterError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) else: dhparam = DHParameterAbsent(module) @@ -442,7 +442,7 @@ def main(): try: dhparam.remove(module) except Exception as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) result = dhparam.dump() diff --git a/plugins/modules/openssl_pkcs12.py b/plugins/modules/openssl_pkcs12.py index 1ac8ac1a..347ded46 100644 --- a/plugins/modules/openssl_pkcs12.py +++ b/plugins/modules/openssl_pkcs12.py @@ -862,7 +862,7 @@ def main(): module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_privatekey.py b/plugins/modules/openssl_privatekey.py index c87b38a4..eb8064c3 100644 --- a/plugins/modules/openssl_privatekey.py +++ b/plugins/modules/openssl_privatekey.py @@ -156,7 +156,6 @@ privatekey: import os -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -287,7 +286,7 @@ def main(): result = private_key.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_privatekey_convert.py b/plugins/modules/openssl_privatekey_convert.py index a6d1f95c..8bf43747 100644 --- a/plugins/modules/openssl_privatekey_convert.py +++ b/plugins/modules/openssl_privatekey_convert.py @@ -61,7 +61,6 @@ backup_file: import os -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -159,7 +158,7 @@ def main(): result = private_key.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_privatekey_info.py b/plugins/modules/openssl_privatekey_info.py index 75101148..87ad4c7e 100644 --- a/plugins/modules/openssl_privatekey_info.py +++ b/plugins/modules/openssl_privatekey_info.py @@ -200,7 +200,6 @@ private_data: from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -266,7 +265,7 @@ def main(): result.update(exc.result) module.fail_json(msg=exc.error_message, **result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_publickey.py b/plugins/modules/openssl_publickey.py index b70e7b3e..e5af9b86 100644 --- a/plugins/modules/openssl_publickey.py +++ b/plugins/modules/openssl_publickey.py @@ -187,7 +187,6 @@ import os import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLBadPassphraseError, OpenSSLObjectError, @@ -499,7 +498,7 @@ def main(): result = public_key.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_publickey_info.py b/plugins/modules/openssl_publickey_info.py index eab70839..de4bc070 100644 --- a/plugins/modules/openssl_publickey_info.py +++ b/plugins/modules/openssl_publickey_info.py @@ -152,7 +152,6 @@ public_data: from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -204,7 +203,7 @@ def main(): result.update(exc.result) module.fail_json(msg=exc.error_message, **result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_signature.py b/plugins/modules/openssl_signature.py index 8d1fdde8..347903de 100644 --- a/plugins/modules/openssl_signature.py +++ b/plugins/modules/openssl_signature.py @@ -120,7 +120,6 @@ else: CRYPTOGRAPHY_FOUND = True from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -280,7 +279,7 @@ def main(): module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/openssl_signature_info.py b/plugins/modules/openssl_signature_info.py index e27f7e38..f266e812 100644 --- a/plugins/modules/openssl_signature_info.py +++ b/plugins/modules/openssl_signature_info.py @@ -109,7 +109,6 @@ else: CRYPTOGRAPHY_FOUND = True from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -285,7 +284,7 @@ def main(): module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/x509_certificate.py b/plugins/modules/x509_certificate.py index cbe25487..9297d76f 100644 --- a/plugins/modules/x509_certificate.py +++ b/plugins/modules/x509_certificate.py @@ -225,7 +225,6 @@ certificate: import os -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -405,7 +404,7 @@ def main(): result = certificate.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/x509_certificate_convert.py b/plugins/modules/x509_certificate_convert.py index 17671831..db6727d7 100644 --- a/plugins/modules/x509_certificate_convert.py +++ b/plugins/modules/x509_certificate_convert.py @@ -109,7 +109,7 @@ import os import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text +from ansible.module_utils.common.text.converters import to_bytes, to_text from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -317,7 +317,7 @@ def main(): result = cert.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/x509_certificate_info.py b/plugins/modules/x509_certificate_info.py index 164eed49..325d66a0 100644 --- a/plugins/modules/x509_certificate_info.py +++ b/plugins/modules/x509_certificate_info.py @@ -390,7 +390,6 @@ issuer_uri: from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -462,7 +461,7 @@ def main(): module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/x509_certificate_pipe.py b/plugins/modules/x509_certificate_pipe.py index 98c968cb..fc35c8ac 100644 --- a/plugins/modules/x509_certificate_pipe.py +++ b/plugins/modules/x509_certificate_pipe.py @@ -118,8 +118,6 @@ certificate: type: str """ - -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -197,7 +195,7 @@ def main(): result = certificate.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/x509_crl.py b/plugins/modules/x509_crl.py index 54dabfd0..ded0a055 100644 --- a/plugins/modules/x509_crl.py +++ b/plugins/modules/x509_crl.py @@ -429,7 +429,7 @@ import os import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native, to_text +from ansible.module_utils.common.text.converters import to_text from ansible.module_utils.common.validation import check_type_int, check_type_str from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLBadPassphraseError, @@ -543,7 +543,7 @@ class CRL(OpenSSLObject): self.issuer_ordered = False self.issuer = parse_name_field(module.params["issuer"], "issuer") except (TypeError, ValueError) as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) self.last_update = get_relative_time_option( module.params["last_update"], @@ -1040,7 +1040,7 @@ def main(): result = crl.dump() module.exit_json(**result) except OpenSSLObjectError as exc: - module.fail_json(msg=to_native(exc)) + module.fail_json(msg=str(exc)) if __name__ == "__main__": diff --git a/plugins/modules/x509_crl_info.py b/plugins/modules/x509_crl_info.py index 774a1922..d44271dc 100644 --- a/plugins/modules/x509_crl_info.py +++ b/plugins/modules/x509_crl_info.py @@ -175,7 +175,6 @@ import base64 import binascii from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import ( OpenSSLObjectError, ) @@ -224,7 +223,7 @@ def main(): ) module.exit_json(**result) except OpenSSLObjectError as e: - module.fail_json(msg=to_native(e)) + module.fail_json(msg=str(e)) if __name__ == "__main__":