From 3248ee1a3d441d42286a98df9f924abd67d216b4 Mon Sep 17 00:00:00 2001 From: yumaojun <719118794@qq.com> Date: Tue, 22 Dec 2015 22:39:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0role=20?= =?UTF-8?q?=E6=97=B6=E3=80=80=E5=9B=A0=E7=A7=81=E9=92=A5=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9=E8=80=8C=E5=BC=95=E8=B5=B7=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/utils.py | 9 ++++----- jperm/views.py | 6 ++++-- templates/jperm/perm_role_add.html | 9 ++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) 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 @@