@@ -544,6 +544,41 @@ def download_report(self, report_id):
544544 url = self .get_urlbase () + "/api/reports/{}" .format (report_id )
545545 return self .execute_get (url , {'Content-Type' : 'application/zip' , 'Accept' :'application/zip' })
546546
547+ ##
548+ #
549+ # License stuff
550+ #
551+ ##
552+ def _get_license_info (self , license_obj ):
553+ if 'license' in license_obj :
554+ license_info = {}
555+ text_json = {}
556+ logging .debug ("license: {}" .format (license_obj ))
557+ response = self .execute_get (license_obj ['license' ])
558+ if response .status_code == 200 :
559+ license_info = response .json ()
560+ text_url = self .get_link (license_info , 'text' )
561+ response = self .execute_get (text_url )
562+ if response .status_code == 200 :
563+ text_json = response .text
564+ yield {"license_info" : license_info ,
565+ "license_text_info" : text_json }
566+ elif 'licenses' in license_obj and isinstance (license_obj ['licenses' ], list ):
567+ for license in license_obj ['licenses' ]:
568+ self ._get_license_info (license )
569+
570+ def get_license_info_for_bom_component (self , bom_component , limit = 1000 ):
571+ self ._check_version_compatibility ()
572+ all_licenses = {}
573+ logging .debug ("gathering license info for bom component {}, version {}" .format (
574+ bom_component ['componentName' ], bom_component ['componentVersionName' ]))
575+ for license in bom_component .get ('licenses' , []):
576+ for license_info_obj in self ._get_license_info (license ):
577+ all_licenses .update ({
578+ license ['licenseDisplay' ]: license_info_obj
579+ })
580+ return all_licenses
581+
547582 ##
548583 #
549584 # Files and Snippet matching
@@ -564,11 +599,10 @@ def get_file_bom_entries(self, hub_release_id, limit=100):
564599 jsondata = response .json ()
565600 return jsondata
566601
567- def get_file_matches_for_component_with_version (self , project_id , version_id , component_id , component_version_id , limit = 1000 ):
602+ def get_file_matches_for_bom_component (self , bom_component , limit = 1000 ):
568603 self ._check_version_compatibility ()
604+ url = self .get_link (bom_component , "matched-files" )
569605 paramstring = self .get_limit_paramstring (limit )
570- url = "{}/projects/{}/versions/{}/components/{}/versions/{}/matched-files" .format (
571- self .get_apibase (), project_id , version_id , component_id , component_version_id )
572606 logging .debug ("GET {}" .format (url ))
573607 response = self .execute_get (url )
574608 jsondata = response .json ()
0 commit comments