Skip to content

Commit bac28a4

Browse files
authored
Merge pull request #604 from yalechen-cyw/main
🎨 Add enhanced_safety_java
2 parents 688b9cc + 686adda commit bac28a4

7 files changed

Lines changed: 399 additions & 11 deletions

File tree

client/tool/collie.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ def __init__(self, params):
2222
self.sensitive_word_maps = {"Collie": "Tool", "collie": "Tool"}
2323

2424
def analyze(self, params):
25-
relpos = len(params.source_dir) + 1
2625
issues = list()
2726
collie = Tool(params=params)
2827
func_output = collie.check()
2928
if func_output and os.path.exists(os.path.join(func_output, "check.csv")):
3029
for issue in collie.get_issue(os.path.join(func_output, "check.csv")):
31-
issue["path"] = issue["path"][relpos:]
3230
issues.append(issue)
3331

3432
return issues

client/tool/util/collie.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import csv
11+
import json
1112
import sys
1213
import psutil
1314

@@ -19,6 +20,7 @@
1920
from util.pathfilter import PathMgr, FilterPathUtil
2021
from util.textutil import CommentsManager
2122
from util.logutil import LogPrinter
23+
from util.configlib import ConfigReader
2224
from node.app import settings
2325
from task.authcheck.check_license import __lu__
2426

@@ -125,10 +127,40 @@ def check(self, files=None, want_suffix=None, force_all=False, method_mode=False
125127
]
126128
if method_mode:
127129
options.append("-m")
130+
131+
# 默认开启所有规则
132+
# 支持指定规则,使用配置文件的方式,以下是demo
133+
# {
134+
# "enableCheckers": {
135+
# "GoFuncVisitor": {},
136+
# "JavaScriptFuncVisitor": {
137+
# "ignoreNestingMethods": true
138+
# }
139+
# }
140+
# }
141+
config = dict()
142+
enable_rules = dict()
143+
rule_list = self.params.get("rule_list", list())
144+
for rule in rule_list:
145+
# 因为有这个字段但本身就是None,所以返回None
146+
rule_params = rule.get("params")
147+
if rule_params is None:
148+
rule_params = ""
149+
if f"[{self.tool_name.lower()}]" not in rule_params:
150+
rule_params = f"[{self.tool_name.lower()}]\r\n" + rule_params
151+
rule_params_dict = ConfigReader(cfg_string=rule_params).read(self.tool_name.lower())
152+
enable_rules[rule["name"]] = rule_params_dict
153+
config["enableCheckers"] = enable_rules
154+
config_path = os.path.join(self.work_dir, f"{self.tool_name}_config.json")
155+
with open(config_path, "w") as f:
156+
json.dump(config, f, indent=2)
157+
options.extend(["-c", config_path])
158+
128159
scan_cmd = self.get_cmd(options)
129160

130161
spc = SubProcController(
131162
scan_cmd,
163+
cwd=self.tool_home,
132164
stdout_line_callback=subprocc_log,
133165
stderr_line_callback=subprocc_log,
134166
)
@@ -171,8 +203,9 @@ def get_issue(self, output):
171203
if not output or not os.path.exists(output):
172204
return
173205

206+
relpos = len(self.params.source_dir) + 1
174207
rules = self.params.get("rules", list())
175-
208+
176209
f = open(output, "r", encoding="utf-8")
177210
fieldnames = (
178211
"checker",
@@ -185,19 +218,33 @@ def get_issue(self, output):
185218
reader = csv.DictReader(csv_f, fieldnames)
186219
next(reader)
187220
for row in reader:
188-
path = row["path"]
221+
path = row["path"][relpos:]
189222
line = int(row["line"])
190223
column = int(row["column"])
191224
rule = row["checker"]
192225
if rule not in rules:
193226
continue
194227
msg = row["description"]
228+
229+
row_refs = row[None]
230+
refs = list()
231+
for ref in row_refs:
232+
parts = ref.split(":")
233+
refs.append(
234+
{
235+
"line": parts[2],
236+
"column": parts[3],
237+
"msg": parts[0],
238+
"path": parts[1][relpos:],
239+
}
240+
)
195241
yield {
196242
"rule": rule,
197243
"msg": msg,
198244
"path": path,
199245
"line": line,
200246
"column": column,
247+
"refs": refs,
201248
}
202249

203250
f.close()

doc/en/quickStarted/enhanceDeploy.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ TCA 增强分析模块,需要用户额外部署 License 鉴权微服务,并
2424
### 准备
2525
- 一台 CLS 微服务专属机器,CLS 微服务需要跟该机器绑定
2626

27+
**注意:不能随意删除CLS目录**
28+
2729
### 步骤
2830
1. 在 TCA 源码中[`server/cls`](https://github.com/Tencent/CodeAnalysis/tree/main/server/cls) 目录下执行以下命令,获取 `Server ID``Client License`
2931

32+
**注意:需要在 CLS 目录下执行命令**
33+
3034
```shell
3135
$ ./cls server
3236
2022-04-13 18:35:29.356510559 +0800 CST [INFO] Version: 20220328.1
@@ -42,8 +46,8 @@ xxx
4246
```ini
4347
[LICENSE_CONFIG]
4448
; [可选]使用独立工具时,需要填写,默认不需要
49+
; License服务的域名和端口
4550
URL=http://<IP或者域名>:<port>
46-
;License服务的域名和端口
4751
BASE_PATH=
4852
LICENSE=<Client License>
4953
```
@@ -88,7 +92,7 @@ tommyzhang@tencent.com
8892
```
8993

9094
6. 启动 TCA 分析任务
91-
在 TCA 平台的分析方案里面勾选独立工具相关的规则包。
95+
在 TCA 平台的分析方案里面勾选独立工具相关的规则包,比如依赖组件分析规则包,然后启动一次分析任务,执行正常则表明设置生效
9296

9397
### CLS 运维
9498
#### 自动重启

doc/zh/quickStarted/enhanceDeploy.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ TCA 增强分析模块,需要用户额外部署 License 鉴权微服务,并
2424
### 准备
2525
- 一台 CLS 微服务专属机器,CLS 微服务需要跟该机器绑定
2626

27+
**注意:不能随意删除CLS目录**
28+
2729
### 步骤
2830
1. 在 TCA 源码中[`server/cls`](https://github.com/Tencent/CodeAnalysis/tree/main/server/cls) 目录下执行以下命令,获取 `Server ID``Client License`
2931

32+
**注意:需要在 CLS 目录下执行命令**
33+
3034
```shell
3135
$ ./cls server
3236
2022-04-13 18:35:29.356510559 +0800 CST [INFO] Version: 20220328.1
@@ -42,8 +46,8 @@ xxx
4246
```ini
4347
[LICENSE_CONFIG]
4448
; [可选]使用独立工具时,需要填写,默认不需要
49+
; License服务的域名和端口
4550
URL=http://<IP或者域名>:<port>
46-
;License服务的域名和端口
4751
BASE_PATH=
4852
LICENSE=<Client License>
4953
```
@@ -88,7 +92,7 @@ tommyzhang@tencent.com
8892
```
8993

9094
6. 启动 TCA 分析任务
91-
在 TCA 平台的分析方案里面勾选独立工具相关的规则包。
95+
在 TCA 平台的分析方案里面勾选独立工具相关的规则包,比如依赖组件分析规则包,然后启动一次分析任务,执行正常则表明设置生效
9296

9397
### CLS 运维
9498
#### 自动重启

0 commit comments

Comments
 (0)