mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-10-22 08:19:04 +00:00
* feat: 账号密钥用vault储存 * perf: 优化 Vault * perf: 重构 Vault Backend 设计架构 (未完成) * perf: 重构 Vault Backend 设计架构 (未完成2) * perf: 重构 Vault Backend 设计架构 (未完成3) * perf: 重构 Vault Backend 设计架构 (未完成4) * perf: 重构 Vault Backend 设计架构 (未完成5) * perf: 重构 Vault Backend 设计架构 (已完成) * perf: 重构 Vault Backend 设计架构 (已完成) * perf: 重构 Vault Backend 设计架构 (已完成) * perf: 小优化 * perf: 优化 --------- Co-authored-by: feng <1304903146@qq.com> Co-authored-by: Bai <baijiangjie@gmail.com> Co-authored-by: feng626 <57284900+feng626@users.noreply.github.com>
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from django.db.models.signals import pre_save, post_save, post_delete
|
|
from django.dispatch import receiver
|
|
|
|
from accounts.backends import vault_client
|
|
from common.utils import get_logger
|
|
from .models import Account, AccountTemplate
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
@receiver(pre_save, sender=Account)
|
|
def on_account_pre_save(sender, instance, **kwargs):
|
|
if instance.version == 0:
|
|
instance.version = 1
|
|
else:
|
|
instance.version = instance.history.count()
|
|
|
|
|
|
class VaultSignalHandler(object):
|
|
""" 处理 Vault 相关的信号 """
|
|
|
|
@staticmethod
|
|
def save_to_vault(sender, instance, created, **kwargs):
|
|
if created:
|
|
vault_client.create(instance)
|
|
else:
|
|
vault_client.update(instance)
|
|
|
|
@staticmethod
|
|
def delete_to_vault(sender, instance, **kwargs):
|
|
vault_client.delete(instance)
|
|
|
|
|
|
for model in (Account, AccountTemplate, Account.history.model):
|
|
post_save.connect(VaultSignalHandler.save_to_vault, sender=model)
|
|
post_delete.connect(VaultSignalHandler.delete_to_vault, sender=model)
|