Update build process to include certificate directory for SSL verification in frozen builds
This commit is contained in:
@@ -30,6 +30,8 @@ from local_file_picker import local_file_picker
|
||||
from local_folder_picker import local_folder_picker
|
||||
|
||||
from typing import Optional
|
||||
import tempfile
|
||||
import glob
|
||||
|
||||
from fastapi import Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
@@ -773,10 +775,46 @@ def launch_app(
|
||||
# when the user hasn't explicitly provided a CA bundle or disabled
|
||||
# verification. This lets builders ship a corporate CA with the app.
|
||||
try:
|
||||
bundled = base_path / "cert.pem"
|
||||
if bundled.exists() and VERIFY_SSL is True:
|
||||
VERIFY_SSL = str(bundled)
|
||||
logger.info(f"Using bundled CA bundle at {VERIFY_SSL}")
|
||||
# Prefer an entire bundled cert/ folder (so users can include many
|
||||
# certificate files). If present, concatenate .pem/.cer/.crt files
|
||||
# into a temporary combined bundle and use that. Otherwise fall back
|
||||
# to a single cert.pem file if present.
|
||||
bundled_dir = base_path / "cert"
|
||||
if bundled_dir.exists() and bundled_dir.is_dir() and VERIFY_SSL is True:
|
||||
# Collect candidate cert files
|
||||
patterns = ["*.pem", "*.cer", "*.crt"]
|
||||
files = []
|
||||
for p in patterns:
|
||||
files.extend(sorted(bundled_dir.glob(p)))
|
||||
|
||||
if files:
|
||||
# Create a temporary combined CA bundle file (persisted)
|
||||
tmp = tempfile.NamedTemporaryFile(delete=False, prefix="nice_uploader_ca_", suffix=".pem")
|
||||
try:
|
||||
for f in files:
|
||||
try:
|
||||
with open(f, "rb") as fh:
|
||||
tmp.write(fh.read())
|
||||
# Ensure certs are separated
|
||||
tmp.write(b"\n")
|
||||
except Exception:
|
||||
# skip unreadable files
|
||||
logger.debug(f"Skipping unreadable cert file: {f}")
|
||||
tmp.flush()
|
||||
tmp.close()
|
||||
VERIFY_SSL = str(Path(tmp.name))
|
||||
logger.info(f"Using bundled CA bundle dir combined to {VERIFY_SSL}")
|
||||
except Exception as e:
|
||||
try:
|
||||
tmp.close()
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug(f"Failed to build combined CA bundle: {e}")
|
||||
else:
|
||||
bundled = base_path / "cert.pem"
|
||||
if bundled.exists() and VERIFY_SSL is True:
|
||||
VERIFY_SSL = str(bundled)
|
||||
logger.info(f"Using bundled CA bundle at {VERIFY_SSL}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user