Skip to content

Commit

Permalink
formats: Modify layer title based on manifest
Browse files Browse the repository at this point in the history
This is work towards tern-tools#948

The html formatting of lists allows for an expansion UI under
the title of the layer object. The title is the layer tarball's
digest. In the Docker image layout, this can be directly taken
from the "tar_file" key. But in the OCI layout, this value is taken
from the "digest" key. This commit allows for that difference and
defaults to the layer's index if neither one of those keys exist.

Signed-off-by: Nisha K <[email protected]>
  • Loading branch information
Nisha K committed Dec 15, 2021
1 parent 4df0850 commit 7f2fdab
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tern/formats/html/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,20 @@ def manifest_handler(list_obj, indent):


def layers_handler(list_obj, indent):
'''Write html code for the origins list in the report
'''Write html code for the layers list in the report
with tar_file hash as title'''
html_string = ' '*indent + '<ul class ="nested"> \n'
for lo in list_obj:
# check whether the item is a dictionary that contains the "tar_file"
# property or not
if "tar_file" in lo:
title = str(lo["tar_file"][:10])
elif "digest" in lo:
title = str(lo["digest"][:10])
else:
title = list_obj.index(lo)
html_string = html_string + ' '*indent + '<li><span class="caret">' \
+ str(lo["tar_file"][:10]) + ' : ' + '</span> \n '
+ title + ' : ' + '</span> \n '
html_string = html_string + dict_handler(lo, indent+1)
html_string = html_string + ' '*indent + '</li> \n'
html_string = html_string + ' '*indent + '</ul> \n'
Expand Down

0 comments on commit 7f2fdab

Please sign in to comment.