Merge branch 'dev' of github.com:jumpserver/jumpserver into dev

pull/9593/head
ibuler 2 years ago
commit 7d813de71d

@ -22,6 +22,17 @@
- debug:
var: info
- name: Check whether SQLServer User exist
community.general.mssql_script:
login_user: "{{ jms_account.username }}"
login_password: "{{ jms_account.secret }}"
login_host: "{{ jms_asset.address }}"
login_port: "{{ jms_asset.port }}"
name: '{{ jms_asset.spec_info.db_name }}'
script: "SELECT 1 from sys.sql_logins WHERE name='{{ account.username }}';"
when: db_info is succeeded
register: user_exist
- name: Change SQLServer password
community.general.mssql_script:
login_user: "{{ jms_account.username }}"
@ -30,7 +41,18 @@
login_port: "{{ jms_asset.port }}"
name: '{{ jms_asset.spec_info.db_name }}'
script: "ALTER LOGIN {{ account.username }} WITH PASSWORD = '{{ account.secret }}'; select @@version"
when: db_info is succeeded
when: user_exist.query_results[0] | length != 0
register: change_info
- name: Add SQLServer user
community.general.mssql_script:
login_user: "{{ jms_account.username }}"
login_password: "{{ jms_account.secret }}"
login_host: "{{ jms_asset.address }}"
login_port: "{{ jms_asset.port }}"
name: '{{ jms_asset.spec_info.db_name }}'
script: "CREATE LOGIN {{ account.username }} WITH PASSWORD = '{{ account.secret }}'; select @@version"
when: user_exist.query_results[0] | length == 0
register: change_info
- name: Verify password

@ -91,7 +91,7 @@ def on_asset_delete(instance: Asset, using, **kwargs):
@receiver(post_delete, sender=Asset)
def on_asset_post_delete(instance: Asset, using, **kwargs):
logger.debug("Asset post delete signal recv: {}".format(instance))
node_ids = getattr(instance, RELATED_NODE_IDS, None)
node_ids = getattr(instance, RELATED_NODE_IDS, [])
if node_ids:
m2m_changed.send(
sender=Asset.nodes.through, instance=instance, reverse=False,

@ -6,7 +6,7 @@ from django.db.models.signals import m2m_changed
from django.dispatch import receiver
from assets.models import Asset, Node
from common.const.signals import PRE_ADD, POST_REMOVE, PRE_CLEAR
from common.const.signals import PRE_CLEAR, POST_ADD, PRE_REMOVE
from common.decorators import on_transaction_commit, merge_delay_run
from common.utils import get_logger
from orgs.utils import tmp_to_org
@ -24,7 +24,8 @@ def on_node_asset_change(sender, action, instance, reverse, pk_set, **kwargs):
if action in refused:
raise ValueError
mapper = {PRE_ADD: add, POST_REMOVE: sub}
# 这里监听 post_add, pre_remove, 如果pre_add 和 post_remove, 那么 node_ids 就已经获取不到了
mapper = {POST_ADD: add, PRE_REMOVE: sub}
if action not in mapper:
return
@ -32,13 +33,14 @@ def on_node_asset_change(sender, action, instance, reverse, pk_set, **kwargs):
if reverse:
node_ids = [instance.id]
else:
node_ids = pk_set
node_ids = list(pk_set)
update_nodes_assets_amount(node_ids=node_ids)
@merge_delay_run(ttl=5)
def update_nodes_assets_amount(node_ids=()):
nodes = list(Node.objects.filter(id__in=node_ids))
nodes = Node.objects.filter(id__in=node_ids)
nodes = Node.get_ancestor_queryset(nodes)
logger.debug('Recv asset nodes change signal, recompute node assets amount')
logger.info('Update nodes assets amount: {} nodes'.format(len(node_ids)))

Loading…
Cancel
Save