diff --git a/jperm/utils.py b/jperm/utils.py index 92506cdc1..ecdac7f81 100644 --- a/jperm/utils.py +++ b/jperm/utils.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import random import os.path import shutil from paramiko import SSHException @@ -8,9 +7,9 @@ from paramiko.rsakey import RSAKey from jumpserver.api import mkdir from uuid import uuid4 from jumpserver.api import CRYPTOR -from os import makedirs -from tempfile import NamedTemporaryFile +from jumpserver.api import logger + from jumpserver.settings import KEY_DIR @@ -55,9 +54,9 @@ def gen_keys(key="", key_path_dir=""): with open(key_file) as f: try: key = RSAKey.from_private_key(f) - except SSHException: + except SSHException, e: shutil.rmtree(key_path_dir, ignore_errors=True) - raise SSHException + raise SSHException(e) os.chmod(private_key, 0644) with open(public_key, 'w') as content_file: diff --git a/jperm/views.py b/jperm/views.py index cb9a7d46e..7af646f9f 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -294,7 +294,10 @@ def perm_role_add(request): # 生成随机密码,生成秘钥对 sudos_obj = [get_object(PermSudo, id=sudo_id) for sudo_id in sudo_ids] if key_content: - key_path = gen_keys(key=key_content) + try: + key_path = gen_keys(key=key_content) + except SSHException, e: + raise ServerError(e) else: key_path = gen_keys() logger.debug('generate role key: %s' % key_path) @@ -305,7 +308,6 @@ def perm_role_add(request): return HttpResponseRedirect(reverse('role_list')) except ServerError, e: error = e - return my_render('jperm/perm_role_add.html', locals(), request) diff --git a/templates/jperm/perm_role_add.html b/templates/jperm/perm_role_add.html index 65a7d8037..ab2ac43b2 100644 --- a/templates/jperm/perm_role_add.html +++ b/templates/jperm/perm_role_add.html @@ -50,7 +50,7 @@