mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-08 06:13:03 +00:00
Reformat everything with black.
I had to undo the u string prefix removals to not drop Python 2 compatibility. That's why black isn't enabled in antsibull-nox.toml yet.
This commit is contained in:
@@ -57,7 +57,9 @@ 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))
|
||||
"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type} instead".format(
|
||||
type=type(input)
|
||||
)
|
||||
)
|
||||
try:
|
||||
gpg = PluginGPGRunner()
|
||||
@@ -67,9 +69,9 @@ def gpg_fingerprint(input):
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'gpg_fingerprint': gpg_fingerprint,
|
||||
"gpg_fingerprint": gpg_fingerprint,
|
||||
}
|
||||
|
||||
@@ -292,27 +292,38 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
)
|
||||
|
||||
|
||||
def openssl_csr_info_filter(data, name_encoding='ignore'):
|
||||
'''Extract information from X.509 PEM certificate.'''
|
||||
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))
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.openssl_csr_info input must be a text type, not %s"
|
||||
% 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))
|
||||
raise AnsibleFilterError(
|
||||
"The name_encoding option must be of a text type, not %s"
|
||||
% 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)
|
||||
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
|
||||
)
|
||||
|
||||
module = FilterModuleMock({'name_encoding': name_encoding})
|
||||
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||
try:
|
||||
return get_csr_info(module, 'cryptography', content=to_bytes(data), validate_signature=True)
|
||||
return get_csr_info(
|
||||
module, "cryptography", content=to_bytes(data), validate_signature=True
|
||||
)
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(to_native(exc))
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'openssl_csr_info': openssl_csr_info_filter,
|
||||
"openssl_csr_info": openssl_csr_info_filter,
|
||||
}
|
||||
|
||||
@@ -165,20 +165,36 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
)
|
||||
|
||||
|
||||
def openssl_privatekey_info_filter(data, passphrase=None, return_private_key_data=False):
|
||||
'''Extract information from X.509 PEM certificate.'''
|
||||
def openssl_privatekey_info_filter(
|
||||
data, passphrase=None, return_private_key_data=False
|
||||
):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError('The community.crypto.openssl_privatekey_info input must be a text type, not %s' % type(data))
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.openssl_privatekey_info input must be a text type, not %s"
|
||||
% 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))
|
||||
raise AnsibleFilterError(
|
||||
"The passphrase option must be a text type, not %s" % 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))
|
||||
raise AnsibleFilterError(
|
||||
"The return_private_key_data option must be a boolean, not %s"
|
||||
% type(return_private_key_data)
|
||||
)
|
||||
|
||||
module = FilterModuleMock({})
|
||||
try:
|
||||
result = get_privatekey_info(module, 'cryptography', content=to_bytes(data), passphrase=passphrase, return_private_key_data=return_private_key_data)
|
||||
result.pop('can_parse_key', None)
|
||||
result.pop('key_is_consistent', None)
|
||||
result = get_privatekey_info(
|
||||
module,
|
||||
"cryptography",
|
||||
content=to_bytes(data),
|
||||
passphrase=passphrase,
|
||||
return_private_key_data=return_private_key_data,
|
||||
)
|
||||
result.pop("can_parse_key", None)
|
||||
result.pop("key_is_consistent", None)
|
||||
return result
|
||||
except PrivateKeyParseError as exc:
|
||||
raise AnsibleFilterError(exc.error_message)
|
||||
@@ -187,9 +203,9 @@ def openssl_privatekey_info_filter(data, passphrase=None, return_private_key_dat
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'openssl_privatekey_info': openssl_privatekey_info_filter,
|
||||
"openssl_privatekey_info": openssl_privatekey_info_filter,
|
||||
}
|
||||
|
||||
@@ -143,13 +143,16 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
|
||||
|
||||
def openssl_publickey_info_filter(data):
|
||||
'''Extract information from OpenSSL PEM public key.'''
|
||||
"""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))
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.openssl_publickey_info input must be a text type, not %s"
|
||||
% type(data)
|
||||
)
|
||||
|
||||
module = FilterModuleMock({})
|
||||
try:
|
||||
return get_publickey_info(module, 'cryptography', content=to_bytes(data))
|
||||
return get_publickey_info(module, "cryptography", content=to_bytes(data))
|
||||
except PublicKeyParseError as exc:
|
||||
raise AnsibleFilterError(exc.error_message)
|
||||
except OpenSSLObjectError as exc:
|
||||
@@ -157,9 +160,9 @@ def openssl_publickey_info_filter(data):
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'openssl_publickey_info': openssl_publickey_info_filter,
|
||||
"openssl_publickey_info": openssl_publickey_info_filter,
|
||||
}
|
||||
|
||||
@@ -53,7 +53,9 @@ 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))
|
||||
"The input for the community.crypto.parse_serial filter must be a string; got {type} instead".format(
|
||||
type=type(input)
|
||||
)
|
||||
)
|
||||
try:
|
||||
return parse_serial(to_native(input))
|
||||
@@ -62,9 +64,9 @@ def parse_serial_filter(input):
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'parse_serial': parse_serial_filter,
|
||||
"parse_serial": parse_serial_filter,
|
||||
}
|
||||
|
||||
@@ -51,18 +51,21 @@ from ansible_collections.community.crypto.plugins.module_utils.crypto.pem import
|
||||
|
||||
|
||||
def split_pem_filter(data):
|
||||
'''Split PEM file.'''
|
||||
"""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))
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.split_pem input must be a text type, not %s"
|
||||
% type(data)
|
||||
)
|
||||
|
||||
data = to_text(data)
|
||||
return split_pem_list(data)
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'split_pem': split_pem_filter,
|
||||
"split_pem": split_pem_filter,
|
||||
}
|
||||
|
||||
@@ -51,10 +51,14 @@ 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))
|
||||
"The input for the community.crypto.to_serial filter must be an integer; got {type} instead".format(
|
||||
type=type(input)
|
||||
)
|
||||
)
|
||||
if input < 0:
|
||||
raise AnsibleFilterError('The input for the community.crypto.to_serial filter must not be negative')
|
||||
raise AnsibleFilterError(
|
||||
"The input for the community.crypto.to_serial filter must not be negative"
|
||||
)
|
||||
try:
|
||||
return to_serial(input)
|
||||
except ValueError as exc:
|
||||
@@ -62,9 +66,9 @@ def to_serial_filter(input):
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'to_serial': to_serial_filter,
|
||||
"to_serial": to_serial_filter,
|
||||
}
|
||||
|
||||
@@ -326,27 +326,36 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
)
|
||||
|
||||
|
||||
def x509_certificate_info_filter(data, name_encoding='ignore'):
|
||||
'''Extract information from X.509 PEM certificate.'''
|
||||
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))
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.x509_certificate_info input must be a text type, not %s"
|
||||
% 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))
|
||||
raise AnsibleFilterError(
|
||||
"The name_encoding option must be of a text type, not %s"
|
||||
% 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)
|
||||
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
|
||||
)
|
||||
|
||||
module = FilterModuleMock({'name_encoding': name_encoding})
|
||||
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||
try:
|
||||
return get_certificate_info(module, 'cryptography', content=to_bytes(data))
|
||||
return get_certificate_info(module, "cryptography", content=to_bytes(data))
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(to_native(exc))
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'x509_certificate_info': x509_certificate_info_filter,
|
||||
"x509_certificate_info": x509_certificate_info_filter,
|
||||
}
|
||||
|
||||
@@ -177,17 +177,29 @@ from ansible_collections.community.crypto.plugins.plugin_utils.filter_module imp
|
||||
)
|
||||
|
||||
|
||||
def x509_crl_info_filter(data, name_encoding='ignore', list_revoked_certificates=True):
|
||||
'''Extract information from X.509 PEM certificate.'''
|
||||
def x509_crl_info_filter(data, name_encoding="ignore", list_revoked_certificates=True):
|
||||
"""Extract information from X.509 PEM certificate."""
|
||||
if not isinstance(data, string_types):
|
||||
raise AnsibleFilterError('The community.crypto.x509_crl_info input must be a text type, not %s' % type(data))
|
||||
raise AnsibleFilterError(
|
||||
"The community.crypto.x509_crl_info input must be a text type, not %s"
|
||||
% 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))
|
||||
raise AnsibleFilterError(
|
||||
"The name_encoding option must be of a text type, not %s"
|
||||
% 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))
|
||||
raise AnsibleFilterError(
|
||||
"The list_revoked_certificates option must be a boolean, not %s"
|
||||
% 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)
|
||||
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
|
||||
)
|
||||
|
||||
data = to_bytes(data)
|
||||
if not identify_pem_format(data):
|
||||
@@ -196,17 +208,19 @@ def x509_crl_info_filter(data, name_encoding='ignore', list_revoked_certificates
|
||||
except (binascii.Error, TypeError, ValueError, UnicodeEncodeError):
|
||||
pass
|
||||
|
||||
module = FilterModuleMock({'name_encoding': name_encoding})
|
||||
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||
try:
|
||||
return get_crl_info(module, content=data, list_revoked_certificates=list_revoked_certificates)
|
||||
return get_crl_info(
|
||||
module, content=data, list_revoked_certificates=list_revoked_certificates
|
||||
)
|
||||
except OpenSSLObjectError as exc:
|
||||
raise AnsibleFilterError(to_native(exc))
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
'''Ansible jinja2 filters'''
|
||||
"""Ansible jinja2 filters"""
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'x509_crl_info': x509_crl_info_filter,
|
||||
"x509_crl_info": x509_crl_info_filter,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user