diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0851268fca..5c277c67cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,3 +24,14 @@ repos: - id: commitlint stages: [commit-msg] additional_dependencies: ['@commitlint/config-conventional'] + - repo: local + hooks: + - id: check-migrate + name: check migrate + entry: python scripts/check_migrate/check_migrate.py + language: system + types: [python] + - id: check-sensitive-info + name: Check Sensitive Info + entry: sh scripts/check_sensitive_info.sh + language: system \ No newline at end of file diff --git a/gcloud/tests/utils/cmdb/test_business_host_topo.py b/gcloud/tests/utils/cmdb/test_business_host_topo.py index 2b81ed35d5..e99e702cd8 100644 --- a/gcloud/tests/utils/cmdb/test_business_host_topo.py +++ b/gcloud/tests/utils/cmdb/test_business_host_topo.py @@ -30,6 +30,7 @@ def setUp(self): self.bk_biz_id = "biz_id_token" self.supplier_account = "supplier_account_token" self.host_fields = ["host_fields_token"] + self.operator = "in" self.ip_list = "ip_list_token" self.list_biz_hosts_topo_return = [ { @@ -113,7 +114,12 @@ def test__get_with_ip_list(self): mock_batch_request = MagicMock(return_value=self.list_biz_hosts_topo_return) with patch("gcloud.utils.cmdb.batch_request", mock_batch_request): hosts_topo = get_business_host_topo( - self.username, self.bk_biz_id, self.supplier_account, self.host_fields, self.ip_list + self.username, + self.bk_biz_id, + self.supplier_account, + self.host_fields, + self.ip_list, + operator=self.operator, ) self.assertEqual(hosts_topo, self.get_business_host_topo_expect_return) diff --git a/gcloud/utils/cmdb.py b/gcloud/utils/cmdb.py index 4a7dd58e07..82310db9ac 100644 --- a/gcloud/utils/cmdb.py +++ b/gcloud/utils/cmdb.py @@ -26,7 +26,7 @@ def get_business_host_topo( - username, bk_biz_id, supplier_account, host_fields, ip_list=None, property_filters=None, page=None + username, bk_biz_id, supplier_account, host_fields, ip_list=None, property_filters=None, page=None, operator=None ): """获取业务下所有主机信息 :param username: 请求用户名 @@ -41,6 +41,10 @@ def get_business_host_topo( :type ip_list: list :param property_filters: 查询主机时的相关属性过滤条件, 当传递该参数时,ip_list参数生成的过滤条件失效 :type property_filters: dict + :param page: 分页参数,例如:{"start":0,"limit":2} + :type page: dict + :param operator: 查询方法,"in"代表精准匹配,"contains"代表模糊查询 + :type operator: str :return: [ { "host": { @@ -75,7 +79,7 @@ def get_business_host_topo( elif ip_list: kwargs["host_property_filter"] = { "condition": "AND", - "rules": [{"field": "bk_host_innerip", "operator": "in", "value": ip_list}], + "rules": [{"field": "bk_host_innerip", "operator": operator, "value": ip_list}], } if page: diff --git a/pipeline_plugins/cmdb_ip_picker/query.py b/pipeline_plugins/cmdb_ip_picker/query.py index bf9d444995..fa6cfe0bf1 100644 --- a/pipeline_plugins/cmdb_ip_picker/query.py +++ b/pipeline_plugins/cmdb_ip_picker/query.py @@ -84,11 +84,20 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id= client = get_client_by_user(request.user.username) topo_modules_id = set() - page = { - "start": int(request.GET.get("start", 0)), - "limit": int(request.GET.get("limit", 10)), - } - ip_list = json.loads(request.GET.get("ip_list", "[]")) + + operator = request.GET.get("operator", None) + if operator == "in": + ip_list = json.loads(request.GET.get("ip_list", "[]")) + elif operator == "contains": + ip_list = json.loads(request.GET.get("ip_list", "")) + else: + ip_list = None + + start = request.GET.get("start", None) + if start: + page = {"start": int(start), "limit": int(request.GET.get("limit", 10))} + else: + page = None # get filter module id if request.GET.get("topo", None): @@ -115,7 +124,7 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id= return JsonResponse(result) raw_host_info_list = cmdb.get_business_host_topo( - request.user.username, bk_biz_id, bk_supplier_account, fields, ip_list=ip_list, page=page + request.user.username, bk_biz_id, bk_supplier_account, fields, ip_list=ip_list, page=page, operator=operator ) # map cloud_area_id to cloud_area