mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-08 14:22:56 +00:00
Get rid of backend parameter whenever possible (#883)
* Get rid of backend parameter whenever possible. * Always auto-detect if backend choices are 'cryptography' and 'auto', resp. always check cryptography version. * Improve error message. * Update documentation.
This commit is contained in:
@@ -425,9 +425,8 @@ crl:
|
||||
|
||||
import base64
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
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 (
|
||||
@@ -471,6 +470,7 @@ from ansible_collections.community.crypto.plugins.module_utils.crypto.support im
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils.cryptography_dep import (
|
||||
COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION,
|
||||
assert_required_cryptography_version,
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils.io import write_file
|
||||
from ansible_collections.community.crypto.plugins.module_utils.serial import (
|
||||
@@ -479,16 +479,11 @@ from ansible_collections.community.crypto.plugins.module_utils.serial import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils.time import (
|
||||
get_relative_time_option,
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils.version import (
|
||||
LooseVersion,
|
||||
)
|
||||
|
||||
|
||||
MINIMAL_CRYPTOGRAPHY_VERSION = COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION
|
||||
|
||||
CRYPTOGRAPHY_IMP_ERR = None
|
||||
try:
|
||||
import cryptography
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.primitives.serialization import Encoding
|
||||
from cryptography.x509 import (
|
||||
@@ -497,13 +492,8 @@ try:
|
||||
NameAttribute,
|
||||
RevokedCertificateBuilder,
|
||||
)
|
||||
|
||||
CRYPTOGRAPHY_VERSION = LooseVersion(cryptography.__version__)
|
||||
except ImportError:
|
||||
CRYPTOGRAPHY_IMP_ERR = traceback.format_exc()
|
||||
CRYPTOGRAPHY_FOUND = False
|
||||
else:
|
||||
CRYPTOGRAPHY_FOUND = True
|
||||
pass
|
||||
|
||||
|
||||
class CRLError(OpenSSLObjectError):
|
||||
@@ -582,9 +572,7 @@ class CRL(OpenSSLObject):
|
||||
try:
|
||||
if rc["content"] is not None:
|
||||
rc["content"] = rc["content"].encode("utf-8")
|
||||
cert = load_certificate(
|
||||
rc["path"], content=rc["content"], backend="cryptography"
|
||||
)
|
||||
cert = load_certificate(rc["path"], content=rc["content"])
|
||||
result["serial_number"] = cert.serial_number
|
||||
except OpenSSLObjectError as e:
|
||||
if rc["content"] is not None:
|
||||
@@ -631,7 +619,6 @@ class CRL(OpenSSLObject):
|
||||
path=self.privatekey_path,
|
||||
content=self.privatekey_content,
|
||||
passphrase=self.privatekey_passphrase,
|
||||
backend="cryptography",
|
||||
)
|
||||
except OpenSSLBadPassphraseError as exc:
|
||||
raise CRLError(exc)
|
||||
@@ -1011,11 +998,7 @@ def main():
|
||||
add_file_common_args=True,
|
||||
)
|
||||
|
||||
if not CRYPTOGRAPHY_FOUND:
|
||||
module.fail_json(
|
||||
msg=missing_required_lib(f"cryptography >= {MINIMAL_CRYPTOGRAPHY_VERSION}"),
|
||||
exception=CRYPTOGRAPHY_IMP_ERR,
|
||||
)
|
||||
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION)
|
||||
|
||||
try:
|
||||
crl = CRL(module)
|
||||
|
||||
Reference in New Issue
Block a user