From 8ece36893c36185f0ffe84c0795959bd8a18ebd3 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 1 Aug 2019 20:57:01 -0700 Subject: [PATCH] letsencrypt: Revoke certificate only if it exists Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/letsencrypt | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/actions/letsencrypt b/actions/letsencrypt index 4b0de375c..4d4975aac 100755 --- a/actions/letsencrypt +++ b/actions/letsencrypt @@ -227,20 +227,21 @@ def subcommand_revoke(arguments): """Disable a domain and revoke the certificate.""" domain = arguments.domain - command = [ - 'certbot', 'revoke', '--non-interactive', '--domain', domain, - '--cert-path', - os.path.join(le.LIVE_DIRECTORY, domain, 'cert.pem') - ] - if TEST_MODE: - command.append('--staging') + cert_path = pathlib.Path(le.LIVE_DIRECTORY) / domain / 'cert.pem' + if cert_path.exists(): + command = [ + 'certbot', 'revoke', '--non-interactive', '--domain', domain, + '--cert-path', cert_path + ] + if TEST_MODE: + command.append('--staging') - process = subprocess.Popen(command, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - _, stderr = process.communicate() - if process.returncode: - print(stderr.decode(), file=sys.stderr) - sys.exit(1) + process = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + _, stderr = process.communicate() + if process.returncode: + print(stderr.decode(), file=sys.stderr) + sys.exit(1) action_utils.webserver_disable(domain, kind='site')