summaryrefslogtreecommitdiff
path: root/src/conf_mode/vyos_cert.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-07 08:27:36 +0200
committerGitHub <noreply@github.com>2020-04-07 08:27:36 +0200
commit09ad28b28c9ebd9308cfe9048686b3b0ef9cfd9c (patch)
tree6e7b0971ecd8859cff864b3ebb37f86f8ba288f5 /src/conf_mode/vyos_cert.py
parente0f13b79a669e7fc8cadac8757b2f5fbbf51dc99 (diff)
parent7256810914e6664bf92041dcd7c3daf649ce0001 (diff)
downloadvyos-1x-09ad28b28c9ebd9308cfe9048686b3b0ef9cfd9c.tar.gz
vyos-1x-09ad28b28c9ebd9308cfe9048686b3b0ef9cfd9c.zip
Merge pull request #307 from thomas-mangin/T2226
util: T2226: convert all call to use vyos.util.{popen, cmd, run}
Diffstat (limited to 'src/conf_mode/vyos_cert.py')
-rwxr-xr-xsrc/conf_mode/vyos_cert.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/conf_mode/vyos_cert.py b/src/conf_mode/vyos_cert.py
index 4a44573ca..8b8953cb7 100755
--- a/src/conf_mode/vyos_cert.py
+++ b/src/conf_mode/vyos_cert.py
@@ -18,7 +18,6 @@
import sys
import os
-import subprocess
import tempfile
import pathlib
import ssl
@@ -26,6 +25,7 @@ import ssl
import vyos.defaults
from vyos.config import Config
from vyos import ConfigError
+from vyos.util import cmd
vyos_conf_scripts_dir = vyos.defaults.directories['conf_mode']
@@ -49,16 +49,16 @@ def status_self_signed(cert_data):
# check if certificate is 1/2 past lifetime, with openssl -checkend
end_days = int(cert_data['lifetime'])
end_seconds = int(0.5*60*60*24*end_days)
- checkend_cmd = ('openssl x509 -checkend {end} -noout -in {crt}'
- ''.format(end=end_seconds, **cert_data))
+ checkend_cmd = 'openssl x509 -checkend {end} -noout -in {crt}'.format(end=end_seconds, **cert_data)
try:
- subprocess.check_call(checkend_cmd, shell=True)
+ cmd(checkend_cmd, message='Called process error')
return True
- except subprocess.CalledProcessError as err:
- if err.returncode == 1:
+ except OSError as err:
+ if err.errno == 1:
return False
- else:
- print("Called process error: {}.".format(err))
+ print(err)
+ # XXX: This seems wrong to continue on failure
+ # implicitely returning None
def generate_self_signed(cert_data):
san_config = None
@@ -86,9 +86,10 @@ def generate_self_signed(cert_data):
''.format(**cert_data))
try:
- subprocess.check_call(openssl_req_cmd, shell=True)
- except subprocess.CalledProcessError as err:
- print("Called process error: {}.".format(err))
+ cmd(openssl_req_cmd, message='Called process error')
+ except OSError as err:
+ print(err)
+ # XXX: seems wrong to ignore the failure
os.chmod('{key}'.format(**cert_data), 0o400)
@@ -126,11 +127,8 @@ def generate(vyos_cert):
def apply(vyos_cert):
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("{}.".format(err))
+ command = '{0}/{1}'.format(vyos_conf_scripts_dir, dep)
+ cmd(command, raising=ConfigError)
if __name__ == '__main__':
try: