Skip to content
Snippets Groups Projects
Commit 10b3f461 authored by Rafael Guterres Jeffman's avatar Rafael Guterres Jeffman
Browse files

pylint: Modify certificate loader function definition.

This patch modifies the way that the certificate load function is
defined, depending on the dependency version, so that the resulting
identifier for the function is always set and static analysis tools,
like linters don't complain about variables being used before being
set.

The same idiom is applied to both the ipaclient role and the plugins
ansible_module_utils.
parent b7e39ce7
No related branches found
No related tags found
No related merge requests found
......@@ -99,9 +99,10 @@ try:
try:
from ipalib.x509 import load_pem_x509_certificate
certificate_loader = load_pem_x509_certificate
except ImportError:
from ipalib.x509 import load_certificate
load_pem_x509_certificate = None
certificate_loader = load_certificate
# Try to import is_ipa_configured or use a fallback implementation.
try:
......@@ -147,7 +148,6 @@ except ImportError as _err:
uuid = None
netaddr = None
is_ipa_configured = None
load_certificate = None
kerberos = None
ipaserver = None # pylint: disable=C0103
else:
......@@ -588,10 +588,7 @@ def load_cert_from_str(cert):
if not cert.endswith("-----END CERTIFICATE-----"):
cert += "\n-----END CERTIFICATE-----"
if load_pem_x509_certificate is not None:
cert = load_pem_x509_certificate(cert.encode('utf-8'))
else:
cert = load_certificate(cert.encode('utf-8'))
cert = certificate_loader(cert.encode('utf-8'))
return cert
......
......@@ -196,9 +196,10 @@ else:
try:
from ipalib.x509 import load_pem_x509_certificate
certificate_loader = load_pem_x509_certificate
except ImportError:
from ipalib.x509 import load_certificate
load_pem_x509_certificate = None
certificate_loader = load_certificate
try:
from ipaserver.install.server.install import get_min_idstart
......@@ -426,10 +427,7 @@ else:
if not cert.endswith("-----END CERTIFICATE-----"):
cert += "\n-----END CERTIFICATE-----"
if load_pem_x509_certificate is not None:
cert = load_pem_x509_certificate(cert.encode('utf-8'))
else:
cert = load_certificate(cert.encode('utf-8'))
cert = certificate_loader(cert.encode('utf-8'))
else:
cert = base64.b64decode(cert)
return cert
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment