Skip to content

Commit

Permalink
refactor to use explicit validate_xml_vulnerabilities() method (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhamail committed Jan 11, 2020
1 parent 5c1580b commit abf2d18
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion jake/cyclonedx/v1_1/generator.py
Expand Up @@ -35,6 +35,15 @@ def create_xml_from_oss_index_results(self, results):
self.__create_component_nodes(results)
return self.__xml

@staticmethod
def validate_xml_vulnerabilities(xml_vulnerabilities):
"""Validates the given xml against the xsd for vulnerability"""
file = pathlib.Path(__file__).parent / "vuln.xsd"
with open(file, "r") as stdin:
xml_schema_d = etree.parse(stdin)
xml_schema = etree.XMLSchema(xml_schema_d)
return xml_schema.assertValid(xml_vulnerabilities)

def validate_xml(self, xml=None):
"""Takes the XML generated and validates it against the xsd
for the vulnerability"""
Expand Down Expand Up @@ -67,7 +76,7 @@ def __create_component_nodes(self, component_list):
component.get_coordinates(),
vulnerabilities,
node)
self.validate_xml(vulnerabilities)
self.validate_xml_vulnerabilities(vulnerabilities)
self.__xml.append(components)

@staticmethod
Expand Down

0 comments on commit abf2d18

Please sign in to comment.