7
7
8
8
from flask import Flask
9
9
from flask_login import LoginManager
10
+ import tempfile
10
11
11
12
global_config = Config_Loader ().config ["global" ]
12
13
app_config = Config_Loader ().config ["interfaces" ]["chat_app" ]
@@ -79,10 +80,24 @@ def load_user(user_id):
79
80
print (f"Starting Chat Service with (host, port): ({ app_config ['HOST' ]} , { app_config ['PORT' ]} )" )
80
81
app = FlaskAppWrapper (app )
81
82
if app_config ["HOSTNAME" ] == "a2rchi.mit.edu" :
83
+
82
84
print ("Adding SSL certificates for a2rchi.mit.edu" )
83
- certificate_path = os .getenv ("A2RCHI_SSL_CERTIFICATE_FILE" )
84
- key_path = os .getenv ("A2RCHI_SSL_CERTIFICATE_KEY_FILE" )
85
- app .run (debug = True , port = app_config ["PORT" ], host = app_config ["HOST" ], ssl_context = (certificate_path , key_path ))
85
+
86
+ #get the ssl cert and key and save them to temporary files
87
+ ssl_cert = read_secret ("A2RCHI_SSL_CERTIFICATE" )
88
+ ssl_key = read_secret ("A2RCHI_SSL_CERTIFICATE_KEY" )
89
+ cert_file = tempfile .NamedTemporaryFile (delete = False )
90
+ key_file = tempfile .NamedTemporaryFile (delete = False )
91
+ cert_file .write (ssl_cert .encode ())
92
+ key_file .write (ssl_key .encode ())
93
+
94
+ app .run (debug = True , port = app_config ["PORT" ], host = app_config ["HOST" ], ssl_context = (cert_file .name , key_file .name ))
95
+
96
+ #remove the temp ssl cert and key temp files
97
+ os .unlink (cert_file .name )
98
+ os .unlink (key_file .name )
99
+
86
100
else :
101
+
87
102
print ("No SSL certificate for this server found. Starting up with adhoc SSL certification" )
88
103
app .run (debug = True , port = app_config ["PORT" ], host = app_config ["HOST" ], ssl_context = "adhoc" )
0 commit comments