forked from sethryder/certman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certbot.py
46 lines (34 loc) · 1.64 KB
/
certbot.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
import os, sys, logging
from subprocess import Popen, PIPE
from helpers import *
def generateCertificates(config_object, domain_objects):
certbot_binary_path = config_object['certbot_binary_path']
certbot_arguments = config_object['certbot_arguments']
hash_file_directory = config_object['hash_file_directory']
for primary_domain, config in domain_objects.iteritems():
if 'additional_domains' in config:
config_hash = generateHash(primary_domain, config['additional_domains'])
else:
config_hash = generateHash(primary_domain)
saved_hash = getSavedHash(primary_domain, hash_file_directory)
if saved_hash != config_hash:
print "Making some certs!"
command = certbot_binary_path + ' certonly ' + certbot_arguments
command = command + " -d " + primary_domain
if 'additional_domains' in config:
for additional_domain in config['additional_domains']:
command = command + ' -d ' + additional_domain
p = Popen(command, shell=True, stdout=PIPE)
output = p.communicate()[0]
if p.returncode != 0:
logError("Unable to generate certificate(s). Command:" + command)
else:
setSavedHash(primary_domain, hash_file_directory, config_hash)
def renewCertificates(certbot_binary_path, certbot_arguments):
command = certbot_binary_path + ' renew ' + certbot_arguments
p = Popen(command, shell=True, stdout=PIPE)
output = p.communicate()[0]
if p.returncode != 0:
print "Something went wrong."
else:
print "All good!"