diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-05 17:30:28 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-06 20:22:35 +0100 |
commit | 35183754914db6e5a783734c6d655a66a6168988 (patch) | |
tree | b9769f06f2ea8a3cc64b3e289d94d33ca1b662f9 | |
parent | 928a136b0978411b551a5ae13232dac785daf53f (diff) | |
download | vyos-1x-35183754914db6e5a783734c6d655a66a6168988.tar.gz vyos-1x-35183754914db6e5a783734c6d655a66a6168988.zip |
util: T2226: rewrite certbot to use cmd
-rwxr-xr-x | src/conf_mode/le_cert.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/conf_mode/le_cert.py b/src/conf_mode/le_cert.py index c0df77710..a4dbecbaa 100755 --- a/src/conf_mode/le_cert.py +++ b/src/conf_mode/le_cert.py @@ -18,7 +18,6 @@ import sys import os -import subprocess import vyos.defaults from vyos.config import Config @@ -47,9 +46,9 @@ def request_certbot(cert): certbot_cmd = 'certbot certonly -n --nginx --agree-tos --no-eff-email --expand {0} {1}'.format(email_flag, domain_flag) - completed = subprocess.run(certbot_cmd, shell=True) - - return completed.returncode + cmd(certbot_cmd, + raising=ConfigError, + message="The certbot request failed for the specified domains.") def get_config(): conf = Config() @@ -90,24 +89,17 @@ def generate(cert): if ret: run('sudo systemctl start nginx.service') - ret = request_certbot(cert) - if ret: - raise ConfigError("The certbot request failed for the" - " specified domains.") + request_certbot(cert) def apply(cert): if cert is not None: - os.system('sudo systemctl restart certbot.timer') + run('sudo systemctl restart certbot.timer') else: - os.system('sudo systemctl stop certbot.timer') + run('sudo systemctl stop certbot.timer') return None for dep in dependencies: - cmd = '{0}/{1}'.format(vyos_conf_scripts_dir, dep) - try: - subprocess.check_call(cmd, shell=True) - except subprocess.CalledProcessError as err: - raise ConfigError(str(err)) + cmd(f'{vyos_conf_scripts_dir}/{dep}', raising=ConfigError) if __name__ == '__main__': try: |