File tree 3 files changed +49
-0
lines changed
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ import base64
2
+ import ssl
3
+ import os
4
+ import tempfile
5
+
6
+
7
+ def start_fastapi (app ):
8
+ cert , key , client_cert = save_certificates_from_env ()
9
+ import uvicorn
10
+ uvicorn .run (
11
+ app ,
12
+ host = "127.0.0.1" ,
13
+ port = int (os .getenv ("PORT" )),
14
+ ssl_certfile = cert ,
15
+ ssl_keyfile = key ,
16
+ ssl_ca_certs = client_cert ,
17
+ ssl_cert_reqs = ssl .CERT_REQUIRED ,
18
+ )
19
+
20
+ def save_certificates_from_env ():
21
+ cert = base64 .b64decode (os .getenv ("CERT" , "" ))
22
+ key = base64 .b64decode (os .getenv ("PRIVATE_KEY" , "" ))
23
+ client_cert = base64 .b64decode (os .getenv ("GPTSCRIPT_CERT" , "" ))
24
+
25
+ if cert == "" :
26
+ print ("error: CERT env var is empty" )
27
+ exit (1 )
28
+ elif key == "" :
29
+ print ("error: PRIVATE_KEY env var is empty" )
30
+ exit (1 )
31
+ elif client_cert == "" :
32
+ print ("error: GPTSCRIPT_CERT env var is empty" )
33
+ exit (1 )
34
+
35
+ cert_file = tempfile .NamedTemporaryFile (delete = False , suffix = ".pem" )
36
+ key_file = tempfile .NamedTemporaryFile (delete = False , suffix = ".pem" )
37
+ client_cert_file = tempfile .NamedTemporaryFile (delete = False , suffix = ".pem" )
38
+
39
+ cert_file .write (cert )
40
+ key_file .write (key )
41
+ client_cert_file .write (client_cert )
42
+
43
+ cert_file .close ()
44
+ key_file .close ()
45
+ client_cert_file .close ()
46
+
47
+ return cert_file .name , key_file .name , client_cert_file .name
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ dependencies = [
19
19
" urllib3==2.2.1" ,
20
20
" pydantic==2.9.2" ,
21
21
" pywin32==306 ; sys_platform == 'win32'" ,
22
+ " uvicorn==0.32.1" ,
22
23
]
23
24
24
25
[project .urls ]
Original file line number Diff line number Diff line change @@ -12,3 +12,4 @@ build==1.1.1
12
12
httpx == 0.27.0
13
13
pydantic == 2.9.2
14
14
pywin32 == 306 ; sys_platform == 'win32'
15
+ uvicorn == 0.32.1
You can’t perform that action at this time.
0 commit comments