mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:32:13 +02:00
Improve code reuse
This commit is contained in:
+9
-17
@@ -320,30 +320,27 @@ class Client(object):
|
|||||||
cert_pem = OpenSSL.crypto.dump_certificate(
|
cert_pem = OpenSSL.crypto.dump_certificate(
|
||||||
OpenSSL.crypto.FILETYPE_PEM, certr.body.wrapped)
|
OpenSSL.crypto.FILETYPE_PEM, certr.body.wrapped)
|
||||||
|
|
||||||
cert_file, act_cert_path = _open_pem_file('cert_path', cert_path)
|
cert_file, abs_cert_path = _open_pem_file('cert_path', cert_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cert_file.write(cert_pem)
|
cert_file.write(cert_pem)
|
||||||
finally:
|
finally:
|
||||||
cert_file.close()
|
cert_file.close()
|
||||||
logger.info("Server issued certificate; certificate written to %s",
|
logger.info("Server issued certificate; certificate written to %s",
|
||||||
act_cert_path)
|
abs_cert_path)
|
||||||
|
|
||||||
cert_chain_abspath = None
|
|
||||||
fullchain_abspath = None
|
|
||||||
if chain_cert:
|
if chain_cert:
|
||||||
chain_pem = crypto_util.dump_pyopenssl_chain(chain_cert)
|
chain_pem = crypto_util.dump_pyopenssl_chain(chain_cert)
|
||||||
|
|
||||||
chain_file, act_chain_path =\
|
chain_file, abs_chain_path =\
|
||||||
_open_pem_file('chain_path', chain_path)
|
_open_pem_file('chain_path', chain_path)
|
||||||
fullchain_file, act_fullchain_path =\
|
fullchain_file, abs_fullchain_path =\
|
||||||
_open_pem_file('fullchain_path', fullchain_path)
|
_open_pem_file('fullchain_path', fullchain_path)
|
||||||
|
|
||||||
cert_chain_abspath = _save_chain(chain_pem, chain_file)
|
_save_chain(chain_pem, chain_file)
|
||||||
fullchain_abspath = _save_chain(cert_pem + chain_pem,
|
_save_chain(cert_pem + chain_pem, fullchain_file
|
||||||
fullchain_file)
|
|
||||||
|
|
||||||
return os.path.abspath(act_cert_path), cert_chain_abspath, fullchain_abspath
|
return abs_cert_path, abs_chain_path, abs_fullchain_path
|
||||||
|
|
||||||
def deploy_certificate(self, domains, privkey_path,
|
def deploy_certificate(self, domains, privkey_path,
|
||||||
cert_path, chain_path, fullchain_path):
|
cert_path, chain_path, fullchain_path):
|
||||||
@@ -577,7 +574,8 @@ def _open_pem_file(cli_arg_path, pem_path):
|
|||||||
return le_util.safe_open(pem_path, chmod=0o644),\
|
return le_util.safe_open(pem_path, chmod=0o644),\
|
||||||
os.path.abspath(pem_path)
|
os.path.abspath(pem_path)
|
||||||
else:
|
else:
|
||||||
return le_util.unique_file(pem_path, 0o644)
|
uniq = le_util.unique_file(pem_path, 0o644)
|
||||||
|
return uniq[0], os.path.abspath(uniq)
|
||||||
|
|
||||||
def _save_chain(chain_pem, chain_file):
|
def _save_chain(chain_pem, chain_file):
|
||||||
"""Saves chain_pem at a unique path based on chain_path.
|
"""Saves chain_pem at a unique path based on chain_path.
|
||||||
@@ -585,9 +583,6 @@ def _save_chain(chain_pem, chain_file):
|
|||||||
:param str chain_pem: certificate chain in PEM format
|
:param str chain_pem: certificate chain in PEM format
|
||||||
:param str chain_file: chain file object
|
:param str chain_file: chain file object
|
||||||
|
|
||||||
:returns: absolute path to saved cert chain
|
|
||||||
:rtype: str
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
chain_file.write(chain_pem)
|
chain_file.write(chain_pem)
|
||||||
@@ -595,6 +590,3 @@ def _save_chain(chain_pem, chain_file):
|
|||||||
chain_file.close()
|
chain_file.close()
|
||||||
|
|
||||||
logger.info("Cert chain written to %s", chain_file.name)
|
logger.info("Cert chain written to %s", chain_file.name)
|
||||||
|
|
||||||
# This expects a valid chain file
|
|
||||||
return os.path.abspath(chain_file.name)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user