From 6bc72c519dd37e79b0d7b373f25f1cf15ad3a13f Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Thu, 16 Feb 2023 16:53:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20sqlserver=E6=97=A0=E6=B3=95=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E7=94=A8=E6=88=B7=E9=97=AE=E9=A2=98=20(#9588)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../change_secret/database/sqlserver/main.yml | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/accounts/automations/change_secret/database/sqlserver/main.yml b/apps/accounts/automations/change_secret/database/sqlserver/main.yml index 75662ec44..da0427f5c 100644 --- a/apps/accounts/automations/change_secret/database/sqlserver/main.yml +++ b/apps/accounts/automations/change_secret/database/sqlserver/main.yml @@ -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 From 22dd81de43b8a587cbe6db64065946c56c0e1d65 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 16 Feb 2023 16:51:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=88=9B=E5=BB=BA=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E3=80=81=E8=B5=84=E4=BA=A7=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E8=B5=84=E4=BA=A7=E6=95=B0=E9=87=8F=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E7=9A=84=E4=BF=A1=E5=8F=B7=E4=B8=8D=E5=A4=AA?= =?UTF-8?q?=E5=AF=B9=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=98=AF=20post=5Fremove?= =?UTF-8?q?=20=E9=82=A3=E4=B9=88=E8=8E=B7=E5=8F=96=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E8=81=94=E8=8A=82=E7=82=B9=E6=98=AF=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=88=B0=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/signal_handlers/asset.py | 2 +- apps/assets/signal_handlers/node_assets_amount.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/assets/signal_handlers/asset.py b/apps/assets/signal_handlers/asset.py index 88ebab11e..be25988f6 100644 --- a/apps/assets/signal_handlers/asset.py +++ b/apps/assets/signal_handlers/asset.py @@ -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, diff --git a/apps/assets/signal_handlers/node_assets_amount.py b/apps/assets/signal_handlers/node_assets_amount.py index 361f3a176..79e2ed568 100644 --- a/apps/assets/signal_handlers/node_assets_amount.py +++ b/apps/assets/signal_handlers/node_assets_amount.py @@ -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)))