mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-04-28 03:21:12 +00:00
* Bai reactor tree ( 重构获取完整资产树中节点下资产总数的逻辑) (#5548) * tree: v0.1 * tree: v0.2 * tree: v0.3 * tree: v0.4 * tree: 添加并发锁未请求到时的debug日志 * 以空间换时间的方式优化资产树 * Reactor tree togther v2 (#5576) * Bai reactor tree ( 重构获取完整资产树中节点下资产总数的逻辑) (#5548) * tree: v0.1 * tree: v0.2 * tree: v0.3 * tree: v0.4 * tree: 添加并发锁未请求到时的debug日志 * 以空间换时间的方式优化资产树 * 修改授权适配新方案 * 添加树处理工具 * 完成新的用户授权树计算以及修改一些信号 * 重构了获取资产的一些 api * 重构了一些节点的api * 整理了一些代码 * 完成了api 的重构 * 重构检查节点数量功能 * 完成重构授权树工具类 * api 添加强制刷新参数 * 整理一些信号 * 处理一些信号的问题 * 完成了信号的处理 * 重构了资产树相关的锁机制 * RebuildUserTreeTask 还得添加回来 * 优化下不能在root组织的检查函数 * 优化资产树变化时锁的使用 * 修改一些算法的小工具 * 资产树锁不再校验是否在具体组织里 * 整理了一些信号的位置 * 修复资产与节点关系维护的bug * 去掉一些调试代码 * 修复资产授权过期检查刷新授权树的 bug * 添加了可重入锁 * 添加一些计时,优化一些sql * 增加 union 查询的支持 * 尝试用 sql 解决节点资产数量问题 * 开始优化计算授权树节点资产数量不用冗余表 * 新代码能跑起来了,修复一下bug * 去掉 UserGrantedMappingNode 换成 UserAssetGrantedTreeNodeRelation * 修了些bug,做了些优化 * 优化QuerySetStage 执行逻辑 * 与小白的内存结合了 * 删掉老的表,迁移新的 assets_amount 字段 * 优化用户授权页面资产列表 count 慢 * 修复批量命令数量不对 * 修改获取非直接授权节点的 children 的逻辑 * 获取整棵树的节点 * 回退锁 * 整理迁移脚本 * 改变更新树策略 * perf: 修改一波缩进 * fix: 修改handler名称 * 修复授权树获取资产sql 泛滥 * 修复授权规则有效bug * 修复一些bug * 修复一些bug * 又修了一些小bug * 去掉了老的 get_nodes_all_assets * 修改一些写法 * Reactor tree togther b2 (#5570) * fix: 修改handler名称 * perf: 优化生成树 * perf: 去掉注释 * 优化了一些 * 重新生成迁移脚本 * 去掉周期检查节点资产数量的任务 * Pr@reactor tree togther guang@perf mapping (#5573) * fix: 修改handler名称 * perf: mapping 拆分出来 * 修改名称 * perf: 修改锁名 * perf: 去掉检查节点任务 * perf: 修改一下名称 * perf: 优化一波 Co-authored-by: Jiangjie.Bai <32935519+BaiJiangJie@users.noreply.github.com> Co-authored-by: Bai <bugatti_it@163.com> Co-authored-by: xinwen <coderWen@126.com> Co-authored-by: xinwen <coderWen@126.com> Co-authored-by: 老广 <ibuler@qq.com>
96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
from random import choice
|
|
import random
|
|
import forgery_py
|
|
|
|
from .base import FakeDataGenerator
|
|
|
|
from assets.models import *
|
|
|
|
|
|
class AdminUsersGenerator(FakeDataGenerator):
|
|
resource = 'admin_user'
|
|
|
|
def do_generate(self, batch, batch_size):
|
|
admin_users = []
|
|
for i in batch:
|
|
username = forgery_py.internet.user_name(True)
|
|
password = forgery_py.basic.password()
|
|
admin_users.append(AdminUser(
|
|
name=username.title(),
|
|
username=username,
|
|
password=password,
|
|
org_id=self.org.id,
|
|
created_by='Fake',
|
|
))
|
|
AdminUser.objects.bulk_create(admin_users, ignore_conflicts=True)
|
|
|
|
|
|
class SystemUsersGenerator(FakeDataGenerator):
|
|
def do_generate(self, batch, batch_size):
|
|
system_users = []
|
|
protocols = list(dict(SystemUser.PROTOCOL_CHOICES).keys())
|
|
for i in batch:
|
|
username = forgery_py.internet.user_name(True)
|
|
protocol = random.choice(protocols)
|
|
name = username.title()
|
|
name = f'{name}-{protocol}'
|
|
system_users.append(SystemUser(
|
|
name=name,
|
|
username=username,
|
|
password=forgery_py.basic.password(),
|
|
protocol=protocol,
|
|
org_id=self.org.id,
|
|
created_by='Fake',
|
|
))
|
|
SystemUser.objects.bulk_create(system_users, ignore_conflicts=True)
|
|
|
|
|
|
class NodesGenerator(FakeDataGenerator):
|
|
resource = 'node'
|
|
|
|
def do_generate(self, batch, batch_size):
|
|
nodes_to_generate_children = list(Node.objects.all())
|
|
for i in batch:
|
|
parent = random.choice(nodes_to_generate_children)
|
|
parent.create_child()
|
|
|
|
|
|
class AssetsGenerator(FakeDataGenerator):
|
|
resource = 'asset'
|
|
admin_users_id: list
|
|
nodes_id: list
|
|
|
|
def pre_generate(self):
|
|
self.admin_users_id = list(AdminUser.objects.all().values_list('id', flat=True))
|
|
self.nodes_id = list(Node.objects.all().values_list('id', flat=True))
|
|
|
|
def set_assets_nodes(self, assets):
|
|
assets_id = [asset.id for asset in assets]
|
|
objs = []
|
|
for asset_id in assets_id:
|
|
nodes_id_add_to = random.sample(self.nodes_id, 3)
|
|
objs_add = [Asset.nodes.through(asset_id=asset_id, node_id=nid) for nid in nodes_id_add_to]
|
|
objs.extend(objs_add)
|
|
Asset.nodes.through.objects.bulk_create(objs, ignore_conflicts=True)
|
|
|
|
def do_generate(self, batch, batch_size):
|
|
assets = []
|
|
|
|
for i in batch:
|
|
ip = forgery_py.internet.ip_v4()
|
|
hostname = forgery_py.email.address().replace('@', '.')
|
|
hostname = f'{hostname}-{ip}'
|
|
data = dict(
|
|
ip=ip,
|
|
hostname=hostname,
|
|
admin_user_id=choice(self.admin_users_id),
|
|
created_by='Fake',
|
|
org_id=self.org.id
|
|
)
|
|
assets.append(Asset(**data))
|
|
creates = Asset.objects.bulk_create(assets, ignore_conflicts=True)
|
|
self.set_assets_nodes(creates)
|
|
|
|
def after_generate(self):
|
|
pass
|