-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
entrypoint.py
executable file
·38 lines (30 loc) · 1013 Bytes
/
entrypoint.py
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
#!/usr/bin/env python3
import os
import sys
import time
from typing import Tuple
from basecert import BaseCert
from func import lookup_env
from letsencryptcert import LetsEncryptCert
from selfsignedcert import SelfSignedCert
if __name__ == "__main__":
mode_choices: Optional[Dict[str, BaseCert]] = {
"self-signed": SelfSignedCert(),
"letsencrypt": LetsEncryptCert(),
}
cert_store: str = lookup_env("CERT_STORE")
for subdir in ["nginx", "selfsigned"]:
os.makedirs(f"{cert_store}/{subdir}", 0o755, True)
cert_mode: str = lookup_env("CERT_MODE")
print(f"Running in {cert_mode} mode")
cert_obj = mode_choices.get(cert_mode, None)
if cert_obj:
cert_obj.create()
while True:
# sleep for 12 hours before checking for renewal
time.sleep(12 * 3600)
cert_obj.renew()
else:
print(f"Cannot run {cert_mode} mode")
# Should never get here but if we do, return a big return code
sys.exit(99)