|
14 | 14 |
|
15 | 15 | import http.server
|
16 | 16 | import logging
|
| 17 | +import socketserver |
17 | 18 | import ssl
|
18 | 19 | from pathlib import Path
|
19 | 20 |
|
@@ -65,17 +66,27 @@ def run_server(port: int, config_path: Path, routing_config_dir: Path, cert_path
|
65 | 66 |
|
66 | 67 | logging.basicConfig(level=logging.DEBUG, format="[%(levelname)s] %(message)s")
|
67 | 68 |
|
68 |
| - config: Configuration = load_configurations(config_path, routing_config_dir) |
| 69 | + if not config_path.is_file(): |
| 70 | + raise ValueError(f"'{config_path}' is not a file") |
69 | 71 |
|
70 |
| - logging.info("Server starting on port %s", port) |
71 |
| - server_address = ("", port) |
| 72 | + if not routing_config_dir.is_dir(): |
| 73 | + raise ValueError(f"'{routing_config_dir}' is not a directory") |
72 | 74 |
|
73 |
| - theMockServerHandler = createMockServerHandler(config) |
| 75 | + if not cert_path.is_file(): |
| 76 | + raise ValueError(f"'{cert_path}' is not a file") |
74 | 77 |
|
75 |
| - httpd = http.server.ThreadingHTTPServer(server_address, theMockServerHandler) |
76 |
| - context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) |
| 78 | + if not key_path.is_file(): |
| 79 | + raise ValueError(f"'{key_path}' is not a file") |
| 80 | + |
| 81 | + config: Configuration = load_configurations(config_path, routing_config_dir) |
| 82 | + server_address: socketserver._AfInetAddress = ("", port) |
| 83 | + context: ssl.SSLContext = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) |
77 | 84 | context.load_cert_chain(certfile=cert_path, keyfile=key_path)
|
78 | 85 |
|
| 86 | + theMockServerHandler = createMockServerHandler(config) |
| 87 | + httpd = http.server.ThreadingHTTPServer(server_address, theMockServerHandler) |
| 88 | + |
| 89 | + logging.info("Server starting on port %s", port) |
79 | 90 | with context.wrap_socket(httpd.socket, server_side=True) as httpd.socket:
|
80 | 91 | logging.info("Server started on port %s", port)
|
81 | 92 | logging.info("HTTPS enabled with cert: %s and key: %s", cert_path, key_path)
|
|
0 commit comments