Allow using environment cacert file (#38816)
This commit is contained in:
1 parent
08d93b8349
commit
f207d46390
1 file changed
+7
-3
@@ -1,4 +1,5 @@
|
|||||||
"""Helper to create SSL contexts."""
|
"""Helper to create SSL contexts."""
|
||||||
|
from os import environ
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
import certifi
|
import certifi
|
||||||
@@ -6,9 +7,12 @@ import certifi
|
|||||||
|
|
||||||
def client_context() -> ssl.SSLContext:
|
def client_context() -> ssl.SSLContext:
|
||||||
"""Return an SSL context for making requests."""
|
"""Return an SSL context for making requests."""
|
||||||
context = ssl.create_default_context(
|
|
||||||
purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where()
|
# Reuse environment variable definition from requests, since it's already a requirement
|
||||||
)
|
# If the environment variable has no value, fall back to using certs from certifi package
|
||||||
|
cafile = environ.get("REQUESTS_CA_BUNDLE", certifi.where())
|
||||||
|
|
||||||
|
context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=cafile)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user