Skip to content

Commit

Permalink
Merge pull request #1 from hmsrc/report_flag
Browse files Browse the repository at this point in the history
adding --report function, report folder
  • Loading branch information
vladdoster committed Apr 16, 2020
2 parents 5d26ac2 + c2130e4 commit 052dc9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions stools/clair/__init__.py
Expand Up @@ -52,8 +52,12 @@ def get_parser():
help='port to serve application (default 8080)',
type=int)

parser.add_argument("--host", default="127.0.0.1",
help='host to serve application (default 127.0.0.1)',
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)

parser.add_argument("--clair-port", default=6060,
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions stools/clair/reports/hello_world.txt
@@ -0,0 +1 @@
.replace with Json report

0 comments on commit 052dc9b

Please sign in to comment.