Skip to content

Commit d1632fb

Browse files
committed
πŸš‘πŸ› Fix TLS locations init when unsupported
Ignore TLS certificate lookup file and dir locations initialization failure when the TLS backend library doesn't support it. Ref #878
1 parent ea4622d commit d1632fb

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

β€Žpygit2/settings.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from _pygit2 import GIT_OPT_SET_CACHE_MAX_SIZE
3939
from _pygit2 import GIT_OPT_SET_SSL_CERT_LOCATIONS
4040

41+
from .errors import GitError
42+
4143

4244
__metaclass__ = type # make all classes new-style by default
4345

@@ -59,11 +61,23 @@ class Settings:
5961
_search_path = SearchPathList()
6062

6163
def __init__(self):
64+
"""Initialize global pygit2 and libgit2 settings."""
65+
self._initialize_tls_certificate_locations()
66+
67+
def _initialize_tls_certificate_locations(self):
68+
"""Set up initial TLS file and directory lookup locations."""
6269
self._default_tls_verify_paths = get_default_verify_paths()
63-
self.set_ssl_cert_locations(
64-
self._default_tls_verify_paths.cafile,
65-
self._default_tls_verify_paths.capath,
66-
)
70+
try:
71+
self.set_ssl_cert_locations(
72+
self._default_tls_verify_paths.cafile,
73+
self._default_tls_verify_paths.capath,
74+
)
75+
except GitError as git_err:
76+
valid_msg = "TLS backend doesn't support certificate locations"
77+
if str(git_err) != valid_msg:
78+
raise
79+
self._ssl_cert_file = self._default_tls_verify_paths.cafile
80+
self._ssl_cert_dir = self._default_tls_verify_paths.capath
6781

6882
@property
6983
def search_path(self):

0 commit comments

Comments
Β (0)