mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-03-26 21:33:25 +00:00
Get rid of some to_native and to_text calls. (#880)
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"]:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"] = (
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user