Skip to content

Commit

Permalink
Remove overriding of tempfile.tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Dec 5, 2024
1 parent a144f88 commit 14e1fc7
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/ert/ensemble_evaluator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,16 @@ def get_server_ssl_context(
) -> typing.Optional[ssl.SSLContext]:
if self.cert is None:
return None
backup_default_tmp = tempfile.tempdir
try:
tempfile.tempdir = os.environ.get("XDG_RUNTIME_DIR", tempfile.gettempdir())
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = pathlib.Path(tmp_dir)
cert_path = tmp_path / "ee.crt"
with open(cert_path, "w", encoding="utf-8") as filehandle_1:
filehandle_1.write(self.cert)

key_path = tmp_path / "ee.key"
if self._key is not None:
with open(key_path, "wb") as filehandle_2:
filehandle_2.write(self._key)
context = ssl.SSLContext(protocol=protocol)
context.load_cert_chain(cert_path, key_path, self._key_pw)
return context
finally:
tempfile.tempdir = backup_default_tmp
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = pathlib.Path(tmp_dir)
cert_path = tmp_path / "ee.crt"
with open(cert_path, "w", encoding="utf-8") as filehandle_1:
filehandle_1.write(self.cert)

key_path = tmp_path / "ee.key"
if self._key is not None:
with open(key_path, "wb") as filehandle_2:
filehandle_2.write(self._key)
context = ssl.SSLContext(protocol=protocol)
context.load_cert_chain(cert_path, key_path, self._key_pw)
return context

0 comments on commit 14e1fc7

Please sign in to comment.