File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -961,12 +961,18 @@ async def run(self):
961961 }
962962 with gifnoc .overlay (overrides ):
963963 app = create_app ()
964+ ssl_config = config .server .ssl
965+ ssl_kwargs = {}
966+ if ssl_config and ssl_config .enabled :
967+ ssl_kwargs ["ssl_certfile" ] = ssl_config .cert_file
968+ ssl_kwargs ["ssl_keyfile" ] = ssl_config .key_file
964969 server = uvicorn .Server (
965970 uvicorn .Config (
966971 app ,
967972 host = config .server .host if self .host is None else self .host ,
968973 port = config .server .port if self .port is None else self .port ,
969974 reload = self .reload ,
975+ ** ssl_kwargs ,
970976 )
971977 )
972978 await server .serve ()
Original file line number Diff line number Diff line change 11from dataclasses import dataclass , field
2+ from functools import cached_property
23from pathlib import Path
4+ from tempfile import NamedTemporaryFile
35from typing import Literal
46
57import gifnoc
@@ -34,6 +36,25 @@ class Refine:
3436 prompt : TaggedSubclass [Prompt ] = field (default_factory = GenAIPrompt )
3537
3638
39+ @dataclass (kw_only = True )
40+ class SSLConfig :
41+ enabled : bool = True
42+ cert : str
43+ key : Secret [str ]
44+
45+ @cached_property
46+ def cert_file (self ):
47+ with NamedTemporaryFile (mode = "w" , suffix = ".pem" , delete = False ) as cf :
48+ cf .write (self .cert )
49+ return cf .name
50+
51+ @cached_property
52+ def key_file (self ):
53+ with NamedTemporaryFile (mode = "w" , suffix = ".pem" , delete = False ) as kf :
54+ kf .write (self .key )
55+ return kf .name
56+
57+
3758@dataclass (kw_only = True )
3859class Server :
3960 host : str = "localhost"
@@ -43,6 +64,7 @@ class Server:
4364 max_results : int = 10000
4465 auth : OAuthManager = None
4566 assets : Path = None
67+ ssl : SSLConfig = None
4668
4769 def __post_init__ (self ):
4870 if self .external_host is None :
You can’t perform that action at this time.
0 commit comments