mirror of
https://github.com/moepman/acertmgr.git
synced 2025-01-04 02:35:23 +01:00
Make key location dynamic
Besides the fact that this removes redundant code, hard coded location of file is generally no good idea Also adapt README.md and provide a default location for key files. Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
79210c5a80
commit
a0e7dd66ea
@ -51,6 +51,8 @@ All configuration files use yaml syntax.
|
||||
mode: webdir
|
||||
#mode: standalone
|
||||
#port: 13135
|
||||
account_key: "/etc/acme/account.key"
|
||||
server_key: "/etc/acme/server.key"
|
||||
webdir: /var/www/acme-challenge/
|
||||
authority: "https://acme-v01.api.letsencrypt.org"
|
||||
#authority: "https://acme-staging.api.letsencrypt.org"
|
||||
|
25
acertmgr.py
25
acertmgr.py
@ -23,6 +23,8 @@ ACME_DIR="/etc/acme"
|
||||
ACME_CONF=os.path.join(ACME_DIR, "acme.conf")
|
||||
ACME_CONFD=os.path.join(ACME_DIR, "domains.d")
|
||||
|
||||
ACME_DEFAULT_SERVER_KEY = os.path.join(ACME_DIR, "server.key")
|
||||
ACME_DEFAULT_ACCOUNT_KEY = os.path.join(ACME_DIR, "account.key")
|
||||
|
||||
class FileNotFoundError(OSError):
|
||||
pass
|
||||
@ -70,11 +72,11 @@ def cert_get(domains, settings):
|
||||
domain = domains.split(' ')[0]
|
||||
print("Getting certificate for %s." % domain)
|
||||
|
||||
key_file = os.path.join(ACME_DIR, "server.key")
|
||||
key_file = settings['server_key']
|
||||
if not os.path.isfile(key_file):
|
||||
raise FileNotFoundError("The server key file (%s) is missing!" % key_file)
|
||||
|
||||
acc_file = os.path.join(ACME_DIR, "account.key")
|
||||
acc_file = settings['account_key']
|
||||
if not os.path.isfile(acc_file):
|
||||
raise FileNotFoundError("The account key file (%s) is missing!" % acc_file)
|
||||
|
||||
@ -128,7 +130,7 @@ def cert_put(domain, settings):
|
||||
crt_format = settings['format'].split(",")
|
||||
crt_action = settings['action']
|
||||
|
||||
key_file = os.path.join(ACME_DIR, "server.key")
|
||||
key_file = settings['server_key']
|
||||
crt_final = os.path.join(ACME_DIR, ("%s.crt" % domain.split(' ')[0]))
|
||||
|
||||
with open(crt_path, "w+") as crt_fd:
|
||||
@ -170,11 +172,12 @@ def cert_put(domain, settings):
|
||||
# @param domainconfig the domain configuration
|
||||
# @param defaults the default configuration
|
||||
# @return the augmented configuration
|
||||
def complete_config(domainconfig, defaults):
|
||||
if defaults:
|
||||
for name, value in defaults.items():
|
||||
if name not in domainconfig:
|
||||
domainconfig[name] = value
|
||||
def complete_config(domainconfig, globalconfig):
|
||||
defaults = globalconfig['defaults']
|
||||
domainconfig['server_key'] = globalconfig['server_key']
|
||||
for name, value in defaults.items():
|
||||
if name not in domainconfig:
|
||||
domainconfig[name] = value
|
||||
if 'action' not in domainconfig:
|
||||
domainconfig['action'] = None
|
||||
return domainconfig
|
||||
@ -189,6 +192,10 @@ if __name__ == "__main__":
|
||||
config = {}
|
||||
if 'defaults' not in config:
|
||||
config['defaults'] = {}
|
||||
if 'server_key' not in config:
|
||||
config['server_key'] = ACME_DEFAULT_SERVER_KEY
|
||||
if 'account_key' not in config:
|
||||
config['account_key'] = ACME_DEFAULT_ACCOUNT_KEY
|
||||
|
||||
config['domains'] = []
|
||||
# load domain configuration
|
||||
@ -211,7 +218,7 @@ if __name__ == "__main__":
|
||||
if not cert_isValid(crt_file, ttl_days):
|
||||
cert_get(domains, config)
|
||||
for domaincfg in domaincfgs:
|
||||
cfg = complete_config(domaincfg, config['defaults'])
|
||||
cfg = complete_config(domaincfg, config)
|
||||
if not target_isCurrent(cfg['path'], crt_file):
|
||||
actions.add(cert_put(domains, cfg))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user