From 92316dc3e26312ad14482e6587b6cf666dc12cac Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 13 Sep 2023 16:59:03 +0800 Subject: [PATCH 1/2] feat/api route is cover. --- .../handler/saas_method_pool_handler.py | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/dongtai_protocol/report/handler/saas_method_pool_handler.py b/dongtai_protocol/report/handler/saas_method_pool_handler.py index fdb5047cf..d0203b9e2 100644 --- a/dongtai_protocol/report/handler/saas_method_pool_handler.py +++ b/dongtai_protocol/report/handler/saas_method_pool_handler.py @@ -17,13 +17,11 @@ from dongtai_common.models.agent import IastAgent from dongtai_common.models.agent_method_pool import MethodPool from dongtai_common.models.api_route import ( - FromWhereChoices, - HttpMethod, IastApiMethod, - IastApiMethodHttpMethodRelation, IastApiParameter, IastApiRoute, ) +from dongtai_common.models.api_route_v2 import IastApiRouteV2 from dongtai_common.models.replay_method_pool import IastAgentMethodPoolReplay from dongtai_common.models.replay_queue import IastReplayQueue from dongtai_common.models.res_header import ( @@ -111,6 +109,7 @@ def save(self): ) # update_api_route_deatil(self.agent_id, self.http_uri, self.http_method, # params_dict) + add_new_api_route(self.agent, self.http_uri, self.http_method) if self.http_replay: # 保存数据至重放请求池 replay_id = headers.get("dongtai-replay-id") @@ -412,27 +411,9 @@ def add_new_api_route(agent: IastAgent, path, method): logger.info(f"found cache api_route-{agent.id}-{path}-{method} ,skip its insert") return try: - api_method, is_create = IastApiMethod.objects.get_or_create(method=method.upper()) - http_method, _ = HttpMethod.objects.get_or_create(method=method.upper()) - IastApiMethodHttpMethodRelation.objects.get_or_create( - api_method_id=api_method.id, http_method_id=http_method.id - ) - api_route, is_create = IastApiRoute.objects.get_or_create( - from_where=FromWhereChoices.FROM_METHOD_POOL, - method_id=api_method.id, - path=path, - agent_id=agent.id, - project_id=agent.bind_project_id, - project_version_id=agent.project_version_id, - ) - except (IntegrityError, MultipleObjectsReturned) as e: - logger.info(e) - logger.debug(e, exc_info=e) - try: - api_method, is_create = IastApiMethod.objects.get_or_create(method=method.upper()) - IastApiRoute.objects.filter( + IastApiRouteV2.objects.filter( path=path, - method_id=api_method.id, + method=method.lower(), project_id=agent.bind_project_id, project_version_id=agent.project_version_id, ).update(is_cover=1) From ccc8baa27521862ce7730f53c29710491197393e Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Wed, 13 Sep 2023 17:01:53 +0800 Subject: [PATCH 2/2] feat/api route is cover. --- dongtai_conf/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dongtai_conf/settings.py b/dongtai_conf/settings.py index 08994e0d9..dfaf4d211 100644 --- a/dongtai_conf/settings.py +++ b/dongtai_conf/settings.py @@ -119,8 +119,8 @@ def get_installed_apps(): "PAGE_SIZE": 20, "DEFAULT_PAGINATION_CLASS": ["django.core.paginator"], "DEFAULT_AUTHENTICATION_CLASSES": [ - "dongtai_common.common.utils.ProjectTokenAuthentication", "rest_framework.authentication.SessionAuthentication", + "dongtai_common.common.utils.ProjectTokenAuthentication", "dongtai_common.common.utils.DepartmentTokenAuthentication", "rest_framework.authentication.TokenAuthentication", ],