anthonyharrison / lib4sbom

Library to ingest and generate SBOMs
Apache License 2.0
14 stars 10 forks source link

TypeError: 'SBOMDocument' object is not iterable #21

Closed rhaley-starfish closed 7 months ago

rhaley-starfish commented 8 months ago

Hello Anthony. I am using lib4sbom 0.5.1 to generate SBOM output. I am trying to add an SBOMDocument to my SBOM and I am running into the above error. Here is the code that I added to my SBOM:

` sbom_document = SBOMDocument()

sbom_document.set_name("ClinicianApp")

sbom_document.set_metadata_version("1.2.2-46")

sbom.add_document(sbom_document)`

And it generates the following error now:

File "C:\Users\rhaley\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\222.3345.131\plugins\python\helpers\pydev\pydevd.py", line 1496, in _exec pydev_imports.execfile(file, globals, locals) # execute the script ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\rhaley\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\222.3345.131\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/rhaley/tuleap/SBOMTools/Client1/Client1_clinician_app.py", line 114, in <module> generate_clinician_sbom() File "C:/Users/rhaley/tuleap/SBOMTools/Client1/Client1_clinician_app.py", line 109, in generate_clinician_sbom sbg.generate("iOSApp", sbom.get_sbom()) File "C:\Users\rhaley\AppData\Local\Programs\Python\Python311\Lib\site-packages\lib4sbom\generator.py", line 81, in generate self._generate_cyclonedx(project_name, sbom_data) File "C:\Users\rhaley\AppData\Local\Programs\Python\Python311\Lib\site-packages\lib4sbom\generator.py", line 287, in _generate_cyclonedx doc.copy_document(sbom_data["document"]) File "C:\Users\rhaley\AppData\Local\Programs\Python\Python311\Lib\site-packages\lib4sbom\data\document.py", line 79, in copy_document for key in document: TypeError: 'SBOMDocument' object is not iterable python-BaseException

I tried modifying the copy_document function and this change works:

def copy_document(self, document):

        for key in document.document:

            self.set_value(key, document.document[key])
rhaley-starfish commented 8 months ago

Ah, I see this may just be a documentation issue. I have a script where the SBOMDocument works, but I add the object differently:

Readme:

my_sbom.add_document(sbom_document)

Actual (note the get_document() call): sbom.add_document(sbom_doc.get_document())