15 from EricWidgets.EricApplication import ericApp |
15 from EricWidgets.EricApplication import ericApp |
16 from EricWidgets import EricMessageBox |
16 from EricWidgets import EricMessageBox |
17 |
17 |
18 from packageurl import PackageURL |
18 from packageurl import PackageURL |
19 |
19 |
20 from cyclonedx.model import LicenseChoice |
20 from cyclonedx.model import ( |
|
21 ExternalReference, ExternalReferenceType, LicenseChoice, |
|
22 OrganizationalContact, OrganizationalEntity, Tool, XsUri |
|
23 ) |
21 from cyclonedx.model.bom import Bom |
24 from cyclonedx.model.bom import Bom |
22 from cyclonedx.model.component import Component |
25 from cyclonedx.model.component import Component |
23 from cyclonedx.model.vulnerability import Vulnerability, VulnerabilitySource |
26 from cyclonedx.model.vulnerability import Vulnerability, VulnerabilitySource |
24 from cyclonedx.output import ( |
27 from cyclonedx.output import ( |
25 OutputFormat, SchemaVersion, get_instance as get_output_instance |
28 OutputFormat, SchemaVersion, get_instance as get_output_instance |
80 """ |
83 """ |
81 from .CycloneDXConfigDialog import CycloneDXConfigDialog |
84 from .CycloneDXConfigDialog import CycloneDXConfigDialog |
82 dlg = CycloneDXConfigDialog(venvName) |
85 dlg = CycloneDXConfigDialog(venvName) |
83 if dlg.exec() == QDialog.DialogCode.Accepted: |
86 if dlg.exec() == QDialog.DialogCode.Accepted: |
84 (inputSource, inputFile, fileFormat, schemaVersion, sbomFile, |
87 (inputSource, inputFile, fileFormat, schemaVersion, sbomFile, |
85 withVulnerabilities, withDependencies) = dlg.getData() |
88 withVulnerabilities, withDependencies, metadataDict) = dlg.getData() |
86 |
89 |
87 # check error conditions first |
90 # check error conditions first |
88 if inputSource not in ("environment", "pipenv", "poetry", |
91 if inputSource not in ("environment", "pipenv", "poetry", |
89 "requirements"): |
92 "requirements"): |
90 raise RuntimeError("Unsupported input source given.") |
93 raise RuntimeError("Unsupported input source given.") |
141 " version is a mandatory field.</p>" |
144 " version is a mandatory field.</p>" |
142 ).format("".join(excludedList)) |
145 ).format("".join(excludedList)) |
143 ) |
146 ) |
144 |
147 |
145 bom = Bom.from_parser(parser=parser) |
148 bom = Bom.from_parser(parser=parser) |
|
149 # TODO: add meta data to the BOM |
|
150 _amendMetaData(bom.metadata, metadataDict) |
146 output = get_output_instance( |
151 output = get_output_instance( |
147 bom=bom, |
152 bom=bom, |
148 output_format=outputFormat, |
153 output_format=outputFormat, |
149 schema_version=SchemaVersion['V{0}'.format( |
154 schema_version=SchemaVersion['V{0}'.format( |
150 schemaVersion.replace('.', '_') |
155 schemaVersion.replace('.', '_') |
248 for component in components: |
253 for component in components: |
249 if component.name == name: |
254 if component.name == name: |
250 return component |
255 return component |
251 |
256 |
252 return None |
257 return None |
|
258 |
|
259 |
|
260 def _amendMetaData(bomMetaData, metadataDict): |
|
261 """ |
|
262 Function to amend the SBOM meta data according the given data. |
|
263 |
|
264 The modifications done are: |
|
265 <ul> |
|
266 <li>add eric7 to the tools</li> |
|
267 </ul> |
|
268 |
|
269 @param bomMetaData reference to the SBOM meta data object |
|
270 @type BomMetaData |
|
271 @param metadataDict dictionary containing additional meta data |
|
272 @type dict |
|
273 @return reference to the modified SBOM meta data object |
|
274 @rtype BomMetaData |
|
275 """ |
|
276 # add a Tool entry for eric7 |
|
277 try: |
|
278 from importlib.metadata import version as meta_version |
|
279 __EricToolVersion = str(meta_version('eric-ide')) |
|
280 except Exception: |
|
281 from UI.Info import Version |
|
282 __EricToolVersion = Version |
|
283 |
|
284 EricTool = Tool(vendor='python-projects.org', |
|
285 name='eric-ide', |
|
286 version=__EricToolVersion) |
|
287 EricTool.external_references.update([ |
|
288 ExternalReference( |
|
289 reference_type=ExternalReferenceType.DISTRIBUTION, |
|
290 url=XsUri( |
|
291 "https://pypi.org/project/eric-ide/" |
|
292 ) |
|
293 ), |
|
294 ExternalReference( |
|
295 reference_type=ExternalReferenceType.DOCUMENTATION, |
|
296 url=XsUri( |
|
297 "https://pypi.org/project/eric-ide/" |
|
298 ) |
|
299 ), |
|
300 ExternalReference( |
|
301 reference_type=ExternalReferenceType.ISSUE_TRACKER, |
|
302 url=XsUri( |
|
303 "https://tracker.die-offenbachs.homelinux.org" |
|
304 ) |
|
305 ), |
|
306 ExternalReference( |
|
307 reference_type=ExternalReferenceType.LICENSE, |
|
308 url=XsUri( |
|
309 "https://hg.die-offenbachs.homelinux.org/eric/file/tip/docs/" |
|
310 "LICENSE.GPL3" |
|
311 ) |
|
312 ), |
|
313 ExternalReference( |
|
314 reference_type=ExternalReferenceType.RELEASE_NOTES, |
|
315 url=XsUri( |
|
316 "https://hg.die-offenbachs.homelinux.org/eric/file/tip/docs/" |
|
317 "changelog" |
|
318 ) |
|
319 ), |
|
320 ExternalReference( |
|
321 reference_type=ExternalReferenceType.VCS, |
|
322 url=XsUri( |
|
323 "https://hg.die-offenbachs.homelinux.org/eric" |
|
324 ) |
|
325 ), |
|
326 ExternalReference( |
|
327 reference_type=ExternalReferenceType.WEBSITE, |
|
328 url=XsUri( |
|
329 "https://eric-ide.python-projects.org" |
|
330 ) |
|
331 ) |
|
332 ]) |
|
333 bomMetaData.tools.add(EricTool) |
|
334 |
|
335 # add the meta data info entered by the user (if any) |
|
336 if metadataDict is not None: |
|
337 # TODO: add the meta info |
|
338 if metadataDict["AuthorName"]: |
|
339 bomMetaData.authors = [OrganizationalContact( |
|
340 name=metadataDict["AuthorName"], |
|
341 email=metadataDict["AuthorEmail"] |
|
342 )] |
|
343 if metadataDict["Manufacturer"]: |
|
344 bomMetaData.manufacture = OrganizationalEntity( |
|
345 name=metadataDict["Manufacturer"] |
|
346 ) |
|
347 if metadataDict["Supplier"]: |
|
348 bomMetaData.supplier = OrganizationalEntity( |
|
349 name=metadataDict["Supplier"]) |
|
350 if metadataDict["License"]: |
|
351 bomMetaData.licenses = [LicenseChoice( |
|
352 license_expression=metadataDict["License"] |
|
353 )] |
|
354 if metadataDict["Name"]: |
|
355 bomMetaData.component = Component( |
|
356 name=metadataDict["Name"], |
|
357 component_type=metadataDict["Type"], |
|
358 version=metadataDict["Version"], |
|
359 description=metadataDict["Description"], |
|
360 author=metadataDict["AuthorName"], |
|
361 licenses=[LicenseChoice( |
|
362 license_expression=metadataDict["License"] |
|
363 )], |
|
364 ) |
|
365 |
|
366 return bomMetaData |