Skip to content

Commit 12a13ff

Browse files
author
Markus Opolka
committed
Refactor fix_tls function to avoid silent errors
1 parent 847f14b commit 12a13ff

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

check_vmware_nsxt.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@
5858
}
5959

6060

61-
def fix_tls_cert_store():
61+
def fix_tls_cert_store(cafile_path):
6262
"""
6363
Ensure we are using the system certstore by default
6464
6565
See https://github.com/psf/requests/issues/2966
6666
Inspired by https://github.com/psf/requests/issues/2966#issuecomment-614323746
6767
"""
6868

69-
try:
70-
system_ca_store = ssl.get_default_verify_paths().cafile
71-
if os.stat(system_ca_store).st_size > 0:
72-
requests.utils.DEFAULT_CA_BUNDLE_PATH = system_ca_store
73-
requests.adapters.DEFAULT_CA_BUNDLE_PATH = system_ca_store
74-
except:
75-
pass
69+
# Check if we got a CA file path
70+
if not cafile_path:
71+
return
72+
73+
# If CA file contains something, set as default
74+
if os.stat(cafile_path).st_size > 0:
75+
requests.utils.DEFAULT_CA_BUNDLE_PATH = cafile_path
76+
requests.adapters.DEFAULT_CA_BUNDLE_PATH = cafile_path
7677

7778

7879
class CriticalException(Exception):
@@ -406,7 +407,7 @@ def commandline(args):
406407

407408

408409
def main(args):
409-
fix_tls_cert_store()
410+
fix_tls_cert_store(ssl.get_default_verify_paths().cafile)
410411

411412
if args.insecure:
412413
urllib3.disable_warnings()

0 commit comments

Comments
 (0)