-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_https.py
More file actions
76 lines (67 loc) · 2.02 KB
/
Copy pathrun_https.py
File metadata and controls
76 lines (67 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import argparse
import os
import uvicorn
# Generate e.g. a self-signed cert using:
# openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj "/CN=zooprocess.com"
def main():
parser = argparse.ArgumentParser(description="Run ASGI app with Uvicorn over HTTPS")
parser.add_argument(
"--host",
default=os.getenv("HOST", "0.0.0.0"),
help="Bind host (default: 0.0.0.0)",
)
parser.add_argument(
"--port",
type=int,
default=int(os.getenv("PORT", "8443")),
help="HTTPS port (default: 8443)",
)
parser.add_argument(
"--proxy-headers",
action="store_true",
default=os.getenv("PROXY_HEADERS", "true").lower() == "true",
help="Respect X-Forwarded-* headers",
)
parser.add_argument(
"--forwarded-allow-ips",
default=os.getenv("FORWARDED_ALLOW_IPS", "*"),
help="Comma list of allowed proxy IPs; '*' to trust all",
)
# TLS-related
parser.add_argument(
"--certfile",
default=os.getenv("SSL_CERTFILE", "/etc/certs/cert.pem"),
help="Path to TLS cert",
)
parser.add_argument(
"--keyfile",
default=os.getenv("SSL_KEYFILE", "/etc/certs/key.pem"),
help="Path to TLS key",
)
parser.add_argument(
"--ca-certs",
default=os.getenv("SSL_CA_CERTS"),
help="Optional CA bundle for client certs",
)
parser.add_argument(
"--ciphers",
default=os.getenv("SSL_CIPHERS"),
help="Optional OpenSSL cipher suite string",
)
args = parser.parse_args()
uvicorn.run(
app="main:app",
host=args.host,
port=args.port,
reload=False,
workers=1,
proxy_headers=args.proxy_headers,
forwarded_allow_ips=args.forwarded_allow_ips,
ssl_certfile=args.certfile,
ssl_keyfile=args.keyfile,
ssl_ca_certs=args.ca_certs,
ssl_ciphers=args.ciphers,
)
if __name__ == "__main__":
main()