Fix assert_required_cryptography_version() calls.

This commit is contained in:
Felix Fontein
2025-05-03 12:55:50 +02:00
parent 83beb7148c
commit 12f958c955
20 changed files with 60 additions and 20 deletions

View File

@@ -330,7 +330,9 @@ def select_backend(module, provider):
""" """
provider.validate_module_args(module) provider.validate_module_args(module)
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
if provider.needs_version_two_certs(module): if provider.needs_version_two_certs(module):
# TODO: remove # TODO: remove

View File

@@ -434,5 +434,7 @@ def get_certificate_info(module, content, prefer_one_fingerprint=False):
def select_backend(module, content): def select_backend(module, content):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return CertificateInfoRetrievalCryptography(module, content) return CertificateInfoRetrievalCryptography(module, content)

View File

@@ -84,7 +84,9 @@ class CRLInfoRetrieval:
def get_crl_info(module, content, list_revoked_certificates=True): def get_crl_info(module, content, list_revoked_certificates=True):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
info = CRLInfoRetrieval( info = CRLInfoRetrieval(
module, content, list_revoked_certificates=list_revoked_certificates module, content, list_revoked_certificates=list_revoked_certificates
) )

View File

@@ -733,7 +733,9 @@ class CertificateSigningRequestCryptographyBackend(CertificateSigningRequestBack
def select_backend(module): def select_backend(module):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return CertificateSigningRequestCryptographyBackend(module) return CertificateSigningRequestCryptographyBackend(module)

View File

@@ -348,7 +348,9 @@ def get_csr_info(
def select_backend(module, content, validate_signature=True): def select_backend(module, content, validate_signature=True):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return CSRInfoRetrievalCryptography( return CSRInfoRetrievalCryptography(
module, content, validate_signature=validate_signature module, content, validate_signature=validate_signature
) )

View File

@@ -542,7 +542,9 @@ class PrivateKeyCryptographyBackend(PrivateKeyBackend):
def select_backend(module): def select_backend(module):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return PrivateKeyCryptographyBackend(module) return PrivateKeyCryptographyBackend(module)

View File

@@ -248,7 +248,9 @@ class PrivateKeyConvertCryptographyBackend(PrivateKeyConvertBackend):
def select_backend(module): def select_backend(module):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return PrivateKeyConvertCryptographyBackend(module) return PrivateKeyConvertCryptographyBackend(module)

View File

@@ -297,7 +297,9 @@ def select_backend(
return_private_key_data=False, return_private_key_data=False,
check_consistency=False, check_consistency=False,
): ):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return PrivateKeyInfoRetrievalCryptography( return PrivateKeyInfoRetrievalCryptography(
module, module,
content, content,

View File

@@ -144,5 +144,7 @@ def get_publickey_info(module, content=None, key=None, prefer_one_fingerprint=Fa
def select_backend(module, content=None, key=None): def select_backend(module, content=None, key=None):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return PublicKeyInfoRetrievalCryptography(module, content=content, key=key) return PublicKeyInfoRetrievalCryptography(module, content=content, key=key)

View File

@@ -207,7 +207,9 @@ def main():
mutually_exclusive=(["private_key_src", "private_key_content"],), mutually_exclusive=(["private_key_src", "private_key_content"],),
) )
assert_required_cryptography_version(COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION
)
try: try:
# Get parameters # Get parameters

View File

@@ -323,7 +323,9 @@ def main():
supports_check_mode=True, supports_check_mode=True,
) )
assert_required_cryptography_version(COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION
)
# Load chain # Load chain
chain = parse_PEM_list(module, module.params["input_chain"], source="input chain") chain = parse_PEM_list(module, module.params["input_chain"], source="input chain")

View File

@@ -994,7 +994,9 @@ def main():
supports_check_mode=True, supports_check_mode=True,
) )
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
# If validate_only is used, pointing to an existing tracking_id is an invalid operation # If validate_only is used, pointing to an existing tracking_id is an invalid operation
if module.params["tracking_id"]: if module.params["tracking_id"]:

View File

@@ -361,7 +361,9 @@ def main():
f"The Python version used to run the get_certificate module is {sys.version}" f"The Python version used to run the get_certificate module is {sys.version}"
) )
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
result = dict( result = dict(
changed=False, changed=False,

View File

@@ -411,7 +411,9 @@ def main():
if backend == "openssl": if backend == "openssl":
dhparam = DHParameterOpenSSL(module) dhparam = DHParameterOpenSSL(module)
elif backend == "cryptography": elif backend == "cryptography":
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
dhparam = DHParameterCryptography(module) dhparam = DHParameterCryptography(module)
else: else:
raise AssertionError("Internal error: unknown backend") raise AssertionError("Internal error: unknown backend")

View File

@@ -712,7 +712,9 @@ class PkcsCryptography(Pkcs):
def select_backend(module): def select_backend(module):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
return PkcsCryptography(module) return PkcsCryptography(module)

View File

@@ -428,7 +428,9 @@ def main():
mutually_exclusive=(["privatekey_path", "privatekey_content"],), mutually_exclusive=(["privatekey_path", "privatekey_content"],),
) )
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
base_dir = os.path.dirname(module.params["path"]) or "." base_dir = os.path.dirname(module.params["path"]) or "."
if not os.path.isdir(base_dir): if not os.path.isdir(base_dir):

View File

@@ -245,7 +245,9 @@ def main():
msg=f"The file {module.params['path']} does not exist", msg=f"The file {module.params['path']} does not exist",
) )
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
try: try:
_sign = SignatureCryptography(module) _sign = SignatureCryptography(module)

View File

@@ -250,7 +250,9 @@ def main():
msg=f"The file {module.params['path']} does not exist", msg=f"The file {module.params['path']} does not exist",
) )
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
try: try:
_sign = SignatureInfoCryptography(module) _sign = SignatureInfoCryptography(module)

View File

@@ -222,7 +222,9 @@ class X509CertificateConvertModule(OpenSSLObject):
pass pass
def verify_cert_parsable(self, module): def verify_cert_parsable(self, module):
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
try: try:
load_der_x509_certificate(self.input) load_der_x509_certificate(self.input)
except Exception as exc: except Exception as exc:

View File

@@ -998,7 +998,9 @@ def main():
add_file_common_args=True, add_file_common_args=True,
) )
assert_required_cryptography_version(MINIMAL_CRYPTOGRAPHY_VERSION) assert_required_cryptography_version(
module, minimum_cryptography_version=MINIMAL_CRYPTOGRAPHY_VERSION
)
try: try:
crl = CRL(module) crl = CRL(module)