From f296e0e9a67706d8d43c9dd85fde05a195f158af Mon Sep 17 00:00:00 2001 From: Alex Cullen Date: Thu, 16 Apr 2020 17:30:52 -0400 Subject: [PATCH] adding --report function, report folder --- stools/clair/__init__.py | 21 ++++++++++++++++++++- stools/clair/reports/hello_world.txt | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 stools/clair/reports/hello_world.txt diff --git a/stools/clair/__init__.py b/stools/clair/__init__.py index 3417457..8f7d184 100644 --- a/stools/clair/__init__.py +++ b/stools/clair/__init__.py @@ -52,6 +52,10 @@ def get_parser(): help='port to serve application (default 8080)', type=int) + parser.add_argument("--report", dest="report", + help='if set, output Clair reports to chosen directory (default: /code/reports)', + default=None, type=str) + parser.add_argument("--host", default="0.0.0.0", help='host to serve application (default 0.0.0.0)', type=str) @@ -142,7 +146,22 @@ def help(retval=0): # 4. Generate report print('3. Generating report!') report = clair.report(os.path.basename(image)) - clair.print(report) + if args.report: + if args.report == None: + with open("/code/reports/%s.log" %(args.images)) as f: + f.write(report) + f.close() + else: + try: + filename="%s-%s.json" %(args.report, args.images) + with open(filename, "w+") as f: + f.write(report) + f.close() + print("Wrote report to %s" %(filename)) + except FileNotFoundError as Error: + sys.exit(status="Issue with report path specified: %s" %(Error)) + else: + clair.print(report) # Shut down temporary server process.terminate() diff --git a/stools/clair/reports/hello_world.txt b/stools/clair/reports/hello_world.txt new file mode 100644 index 0000000..3e42520 --- /dev/null +++ b/stools/clair/reports/hello_world.txt @@ -0,0 +1 @@ +.replace with Json report \ No newline at end of file