fix: 修复playbook部分不可执行问题

pull/12138/head
Aaron3S 1 year ago committed by Bryan
parent 23fce9e426
commit 44f029774d

@ -40,11 +40,16 @@ class Playbook(JMSOrgBaseModel):
result = [] result = []
for root, dirs, files in os.walk(self.work_dir): for root, dirs, files in os.walk(self.work_dir):
for f in files: for f in files:
if str(f).endswith('.yml') or str(f).endswith('.yaml'): try:
lines = self.search_keywords(os.path.join(root, f)) if str(f).endswith('.yml') or str(f).endswith('.yaml'):
if len(lines) > 0: lines = self.search_keywords(os.path.join(root, f))
for line in lines: if len(lines) > 0:
result.append({'file': f, 'line': line[0], 'keyword': line[1]}) for line in lines:
result.append({'file': f, 'line': line[0], 'keyword': line[1]})
# 遇到无法读取的文件,跳过
except UnicodeEncodeError:
continue
return result return result
@staticmethod @staticmethod
@ -53,12 +58,12 @@ class Playbook(JMSOrgBaseModel):
with open(file, 'r') as f: with open(file, 'r') as f:
for line_num, line in enumerate(f): for line_num, line in enumerate(f):
for keyword in dangerous_keywords: for keyword in dangerous_keywords:
clear_line = line.replace(' ', '')\ clear_line = line.replace(' ', '') \
.replace('\n', '')\ .replace('\n', '') \
.replace('\r', '')\ .replace('\r', '') \
.replace('\t', '') \ .replace('\t', '') \
.replace('\'', '') \ .replace('\'', '') \
.replace('\"', '')\ .replace('\"', '') \
.replace('\v', '') .replace('\v', '')
if keyword in clear_line: if keyword in clear_line:
result.append((line_num, keyword)) result.append((line_num, keyword))

Loading…
Cancel
Save