Skip to content

Commit

Permalink
fix ca_file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Dec 3, 2024
1 parent 5ac790e commit f98e562
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .evergreen/mongodl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import re
import shutil
import sqlite3
import ssl
import sys
import tarfile
import textwrap
Expand All @@ -45,12 +46,13 @@
cast,
)

SSL_CONTEXT = ssl.create_default_context()
try:
import certifi

CA_FILE = certifi.where()
SSL_CONTEXT.load_verify_locations(certifi.where())
except ImportError:
CA_FILE = None
pass

# These versions are used for performance benchmarking. Do not update to a newer version.
PERF_VERSIONS = {"v6.0-perf": "6.0.6", "v8.0-perf": "8.0.1"}
Expand Down Expand Up @@ -587,7 +589,7 @@ def download_file(self, url: str) -> DownloadResult:
req = urllib.request.Request(url, headers=headers)

try:
resp = urllib.request.urlopen(req, cafile=CA_FILE)
resp = urllib.request.urlopen(req, context=SSL_CONTEXT)
except urllib.error.HTTPError as e:
if e.code != 304:
raise RuntimeError(f"Failed to download [{url}]") from e
Expand Down
4 changes: 2 additions & 2 deletions .evergreen/mongosh_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

HERE = Path(__file__).absolute().parent
sys.path.insert(0, str(HERE))
from mongodl import CA_FILE, ExpandResult, _expand_archive, infer_arch
from mongodl import SSL_CONTEXT, ExpandResult, _expand_archive, infer_arch


def _get_latest_version():
Expand All @@ -29,7 +29,7 @@ def _get_latest_version():
url = "https://api.github.com/repos/mongodb-js/mongosh/releases"
req = urllib.request.Request(url, headers=headers)
try:
resp = urllib.request.urlopen(req, cafile=CA_FILE)
resp = urllib.request.urlopen(req, context=SSL_CONTEXT)
except Exception:
return _get_latest_version_git()

Expand Down

0 comments on commit f98e562

Please sign in to comment.