當前位置: 首頁>>代碼示例>>Python>>正文


Python CRYPTOR.decrypt方法代碼示例

本文整理匯總了Python中jumpserver.api.CRYPTOR.decrypt方法的典型用法代碼示例。如果您正苦於以下問題:Python CRYPTOR.decrypt方法的具體用法?Python CRYPTOR.decrypt怎麽用?Python CRYPTOR.decrypt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jumpserver.api.CRYPTOR的用法示例。


在下文中一共展示了CRYPTOR.decrypt方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: perm_role_edit

# 需要導入模塊: from jumpserver.api import CRYPTOR [as 別名]
# 或者: from jumpserver.api.CRYPTOR import decrypt [as 別名]
def perm_role_edit(request):
    """
    edit role page
    """
    # 渲染數據
    header_title, path1, path2 = "係統用戶", "係統用戶管理", "係統用戶編輯"

    # 渲染數據
    role_id = request.GET.get("id")
    role = PermRole.objects.get(id=role_id)
    role_pass = CRYPTOR.decrypt(role.password)
    sudo_all = PermSudo.objects.all()
    role_sudos = role.sudo.all()
    sudo_all = PermSudo.objects.all()
    if request.method == "GET":
        return my_render('jperm/perm_role_edit.html', locals(), request)

    if request.method == "POST":
        # 獲取 POST 數據
        role_name = request.POST.get("role_name")
        role_password = request.POST.get("role_password")
        role_comment = request.POST.get("role_comment")
        role_sudo_names = request.POST.getlist("sudo_name")
        role_sudos = [PermSudo.objects.get(id=sudo_id) for sudo_id in role_sudo_names]
        key_content = request.POST.get("role_key", "")
        if len(role_password) > 64:
            raise ServerError(u'密碼長度不能超過64位!')

        try:
            if not role:
                raise ServerError('該係統用戶不能存在')

            if role_name == "root":
                raise ServerError(u'禁止使用root用戶作為係統用戶,這樣非常危險!')

            if role_password:
                encrypt_pass = CRYPTOR.encrypt(role_password)
                role.password = encrypt_pass
            # 生成隨機密碼,生成秘鑰對
            if key_content:
                try:
                    key_path = gen_keys(key=key_content, key_path_dir=role.key_path)
                except SSHException:
                    raise ServerError('輸入的密鑰不合法')
                logger.debug('Recreate role key: %s' % role.key_path)
            # 寫入數據庫
            role.name = role_name
            role.comment = role_comment
            role.sudo = role_sudos

            role.save()
            msg = u"更新係統用戶: %s" % role.name
            return HttpResponseRedirect(reverse('role_list'))
        except ServerError, e:
            error = e
開發者ID:240325184,項目名稱:jumpserver,代碼行數:57,代碼來源:views.py

示例2: get_connect_info

# 需要導入模塊: from jumpserver.api import CRYPTOR [as 別名]
# 或者: from jumpserver.api.CRYPTOR import decrypt [as 別名]
 def get_connect_info(self):
     """
     獲取需要登陸的主機的信息和映射用戶的賬號密碼
     """
     asset_info = get_asset_info(self.asset)
     role_key = get_role_key(self.user, self.role)  # 獲取角色的key,因為ansible需要權限是600,所以統一生成用戶_角色key
     role_pass = CRYPTOR.decrypt(self.role.password)
     connect_info = {'user': self.user, 'asset': self.asset, 'ip': asset_info.get('ip'),
                     'port': int(asset_info.get('port')), 'role_name': self.role.name,
                     'role_pass': role_pass, 'role_key': role_key}
     logger.debug(connect_info)
     return connect_info
開發者ID:280455936,項目名稱:jumpserver,代碼行數:14,代碼來源:connect.py

示例3: get_connect_info

# 需要導入模塊: from jumpserver.api import CRYPTOR [as 別名]
# 或者: from jumpserver.api.CRYPTOR import decrypt [as 別名]
 def get_connect_info(self):
     """
     獲取需要登陸的主機的信息和映射用戶的賬號密碼
     """
     asset_info = get_asset_info(self.asset)
     role_key = get_role_key(self.user, self.role)  # 獲取角色的key,因為ansible需要權限是600,所以統一生成用戶_角色key
     role_pass = CRYPTOR.decrypt(self.role.password)
     connect_info = {
         "user": self.user,
         "asset": self.asset,
         "ip": asset_info.get("ip"),
         "port": int(asset_info.get("port")),
         "role_name": self.role.name,
         "role_pass": role_pass,
         "role_key": role_key,
     }
     logger.debug(connect_info)
     return connect_info
開發者ID:cn27001,項目名稱:jumpserver,代碼行數:20,代碼來源:connect.py

示例4: perm_role_push

# 需要導入模塊: from jumpserver.api import CRYPTOR [as 別名]
# 或者: from jumpserver.api.CRYPTOR import decrypt [as 別名]
def perm_role_push(request):
    """
    the role push page
    """
    # 渲染數據
    header_title, path1, path2 = "係統用戶", "係統用戶管理", "係統用戶推送"
    role_id = request.GET.get('id')
    asset_ids = request.GET.get('asset_id')
    role = get_object(PermRole, id=role_id)
    assets = Asset.objects.all()
    asset_groups = AssetGroup.objects.all()
    if asset_ids:
        need_push_asset = [get_object(Asset, id=asset_id) for asset_id in asset_ids.split(',')]

    if request.method == "POST":
        # 獲取推薦角色的名稱列表
        # 計算出需要推送的資產列表
        asset_ids = request.POST.getlist("assets")
        asset_group_ids = request.POST.getlist("asset_groups")
        assets_obj = [Asset.objects.get(id=asset_id) for asset_id in asset_ids]
        asset_groups_obj = [AssetGroup.objects.get(id=asset_group_id) for asset_group_id in asset_group_ids]
        group_assets_obj = []
        for asset_group in asset_groups_obj:
            group_assets_obj.extend(asset_group.asset_set.all())
        calc_assets = list(set(assets_obj) | set(group_assets_obj))

        push_resource = gen_resource(calc_assets)

        # 調用Ansible API 進行推送
        password_push = True if request.POST.get("use_password") else False
        key_push = True if request.POST.get("use_publicKey") else False
        task = MyTask(push_resource)
        ret = {}

        # 因為要先建立用戶,所以password 是必選項,而push key是在 password也完成的情況下的 可選項
        # 1. 以秘鑰 方式推送角色
        if key_push:
            ret["pass_push"] = task.add_user(role.name, CRYPTOR.decrypt(role.password))
            ret["key_push"] = task.push_key(role.name, os.path.join(role.key_path, 'id_rsa.pub'))

        # 2. 推送賬號密碼
        elif password_push:
            ret["pass_push"] = task.add_user(role.name, CRYPTOR.decrypt(role.password))

        # 3. 推送sudo配置文件
        if password_push or key_push:
            sudo_list = set([sudo for sudo in role.sudo.all()])  # set(sudo1, sudo2, sudo3)
            if sudo_list:
                ret['sudo'] = task.push_sudo_file([role], sudo_list)

        logger.debug('推送role結果: %s' % ret)
        success_asset = {}
        failed_asset = {}
        logger.debug(ret)
        for push_type, result in ret.items():
            if result.get('failed'):
                for hostname, info in result.get('failed').items():
                    if hostname in failed_asset.keys():
                        if info in failed_asset.get(hostname):
                            failed_asset[hostname] += info
                    else:
                        failed_asset[hostname] = info

        for push_type, result in ret.items():
            if result.get('ok'):
                for hostname, info in result.get('ok').items():
                    if hostname in failed_asset.keys():
                        continue
                    elif hostname in success_asset.keys():
                        if str(info) in success_asset.get(hostname, ''):
                            success_asset[hostname] += str(info)
                    else:
                        success_asset[hostname] = str(info)

        # 推送成功 回寫push表
        for asset in calc_assets:
            push_check = PermPush.objects.filter(role=role, asset=asset)
            if push_check:
                func = push_check.update
            else:
                def func(**kwargs):
                    PermPush(**kwargs).save()

            if failed_asset.get(asset.hostname):
                func(is_password=password_push, is_public_key=key_push, role=role, asset=asset, success=False,
                     result=failed_asset.get(asset.hostname))
            else:
                func(is_password=password_push, is_public_key=key_push, role=role, asset=asset, success=True)

        if not failed_asset:
            msg = u'係統用戶 %s 推送成功[ %s ]' % (role.name, ','.join(success_asset.keys()))
        else:
            error = u'係統用戶 %s 推送失敗 [ %s ], 推送成功 [ %s ] 進入係統用戶詳情,查看失敗原因' % (role.name,
                                                                ','.join(failed_asset.keys()),
                                                                ','.join(success_asset.keys()))
    return my_render('jperm/perm_role_push.html', locals(), request)
開發者ID:277800076,項目名稱:jumpserver,代碼行數:98,代碼來源:views.py


注:本文中的jumpserver.api.CRYPTOR.decrypt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。