mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 21:33:00 +00:00
Replace to_native with to_text. (#897)
This commit is contained in:
@@ -14,7 +14,7 @@ import os
|
||||
import traceback
|
||||
import typing as t
|
||||
|
||||
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,
|
||||
@@ -120,14 +120,14 @@ class CryptographyChainMatcher(ChainMatcher):
|
||||
self.issuer: list[tuple[cryptography.x509.oid.ObjectIdentifier, str]] = []
|
||||
if criterium.subject:
|
||||
self.subject = [
|
||||
(cryptography_name_to_oid(k), to_native(v))
|
||||
(cryptography_name_to_oid(k), to_text(v))
|
||||
for k, v in parse_name_field(
|
||||
criterium.subject, name_field_name="subject"
|
||||
)
|
||||
]
|
||||
if criterium.issuer:
|
||||
self.issuer = [
|
||||
(cryptography_name_to_oid(k), to_native(v))
|
||||
(cryptography_name_to_oid(k), to_text(v))
|
||||
for k, v in parse_name_field(criterium.issuer, name_field_name="issuer")
|
||||
]
|
||||
self.subject_key_identifier = CryptographyChainMatcher._parse_key_identifier(
|
||||
@@ -153,7 +153,7 @@ class CryptographyChainMatcher(ChainMatcher):
|
||||
for oid, value in match_subject:
|
||||
found = False
|
||||
for attribute in x509_subject:
|
||||
if attribute.oid == oid and value == to_native(attribute.value):
|
||||
if attribute.oid == oid and value == to_text(attribute.value):
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
|
||||
@@ -12,7 +12,7 @@ import datetime
|
||||
import os
|
||||
import typing as t
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||
from ansible_collections.community.crypto.plugins.module_utils._crypto.cryptography_support import (
|
||||
CRYPTOGRAPHY_TIMEZONE,
|
||||
get_not_valid_after,
|
||||
@@ -117,7 +117,7 @@ class EntrustCertificateBackend(CertificateBackend):
|
||||
# Read the CSR that was generated for us
|
||||
if self.csr_content is not None:
|
||||
# csr_content contains bytes
|
||||
body["csr"] = to_native(self.csr_content)
|
||||
body["csr"] = to_text(self.csr_content)
|
||||
else:
|
||||
assert self.csr_path is not None
|
||||
with open(self.csr_path, "r", encoding="utf-8") as csr_file:
|
||||
|
||||
@@ -13,7 +13,7 @@ import abc
|
||||
import binascii
|
||||
import typing as t
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible_collections.community.crypto.plugins.module_utils._crypto.cryptography_support import (
|
||||
CRYPTOGRAPHY_TIMEZONE,
|
||||
cryptography_decode_name,
|
||||
@@ -202,7 +202,7 @@ class CertificateInfoRetrieval(metaclass=abc.ABCMeta):
|
||||
with_timezone=CRYPTOGRAPHY_TIMEZONE
|
||||
)
|
||||
|
||||
result["public_key"] = to_native(self._get_public_key_pem())
|
||||
result["public_key"] = to_text(self._get_public_key_pem())
|
||||
|
||||
public_key_info = get_publickey_info(
|
||||
module=self.module,
|
||||
@@ -264,7 +264,7 @@ class CertificateInfoRetrievalCryptography(CertificateInfoRetrieval):
|
||||
result: list[list[str]] = []
|
||||
for attribute in self.cert.subject:
|
||||
result.append(
|
||||
[cryptography_oid_to_name(attribute.oid), to_native(attribute.value)]
|
||||
[cryptography_oid_to_name(attribute.oid), to_text(attribute.value)]
|
||||
)
|
||||
return result
|
||||
|
||||
@@ -272,7 +272,7 @@ class CertificateInfoRetrievalCryptography(CertificateInfoRetrieval):
|
||||
result = []
|
||||
for attribute in self.cert.issuer:
|
||||
result.append(
|
||||
[cryptography_oid_to_name(attribute.oid), to_native(attribute.value)]
|
||||
[cryptography_oid_to_name(attribute.oid), to_text(attribute.value)]
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import abc
|
||||
import binascii
|
||||
import typing as t
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible_collections.community.crypto.plugins.module_utils._crypto.cryptography_support import (
|
||||
cryptography_decode_name,
|
||||
cryptography_get_extensions_from_csr,
|
||||
@@ -154,7 +154,7 @@ class CSRInfoRetrieval(metaclass=abc.ABCMeta):
|
||||
result["name_constraints_critical"],
|
||||
) = self._get_name_constraints()
|
||||
|
||||
result["public_key"] = to_native(self._get_public_key_pem())
|
||||
result["public_key"] = to_text(self._get_public_key_pem())
|
||||
|
||||
public_key_info = get_publickey_info(
|
||||
module=self.module,
|
||||
@@ -210,7 +210,7 @@ class CSRInfoRetrievalCryptography(CSRInfoRetrieval):
|
||||
result: list[list[str]] = []
|
||||
for attribute in self.csr.subject:
|
||||
result.append(
|
||||
[cryptography_oid_to_name(attribute.oid), to_native(attribute.value)]
|
||||
[cryptography_oid_to_name(attribute.oid), to_text(attribute.value)]
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from __future__ import annotations
|
||||
import abc
|
||||
import typing as t
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -261,7 +261,7 @@ class PrivateKeyInfoRetrieval(metaclass=abc.ABCMeta):
|
||||
except OpenSSLObjectError as exc:
|
||||
raise PrivateKeyParseError(str(exc), result=result) from exc
|
||||
|
||||
result["public_key"] = to_native(self._get_public_key(binary=False))
|
||||
result["public_key"] = to_text(self._get_public_key(binary=False))
|
||||
pk = self._get_public_key(binary=True)
|
||||
result["public_key_fingerprints"] = (
|
||||
get_fingerprint_of_bytes(pk, prefer_one=prefer_one_fingerprint)
|
||||
|
||||
@@ -22,7 +22,7 @@ from urllib.error import HTTPError
|
||||
from urllib.parse import urlencode
|
||||
|
||||
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.module_utils.urls import Request
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ class RestOperationException(Exception):
|
||||
"""Encapsulate a REST API error"""
|
||||
|
||||
def __init__(self, error: dict[str, t.Any]) -> None:
|
||||
self.status = to_native(error.get("status", None))
|
||||
self.errors = [to_native(err.get("message")) for err in error.get("errors", {})]
|
||||
self.status = to_text(error.get("status", None))
|
||||
self.errors = [to_text(err.get("message")) for err in error.get("errors", {})]
|
||||
self.message = " ".join(self.errors)
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible_collections.community.crypto.plugins.module_utils._crypto.math import (
|
||||
convert_int_to_hex,
|
||||
)
|
||||
@@ -31,7 +31,7 @@ def parse_serial(value: str | bytes) -> int:
|
||||
"""
|
||||
Given a colon-separated string of hexadecimal byte values, converts it to an integer.
|
||||
"""
|
||||
value_str = to_native(value)
|
||||
value_str = to_text(value)
|
||||
result = 0
|
||||
for i, part in enumerate(value_str.split(":")):
|
||||
try:
|
||||
|
||||
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.common.text.converters import to_text
|
||||
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
@@ -118,7 +118,7 @@ def get_relative_time_option(
|
||||
|
||||
The return value will be a datetime object.
|
||||
"""
|
||||
result = to_native(input_string)
|
||||
result = to_text(input_string)
|
||||
if result is None:
|
||||
raise OpenSSLObjectError(
|
||||
f'The timespec "{input_string}" for {input_name} is not valid'
|
||||
|
||||
Reference in New Issue
Block a user