Skip to content

Commit

Permalink
Merge pull request #102 from jspeed-meyers/add-html-output
Browse files Browse the repository at this point in the history
Add html output
  • Loading branch information
jspeed-meyers committed Mar 23, 2023
2 parents b088406 + c7276da commit 30ad4c4
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[MAIN]

disable=
duplicate-code
5 changes: 4 additions & 1 deletion ntia_conformance_checker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_parsed_args():
parser.add_argument("--file", help="Filepath for SPDX SBOM")
parser.add_argument(
"--output",
choices=["print", "json", "quiet"],
choices=["print", "json", "html", "quiet"],
default="print",
help="Specify type of output",
)
Expand Down Expand Up @@ -60,6 +60,9 @@ def main():
json.dump(result_dict, outfile)
else:
print(json.dumps(result_dict, indent=2))
if args.output == "html":
html_output = sbom.output_html()
print(html_output)
# 0 indicates success
sys.exit(0 if sbom.ntia_mininum_elements_compliant else 1)

Expand Down
45 changes: 45 additions & 0 deletions ntia_conformance_checker/sbom_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,48 @@ def output_json(self):

result["totalNumberComponents"] = self.get_total_number_components()
return result

def output_html(self):
"""Print HTML of output."""

result = f"""
<h2>NTIA Conformance Results</h2>
<h3>Conformant: {self.ntia_mininum_elements_compliant}
<table>
<tr>
<th>Individual Elements</th>
<th>Conformant</th>
</tr>
<tr>
<td>All component names provided</td>
<td>{not self.components_without_names}</td>
</tr>
<tr>
<td>All component versions provided</td>
<td>{not self.components_without_versions}</td>
</tr>
<tr>
<td>All component identifiers provided</td>
<td>{not self.components_without_identifiers}</td>
</tr>
<tr>
<td>All component suppliers provided</td>
<td>{not self.components_without_suppliers}</td>
</tr>
<tr>
<td>SBOM author name provided</td>
<td>{self.doc_author}</td>
</tr>
<tr>
<td>SBOM creation timestamp provided</td>
<td>{self.doc_timestamp}</td>
</tr>
<tr>
<td>Dependency relationships provided?</td>
<td>{self.dependency_relationships}</td>
</tr>
</table>
"""

return result
50 changes: 50 additions & 0 deletions tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,53 @@ def test_sbomchecker_output_json():
"openssl",
]
assert got["totalNumberComponents"] == 3


def test_sbomchecker_output_html():
filepath = os.path.join(
os.path.dirname(__file__), "data", "other_tests", "SPDXSBOMExample.spdx.yml"
)
sbom = sbom_checker.SbomChecker(filepath)

got = sbom.output_html()
expected = """
<h2>NTIA Conformance Results</h2>
<h3>Conformant: False
<table>
<tr>
<th>Individual Elements</th>
<th>Conformant</th>
</tr>
<tr>
<td>All component names provided</td>
<td>True</td>
</tr>
<tr>
<td>All component versions provided</td>
<td>True</td>
</tr>
<tr>
<td>All component identifiers provided</td>
<td>True</td>
</tr>
<tr>
<td>All component suppliers provided</td>
<td>False</td>
</tr>
<tr>
<td>SBOM author name provided</td>
<td>True</td>
</tr>
<tr>
<td>SBOM creation timestamp provided</td>
<td>False</td>
</tr>
<tr>
<td>Dependency relationships provided?</td>
<td>True</td>
</tr>
</table>
"""

assert got == expected

0 comments on commit 30ad4c4

Please sign in to comment.