mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 13:22:58 +00:00
Replace % and str.format() with f-strings (#875)
* Replace % and str.format() with f-strings. * Apply suggestions from review.
This commit is contained in:
@@ -54,9 +54,7 @@ from ansible_collections.community.crypto.plugins.plugin_utils.gnupg import (
|
||||
def gpg_fingerprint(input):
|
||||
if not isinstance(input, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type} instead".format(
|
||||
type=type(input)
|
||||
)
|
||||
f"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type(input)} instead"
|
||||
)
|
||||
try:
|
||||
gpg = PluginGPGRunner()
|
||||
|
||||
@@ -292,19 +292,16 @@ def openssl_csr_info_filter(data, name_encoding="ignore"):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.openssl_csr_info input must be a text type, not %s"
|
||||
% type(data)
|
||||
f"The community.crypto.openssl_csr_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if not isinstance(name_encoding, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The name_encoding option must be of a text type, not %s"
|
||||
% type(name_encoding)
|
||||
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||
)
|
||||
name_encoding = to_native(name_encoding)
|
||||
if name_encoding not in ("ignore", "idna", "unicode"):
|
||||
raise AnsibleFilterError(
|
||||
'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "%s"'
|
||||
% name_encoding
|
||||
f'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "{name_encoding}"'
|
||||
)
|
||||
|
||||
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||
|
||||
@@ -167,17 +167,15 @@ def openssl_privatekey_info_filter(
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.openssl_privatekey_info input must be a text type, not %s"
|
||||
% type(data)
|
||||
f"The community.crypto.openssl_privatekey_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if passphrase is not None and not isinstance(passphrase, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The passphrase option must be a text type, not %s" % type(passphrase)
|
||||
f"The passphrase option must be a text type, not {type(passphrase)}"
|
||||
)
|
||||
if not isinstance(return_private_key_data, bool):
|
||||
raise AnsibleFilterError(
|
||||
"The return_private_key_data option must be a boolean, not %s"
|
||||
% type(return_private_key_data)
|
||||
f"The return_private_key_data option must be a boolean, not {type(return_private_key_data)}"
|
||||
)
|
||||
|
||||
module = FilterModuleMock({})
|
||||
|
||||
@@ -142,8 +142,7 @@ def openssl_publickey_info_filter(data):
|
||||
"""Extract information from OpenSSL PEM public key."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.openssl_publickey_info input must be a text type, not %s"
|
||||
% type(data)
|
||||
f"The community.crypto.openssl_publickey_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
|
||||
module = FilterModuleMock({})
|
||||
|
||||
@@ -50,9 +50,7 @@ from ansible_collections.community.crypto.plugins.module_utils.serial import (
|
||||
def parse_serial_filter(input):
|
||||
if not isinstance(input, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The input for the community.crypto.parse_serial filter must be a string; got {type} instead".format(
|
||||
type=type(input)
|
||||
)
|
||||
f"The input for the community.crypto.parse_serial filter must be a string; got {type(input)} instead"
|
||||
)
|
||||
try:
|
||||
return parse_serial(to_native(input))
|
||||
|
||||
@@ -50,8 +50,7 @@ def split_pem_filter(data):
|
||||
"""Split PEM file."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.split_pem input must be a text type, not %s"
|
||||
% type(data)
|
||||
f"The community.crypto.split_pem input must be a text type, not {type(data)}"
|
||||
)
|
||||
|
||||
data = to_text(data)
|
||||
|
||||
@@ -48,9 +48,7 @@ from ansible_collections.community.crypto.plugins.module_utils.serial import to_
|
||||
def to_serial_filter(input):
|
||||
if not isinstance(input, integer_types):
|
||||
raise AnsibleFilterError(
|
||||
"The input for the community.crypto.to_serial filter must be an integer; got {type} instead".format(
|
||||
type=type(input)
|
||||
)
|
||||
f"The input for the community.crypto.to_serial filter must be an integer; got {type(input)} instead"
|
||||
)
|
||||
if input < 0:
|
||||
raise AnsibleFilterError(
|
||||
|
||||
@@ -326,19 +326,16 @@ def x509_certificate_info_filter(data, name_encoding="ignore"):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.x509_certificate_info input must be a text type, not %s"
|
||||
% type(data)
|
||||
f"The community.crypto.x509_certificate_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if not isinstance(name_encoding, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The name_encoding option must be of a text type, not %s"
|
||||
% type(name_encoding)
|
||||
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||
)
|
||||
name_encoding = to_native(name_encoding)
|
||||
if name_encoding not in ("ignore", "idna", "unicode"):
|
||||
raise AnsibleFilterError(
|
||||
'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "%s"'
|
||||
% name_encoding
|
||||
f'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "{name_encoding}"'
|
||||
)
|
||||
|
||||
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||
|
||||
@@ -177,24 +177,20 @@ def x509_crl_info_filter(data, name_encoding="ignore", list_revoked_certificates
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.x509_crl_info input must be a text type, not %s"
|
||||
% type(data)
|
||||
f"The community.crypto.x509_crl_info input must be a text type, not {type(data)}"
|
||||
)
|
||||
if not isinstance(name_encoding, string_types):
|
||||
raise AnsibleFilterError(
|
||||
"The name_encoding option must be of a text type, not %s"
|
||||
% type(name_encoding)
|
||||
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||
)
|
||||
if not isinstance(list_revoked_certificates, bool):
|
||||
raise AnsibleFilterError(
|
||||
"The list_revoked_certificates option must be a boolean, not %s"
|
||||
% type(list_revoked_certificates)
|
||||
f"The list_revoked_certificates option must be a boolean, not {type(list_revoked_certificates)}"
|
||||
)
|
||||
name_encoding = to_native(name_encoding)
|
||||
if name_encoding not in ("ignore", "idna", "unicode"):
|
||||
raise AnsibleFilterError(
|
||||
'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "%s"'
|
||||
% name_encoding
|
||||
f'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "{name_encoding}"'
|
||||
)
|
||||
|
||||
data = to_bytes(data)
|
||||
|
||||
Reference in New Issue
Block a user