2727class CreateBom (capycli .common .script_base .ScriptBase ):
2828 """Create a SBOM for a project on SW360."""
2929
30+ comments = {
31+ "SOURCE" : CaPyCliBom .SOURCE_FILE_COMMENT ,
32+ "SOURCE_SELF" : CaPyCliBom .SOURCE_FILE_COMMENT ,
33+ "BINARY" : CaPyCliBom .BINARY_FILE_COMMENT ,
34+ "BINARY_SELF" : CaPyCliBom .BINARY_FILE_COMMENT ,
35+ "COMPONENT_LICENSE_INFO_XML" : CaPyCliBom .CLI_API_COMMENT ,
36+ "CLEARING_REPORT" : CaPyCliBom .CRT_API_COMMENT
37+ }
38+
3039 def get_external_id (self , name : str , release_details : dict ):
3140 """Returns the external id with the given name or None."""
3241 if "externalIds" not in release_details :
@@ -51,6 +60,7 @@ def create_project_bom(self, project) -> list:
5160 for release in releases :
5261 print_text (" " , release ["name" ], release ["version" ])
5362 href = release ["_links" ]["self" ]["href" ]
63+ sw360_id = self .client .get_id_from_href (href )
5464
5565 try :
5666 release_details = self .client .get_release_by_url (href )
@@ -85,13 +95,22 @@ def create_project_bom(self, project) -> list:
8595 CycloneDxSupport .set_ext_ref (rel_item , ExternalReferenceType .VCS , comment = None ,
8696 value = release_details ["repository" ]["url" ])
8797
88- for at_type , comment in (("SOURCE" , CaPyCliBom .SOURCE_FILE_COMMENT ),
89- ("BINARY" , CaPyCliBom .BINARY_FILE_COMMENT )):
90- attachments = self .get_release_attachments (release_details , (at_type , at_type + "_SELF" ))
91- for attachment in attachments :
92- CycloneDxSupport .set_ext_ref (rel_item , ExternalReferenceType .DISTRIBUTION ,
93- comment , attachment ["filename" ],
94- HashAlgorithm .SHA_1 , attachment .get ("sha1" ))
98+ attachments = self .get_release_attachments (release_details )
99+ for attachment in attachments :
100+ at_type = attachment ["attachmentType" ]
101+ if at_type not in self .comments :
102+ continue
103+ if at_type in ("SOURCE" , "SOURCE_SELF" , "BINARY" , "BINARY_SELF" ):
104+ ext_ref_type = ExternalReferenceType .DISTRIBUTION
105+ url = attachment ["filename" ]
106+ else :
107+ ext_ref_type = ExternalReferenceType .OTHER
108+ url = self .attachment_api_url (
109+ sw360_id ,
110+ self .client .get_id_from_href (attachment ["_links" ]["self" ]["href" ]))
111+ CycloneDxSupport .set_ext_ref (rel_item , ext_ref_type ,
112+ self .comments [at_type ], url ,
113+ HashAlgorithm .SHA_1 , attachment .get ("sha1" ))
95114
96115 except sw360 .SW360Error as swex :
97116 print_red (" ERROR: unable to access project:" + repr (swex ))
@@ -101,7 +120,6 @@ def create_project_bom(self, project) -> list:
101120 if state :
102121 CycloneDxSupport .set_property (rel_item , CycloneDxSupport .CDX_PROP_PROJ_STATE , state )
103122
104- sw360_id = self .client .get_id_from_href (href )
105123 CycloneDxSupport .set_property (rel_item , CycloneDxSupport .CDX_PROP_SW360ID , sw360_id )
106124
107125 CycloneDxSupport .set_property (
0 commit comments