forked from sethryder/certman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certman.py
62 lines (57 loc) · 2.37 KB
/
certman.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python -W ignore::DeprecationWarning
import getopt, sys
from helpers import *
from cloudfront import *
from certbot import *
import logging
config_file = "/etc/certman.conf"
config = loadConfig(config_file)
domain_objects = loadDomainConfigs(config['domain_config_directory'])
def certbot():
ran = False
try:
opts, args = getopt.getopt(sys.argv[1:], "agrudwlh", [
"all",
"generate-certificates",
"renew-certificates",
"upload-certificates",
"update-cloudfront-distributions",
"list",
"help"])
except getopt.GetoptError, err:
print str(err) # will print something like "option -z not recognized"
usage()
sys.exit(2)
for opt, arg in opts:
ran = True
if opt in ("-a", "--all"):
updateCloudFrontWellKnown(domain_objects, config['certbot_server'])
generateCertificates(config, domain_objects)
renewCertificates(config['certbot_binary_path'], config['certbot_arguments'])
uploadCloudFrontCertificates(domain_objects, config['certbot_certificate_path'])
updateCloudFrontDistributions(domain_objects, config['certbot_certificate_path'])
elif opt in ("-g", "--generate-certificates"):
generateCertificates(config, domain_objects)
elif opt in ("-r", "--renew-certificates"):
renewCertificates(config['certbot_binary_path'], config['certbot_arguments'])
elif opt in ("-u", "--upload-certificates"):
uploadCloudFrontCertificates(domain_objects, config['certbot_certificate_path'])
elif opt in ("-d", "--update-cloudfront-distributions"):
updateCloudFrontDistributions(domain_objects, config['certbot_certificate_path'])
elif opt in ("-w", "--add-well-known"):
updateCloudFrontWellKnown(domain_objects, config['certbot_server'])
elif opt in ("-l", "--list"):
for domain in domain_objects.keys():
certs_info = listCertificates(domain)
print("%s: " % domain)
for i in certs_info:
for k,v in i.iteritems():
print(" %s: %s" % (k,v))
elif opt in ("-h", "--help"):
usage()
else:
assert False, "unhandled option"
if not ran:
usage()
if __name__ == "__main__":
certbot()