Skip to content

Commit 6992c53

Browse files
committed
Provide a fall back to CURL_CA_BUNDLE.
This is only used if we can't discover a system certs location.
1 parent 34c2826 commit 6992c53

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

doc/api/request.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Requests
1111
.. autodata:: DEFAULT_GITHUB_URL
1212

1313
.. autodata:: SYSTEM_CERTS
14+
.. autodata:: CURL_CERTS
1415

1516
.. autoexception:: GithubError
1617

github2/request.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import json as simplejson # For Python 2.6+
1919
except ImportError:
2020
import simplejson
21-
from os import path
21+
from os import (getenv, path)
2222
try:
2323
# For Python 3
2424
from urllib.parse import (parse_qs, quote, urlencode, urlsplit, urlunsplit)
@@ -41,6 +41,8 @@
4141

4242
#: Whether github2 is using the system's certificates for SSL connections
4343
SYSTEM_CERTS = not httplib2.CA_CERTS.startswith(path.dirname(httplib2.__file__))
44+
#: Whether github2 is using the cert's from the file given in $CURL_CA_BUNDLE
45+
CURL_CERTS = False
4446
if not SYSTEM_CERTS and sys.platform.startswith('linux'):
4547
for cert_file in ['/etc/ssl/certs/ca-certificates.crt',
4648
'/etc/pki/tls/certs/ca-bundle.crt']:
@@ -52,6 +54,9 @@
5254
if path.exists('/usr/local/share/certs/ca-root-nss.crt'):
5355
CA_CERTS = '/usr/local/share/certs/ca-root-nss.crt'
5456
SYSTEM_CERTS = True
57+
elif path.exists(getenv('CURL_CA_BUNDLE', '')):
58+
CA_CERTS = getenv('CURL_CA_BUNDLE')
59+
CURL_CERTS = True
5560
else:
5661
CA_CERTS = path.join(path.dirname(path.abspath(__file__)),
5762
"DigiCert_High_Assurance_EV_Root_CA.crt")
@@ -142,6 +147,8 @@ def __init__(self, username=None, api_token=None, url_prefix=None,
142147
self._http.ca_certs = CA_CERTS
143148
if SYSTEM_CERTS:
144149
LOGGER.info('Using system certificates in %r', CA_CERTS)
150+
elif CURL_CERTS:
151+
LOGGER.info("Using cURL's certificates in %r", CA_CERTS)
145152
else:
146153
LOGGER.warning('Using bundled certificate for HTTPS connections')
147154

0 commit comments

Comments
 (0)