Gracefully handle lack of key/cert files.

This commit is contained in:
Solderpunk 2019-08-14 21:39:35 +03:00
parent 808edc594a
commit 5ddc43e77a
1 changed files with 8 additions and 2 deletions

View File

@ -7,13 +7,12 @@ import subprocess
import socket
import socketserver
import ssl
import sys
import tempfile
import urllib.parse
HOST, PORT = "localhost", 1965
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.load_cert_chain(certfile="cert.pem", keyfile="key.pem")
class AgenaHandler(socketserver.BaseRequestHandler):
@ -190,6 +189,13 @@ class AgenaHandler(socketserver.BaseRequestHandler):
if __name__ == "__main__":
if not (os.path.exists("cert.pem") and os.path.exists("key.pem")):
print("Couldn't find cert.pem and/or key.pem. :(")
sys.exit(1)
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.load_cert_chain(certfile="cert.pem", keyfile="key.pem")
agena = socketserver.TCPServer((HOST, PORT), AgenaHandler)
try:
agena.serve_forever()