summaryrefslogtreecommitdiff
path: root/analyze.py
diff options
context:
space:
mode:
authorYang Qian <yang.qian@citrix.com>2019-05-30 20:43:03 +0800
committerYang Qian <yang.qian@citrix.com>2019-05-30 22:48:27 +0800
commit4a3ba58260e7c5e6045c4060708dcb40ba7577f5 (patch)
tree8992bef2c8faee15482685316759d2733c4b8efc /analyze.py
parent218d1c376840efc4c2567f1c5a573c9d439217b1 (diff)
downloadvyos-xe-guest-utilities-4a3ba58260e7c5e6045c4060708dcb40ba7577f5.tar.gz
vyos-xe-guest-utilities-4a3ba58260e7c5e6045c4060708dcb40ba7577f5.zip
output formatted issues
Output the formatted issues to a file Signed-off-by: Yang Qian <yang.qian@citrix.com>
Diffstat (limited to 'analyze.py')
-rw-r--r--analyze.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/analyze.py b/analyze.py
index 51a7269..abea29f 100644
--- a/analyze.py
+++ b/analyze.py
@@ -6,7 +6,14 @@ import json
def cnt_on_rule_id(issues, rule_id):
return len([issue for issue in issues if issue['rule_id'] == rule_id])
-def analyze(js):
+
+def write_issue(f, issue, idx):
+ f.write('Issue %d\\n' % idx)
+ for k, v in issue.iteritems():
+ f.write('|%s|%s|\\n' % (k, v))
+
+
+def analyze(js, formatted_issues_f):
issues = js['Issues']
if not issues:
print "Security check: no security issue detected"
@@ -26,13 +33,21 @@ def analyze(js):
better_fix.append(issue)
- print '======== Must fix the potential security issues ========'
- for issue in must_fix:
- print json.dumps(issue, indent=4)
+ with open(formatted_issues_f, 'w') as f:
+ idx = 1
+ f.write('\\n*Must fix issues*\\n')
+ print '======== Must fix the potential security issues ========'
+ for issue in must_fix:
+ print json.dumps(issue, indent=4)
+ write_issue(f, issue, idx)
+ idx += 1
- print '======== Optional to fix the potential security issues ========'
- for issue in better_fix:
- print json.dumps(issue, indent=4)
+ f.write('\\n----\\n*Optinal fix issues*\\n')
+ print '======== Optional to fix the potential security issues ========'
+ for issue in better_fix:
+ print json.dumps(issue, indent=4)
+ write_issue(f, issue, idx)
+ idx += 1
if must_fix:
return 1
@@ -45,8 +60,10 @@ def parse_args_or_exit(argv=None):
Parse command line options
"""
parser = argparse.ArgumentParser(description="Analyze security check result")
- parser.add_argument("check_result", metavar="check_result",
- help="json file of check result")
+ parser.add_argument("-i", metavar="check_result",
+ dest="check_result", help="json file of check result")
+ parser.add_argument("issues", metavar="issues",
+ help="formatted issues")
args = parser.parse_args(argv)
@@ -57,7 +74,7 @@ def main(argv):
check_result = args.check_result
with open(args.check_result) as f:
js = json.load(f)
- sys.exit(analyze(js))
+ sys.exit(analyze(js, args.issues))
if __name__ == '__main__':
main(sys.argv[1:])