From f592f19b087d99ce9729e220e99ec23ad096f71e Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Mon, 19 Feb 2024 17:32:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=87=AA=E5=8A=A8=E5=8C=96=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8C=89=E4=BC=98=E5=85=88=E7=BA=A7=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automations/change_secret/custom/ssh/manifest.yml | 1 + .../change_secret/host/windows_rdp_verify/manifest.yml | 1 + .../push_account/host/windows_rdp_verify/manifest.yml | 1 + .../automations/verify_account/custom/rdp/manifest.yml | 1 + .../automations/verify_account/custom/ssh/manifest.yml | 1 + apps/assets/automations/__init__.py | 2 +- apps/assets/automations/methods.py | 4 ++++ apps/assets/automations/ping/custom/rdp/manifest.yml | 1 + apps/assets/automations/ping/custom/ssh/manifest.yml | 1 + apps/assets/const/types.py | 3 ++- 10 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/accounts/automations/change_secret/custom/ssh/manifest.yml b/apps/accounts/automations/change_secret/custom/ssh/manifest.yml index 7d3d0edde..1b0a38a00 100644 --- a/apps/accounts/automations/change_secret/custom/ssh/manifest.yml +++ b/apps/accounts/automations/change_secret/custom/ssh/manifest.yml @@ -7,6 +7,7 @@ type: - all method: change_secret protocol: ssh +priority: 50 params: - name: commands type: list diff --git a/apps/accounts/automations/change_secret/host/windows_rdp_verify/manifest.yml b/apps/accounts/automations/change_secret/host/windows_rdp_verify/manifest.yml index 52f0e02df..242261d59 100644 --- a/apps/accounts/automations/change_secret/host/windows_rdp_verify/manifest.yml +++ b/apps/accounts/automations/change_secret/host/windows_rdp_verify/manifest.yml @@ -5,6 +5,7 @@ method: change_secret category: host type: - windows +priority: 49 params: - name: groups type: str diff --git a/apps/accounts/automations/push_account/host/windows_rdp_verify/manifest.yml b/apps/accounts/automations/push_account/host/windows_rdp_verify/manifest.yml index d08a29ebc..63b4a0f9c 100644 --- a/apps/accounts/automations/push_account/host/windows_rdp_verify/manifest.yml +++ b/apps/accounts/automations/push_account/host/windows_rdp_verify/manifest.yml @@ -5,6 +5,7 @@ method: push_account category: host type: - windows +priority: 49 params: - name: groups type: str diff --git a/apps/accounts/automations/verify_account/custom/rdp/manifest.yml b/apps/accounts/automations/verify_account/custom/rdp/manifest.yml index e4b034366..3cfaf1880 100644 --- a/apps/accounts/automations/verify_account/custom/rdp/manifest.yml +++ b/apps/accounts/automations/verify_account/custom/rdp/manifest.yml @@ -6,6 +6,7 @@ type: - windows method: verify_account protocol: rdp +priority: 1 i18n: Windows rdp account verify: diff --git a/apps/accounts/automations/verify_account/custom/ssh/manifest.yml b/apps/accounts/automations/verify_account/custom/ssh/manifest.yml index bebc02c7f..3edddc531 100644 --- a/apps/accounts/automations/verify_account/custom/ssh/manifest.yml +++ b/apps/accounts/automations/verify_account/custom/ssh/manifest.yml @@ -7,6 +7,7 @@ type: - all method: verify_account protocol: ssh +priority: 50 i18n: SSH account verify: diff --git a/apps/assets/automations/__init__.py b/apps/assets/automations/__init__.py index 30fb03cda..f508f7ba2 100644 --- a/apps/assets/automations/__init__.py +++ b/apps/assets/automations/__init__.py @@ -1,2 +1,2 @@ from .endpoint import ExecutionManager -from .methods import platform_automation_methods, filter_platform_methods +from .methods import platform_automation_methods, filter_platform_methods, sorted_methods diff --git a/apps/assets/automations/methods.py b/apps/assets/automations/methods.py index 1453cc7a1..c922a6d62 100644 --- a/apps/assets/automations/methods.py +++ b/apps/assets/automations/methods.py @@ -68,6 +68,10 @@ def filter_platform_methods(category, tp_name, method=None, methods=None): return methods +def sorted_methods(methods): + return sorted(methods, key=lambda x: x.get('priority', 10)) + + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) platform_automation_methods = get_platform_automation_methods(BASE_DIR) diff --git a/apps/assets/automations/ping/custom/rdp/manifest.yml b/apps/assets/automations/ping/custom/rdp/manifest.yml index b8346c3f2..ad499b90e 100644 --- a/apps/assets/automations/ping/custom/rdp/manifest.yml +++ b/apps/assets/automations/ping/custom/rdp/manifest.yml @@ -7,6 +7,7 @@ type: - windows method: ping protocol: rdp +priority: 1 i18n: Ping by pyfreerdp: diff --git a/apps/assets/automations/ping/custom/ssh/manifest.yml b/apps/assets/automations/ping/custom/ssh/manifest.yml index 7a7068108..c6d08ca12 100644 --- a/apps/assets/automations/ping/custom/ssh/manifest.yml +++ b/apps/assets/automations/ping/custom/ssh/manifest.yml @@ -7,6 +7,7 @@ type: - all method: ping protocol: ssh +priority: 50 i18n: Ping by paramiko: diff --git a/apps/assets/const/types.py b/apps/assets/const/types.py index 220d10731..53f41c218 100644 --- a/apps/assets/const/types.py +++ b/apps/assets/const/types.py @@ -90,7 +90,7 @@ class AllTypes(ChoicesMixin): @classmethod def set_automation_methods(cls, category, tp_name, constraints): - from assets.automations import filter_platform_methods + from assets.automations import filter_platform_methods, sorted_methods automation = constraints.get('automation', {}) automation_methods = {} platform_automation_methods = cls.get_automation_methods() @@ -101,6 +101,7 @@ class AllTypes(ChoicesMixin): methods = filter_platform_methods( category, tp_name, item_name, methods=platform_automation_methods ) + methods = sorted_methods(methods) methods = [{'name': m['name'], 'id': m['id']} for m in methods] automation_methods[item_name + '_methods'] = methods automation.update(automation_methods)