summaryrefslogtreecommitdiff
path: root/src/conf_mode/le_cert.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/conf_mode/le_cert.py')
-rwxr-xr-xsrc/conf_mode/le_cert.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/conf_mode/le_cert.py b/src/conf_mode/le_cert.py
index c657098e1..a4dbecbaa 100755
--- a/src/conf_mode/le_cert.py
+++ b/src/conf_mode/le_cert.py
@@ -18,11 +18,12 @@
import sys
import os
-import subprocess
import vyos.defaults
from vyos.config import Config
from vyos import ConfigError
+from vyos.util import cmd, run
+
vyos_conf_scripts_dir = vyos.defaults.directories['conf_mode']
@@ -45,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()
@@ -84,28 +85,21 @@ def generate(cert):
# certbot will attempt to reload nginx, even with 'certonly';
# start nginx if not active
- ret = os.system('systemctl is-active --quiet nginx.ervice')
+ ret = run('systemctl is-active --quiet nginx.ervice')
if ret:
- os.system('sudo systemctl start nginx.service')
+ 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: