mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-10-22 16:31:33 +00:00
* [Feature] 1. 资产用户管理器 * [Feature] 2. 资产用户管理器: 更新AuthBook * [Feature] 3. 资产用户管理器: 添加 AssetUser API * [Feature] 4. AssetUser Model: 添加方法 load_related_asset_auth * [Feature] 5. AdminUser: 更新管理用户获取认证信息时,先加载相关资产的认证 * [Feature] 6. SystemUser: 更新系统用户获取认证信息时,先加载相关资产的认证 * [Feature] 前端页面: 添加资产用户列表页面 * [Feature] 前端页面: 管理用户的资产管理页面添加按钮: 修改资产用户认证信息 * [Feature] 前端页面: 系统用户的资产管理页面添加按钮: 修改资产用户认证信息 * [Feature] 优化: 从管理用户和系统用户的backend中获取相关资产用户的逻辑 * [Update] Fix 1 * [Feature] 优化: SystemUserBackend之filter功能 * [Feature] 优化: AdminUserBackend之filter功能 * [Feature] 优化: AdminUserBackend和SystemUserBackend功能 * [Feature] 更新翻译: 资产用户管理器 * [Update] 更新资产用户列表页名称为: asset_asset_user_list.html * [Bugfix] 修改bug: SystemUserBackend 根据用户名过滤系统用户 * [Feature] 添加: 资产用户列表中可测试资产用户的连接性 * [Update] 修改: AdHoc model的run_as字段从SystemUser外键修改为username字符串 * [Feature] 添加: 获取系统用户认证信息(对应某个资产)API * [Update] 更新: API获取asset user时进行排序 * [Bugfix] 修改: 资产用户可连接性CACHE_KEY * [Update] 更新翻译信息 * [Update] 修改获取资产用户认证信息API的返回响应(200/400) * [Update] 修改BaseUser获取特定资产的方法名 * [Update] 修改logger输出,AuthBook set_version_and_latest * [Update] 修改日志输出添加exc_info参数 * [Update] 移除AuthBook迁移文件0026 * [Bugfix] 修复AdminUserBackend获取instances为空的bug
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
|
|
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
|
from abc import abstractmethod
|
|
|
|
|
|
class NotSupportError(Exception):
|
|
pass
|
|
|
|
|
|
class BaseBackend:
|
|
ObjectDoesNotExist = ObjectDoesNotExist
|
|
MultipleObjectsReturned = MultipleObjectsReturned
|
|
NotSupportError = NotSupportError
|
|
MSG_NOT_EXIST = '{} Object matching query does not exist'
|
|
MSG_MULTIPLE = '{} get() returned more than one object ' \
|
|
'-- it returned {}!'
|
|
|
|
@classmethod
|
|
def get(cls, username, asset):
|
|
instances = cls.filter(username, asset)
|
|
if len(instances) == 1:
|
|
return instances[0]
|
|
elif len(instances) == 0:
|
|
cls.raise_does_not_exist(cls.__name__)
|
|
else:
|
|
cls.raise_multiple_return(cls.__name__, len(instances))
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def filter(cls, username=None, asset=None, latest=True):
|
|
"""
|
|
:param username: 用户名
|
|
:param asset: <Asset>对象
|
|
:param latest: 是否是最新记录
|
|
:return: 元素为<AuthBook>的可迭代对象(<list> or <QuerySet>)
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def create(cls, **kwargs):
|
|
"""
|
|
:param kwargs:
|
|
{
|
|
name, username, asset, comment, password, public_key, private_key,
|
|
(org_id)
|
|
}
|
|
:return: <AuthBook>对象
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
def raise_does_not_exist(cls, name):
|
|
raise cls.ObjectDoesNotExist(cls.MSG_NOT_EXIST.format(name))
|
|
|
|
@classmethod
|
|
def raise_multiple_return(cls, name, length):
|
|
raise cls.MultipleObjectsReturned(cls.MSG_MULTIPLE.format(name, length))
|