Clean up acme certs on destroy. (#51)

This will prevent the acme.sh cron job from continuing to request
certificates for apps which have been destroyed.
pull/50/head^2
Chris McCormick 2019-06-28 19:55:34 +08:00 zatwierdzone przez Rui Carmo
rodzic 3ce615ec7a
commit d26fb6ee1c
1 zmienionych plików z 11 dodań i 1 usunięć

12
piku.py
Wyświetl plik

@ -16,7 +16,7 @@ from glob import glob
from hashlib import md5 from hashlib import md5
from json import loads from json import loads
from multiprocessing import cpu_count from multiprocessing import cpu_count
from os import chmod, getgid, getuid, unlink, remove, stat, listdir, environ, makedirs, O_NONBLOCK from os import chmod, getgid, getuid, symlink, unlink, remove, stat, listdir, environ, makedirs, O_NONBLOCK
from os.path import abspath, basename, dirname, exists, getmtime, join, realpath, splitext from os.path import abspath, basename, dirname, exists, getmtime, join, realpath, splitext
from re import sub from re import sub
from shutil import copyfile, rmtree, which from shutil import copyfile, rmtree, which
@ -573,6 +573,8 @@ def spawn_app(app, deltas={}):
echo("-----> getting letsencrypt certificate") echo("-----> getting letsencrypt certificate")
call('{acme:s}/acme.sh --issue -d {domain:s} -w {www:s}'.format(**locals()), shell=True) call('{acme:s}/acme.sh --issue -d {domain:s} -w {www:s}'.format(**locals()), shell=True)
call('{acme:s}/acme.sh --install-cert -d {domain:s} --key-file {key:s} --fullchain-file {crt:s}'.format(**locals()), shell=True) call('{acme:s}/acme.sh --install-cert -d {domain:s} --key-file {key:s} --fullchain-file {crt:s}'.format(**locals()), shell=True)
if exists(join(ACME_ROOT, domain)) and not exists(join(ACME_WWW, app)):
symlink(join(ACME_ROOT, domain), join(ACME_WWW, app))
else: else:
echo("-----> letsencrypt certificate already installed") echo("-----> letsencrypt certificate already installed")
@ -979,6 +981,14 @@ def cmd_destroy(app):
echo("Removing file '{}'".format(f), fg='yellow') echo("Removing file '{}'".format(f), fg='yellow')
remove(f) remove(f)
acme_link = join(ACME_WWW, app)
acme_certs = realpath(acme_link)
if exists(acme_certs):
echo("Removing folder '{}'".format(acme_certs), fg='yellow')
rmtree(acme_certs)
echo("Removing file '{}'".format(acme_link), fg='yellow')
unlink(acme_link)
@piku.command("logs") @piku.command("logs")
@argument('app') @argument('app')