MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / QuickScan

Class QuickScan

client/node/quicktask/quickscan.py:30–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class QuickScan(object):
31 @staticmethod
32 def is_quick_scan():
33 """
34 判断是否快速分析模式
35 :return:
36 """
37 if os.getenv("TCA_QUICK_SCAN") == "True":
38 return True
39 else:
40 return False
41
42 @staticmethod
43 def get_task_json_files(config_dir, languages):
44 """
45 从对应标签的配置目录中读取需要的任务参数json文件
46 目录结构:
47 |- label_name
48 |- tool_name.json 适用于所有语言的任务
49 |- language_name 语言类型名
50 |- tool_name.json 适用于指定语言的任务
51 """
52 task_json_paths = []
53 for f_name in os.listdir(config_dir):
54 f_path = os.path.join(config_dir, f_name)
55 if os.path.isdir(f_path): # 如果是个目录,则目录名为语言类型,如果在需要扫描的语言列表中,则添加到list
56 if not languages or (languages and f_name in languages):
57 for json_name in os.listdir(f_path):
58 json_path = os.path.join(f_path, json_name)
59 task_json_paths.append(json_path)
60 else: # 如果是文件,表示适用于所有语言,直接添加到list
61 task_json_paths.append(f_path)
62 # logger.info(f">> task_json_paths: {task_json_paths}")
63 return task_json_paths
64
65 @staticmethod
66 def get_scan_tasks(languages, labels, input_params):
67 """获取工具任务参数"""
68 tasks = []
69 # 使用标签指定工具规则类型(标签优先使用命令行参数,其次从 input_params 中获取)
70 if not labels:
71 labels = input_params.get("labels", [])
72 if labels:
73 for label in labels:
74 config_dir = os.path.join(settings.TOOL_BASE_DIR, f"quickscan/tasks/{label}")
75 if not os.path.exists(config_dir):
76 raise NodeError(code=E_NODE_TASK_CONFIG,
77 msg=f"config dir({config_dir}) not exist, please init tca.")
78 new_task_json_files = QuickScan.get_task_json_files(config_dir, languages)
79
80 new_tasks = []
81 for file_path in new_task_json_files:
82 if not file_path.endswith(".json"):
83 continue
84 with open(file_path, "r") as rf:
85 task_config = json.load(rf)
86 new_tasks.append(task_config)
87 # 不同的标签可能会包含同样的工具,这里通过merge合并相同工具

Callers 1

_output_resultMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected