@@ -48,7 +48,7 @@ def fetch_list_of_cves() -> Iterable[List[Dict]]:
4848 page_no = 1
4949 cve_data = None
5050 while True :
51- current_url = f"https://access.redhat.com/hydra/rest/securitydata/cve.json?per_page=10000 &page={ page_no } " # nopep8
51+ current_url = f"https://access.redhat.com/hydra/rest/securitydata/cve.json?per_page=1000 &page={ page_no } " # nopep8
5252 try :
5353 response = requests_session .get (current_url )
5454 if response .status_code != requests .codes .ok :
@@ -64,14 +64,12 @@ def fetch_list_of_cves() -> Iterable[List[Dict]]:
6464 yield cve_data
6565
6666
67- def get_bugzilla_data (bugzilla ):
68- return requests_session .get (f"https://bugzilla.redhat.com/rest/bug/{ bugzilla } " ).json ()
69-
70-
71- def get_rhsa_data (rh_adv ):
72- return requests_session .get (
73- f"https://access.redhat.com/hydra/rest/securitydata/cvrf/{ rh_adv } .json"
74- ).json ()
67+ def get_data_from_url (url ):
68+ try :
69+ return requests_session .get (url ).json ()
70+ except Exception as e :
71+ logger .error (f"Failed to fetch results from { url } { e !r} " )
72+ return {}
7573
7674
7775class RedhatImporter (Importer ):
@@ -112,25 +110,24 @@ def to_advisory(advisory_data):
112110 bugzilla = advisory_data .get ("bugzilla" )
113111 if bugzilla :
114112 url = "https://bugzilla.redhat.com/show_bug.cgi?id={}" .format (bugzilla )
115- bugzilla_data = get_bugzilla_data ( bugzilla )
116- if (
117- bugzilla_data .get ("bugs" )
118- and len ( bugzilla_data [ " bugs" ])
119- and bugzilla_data [ "bugs" ][ 0 ]. get ( "severity" )
120- ):
121- bugzilla_severity_val = bugzilla_data [ "bugs" ][ 0 ][ " severity" ]
122- bugzilla_severity = VulnerabilitySeverity (
123- system = severity_systems .REDHAT_BUGZILLA ,
124- value = bugzilla_severity_val ,
125- )
126-
127- references . append (
128- Reference (
129- severities = [ bugzilla_severity ] ,
130- url = url ,
131- reference_id = bugzilla ,
113+ bugzilla_url = f"https:// bugzilla.redhat.com/rest/bug/ { bugzilla } "
114+ bugzilla_data = get_data_from_url ( bugzilla_url )
115+ bugs = bugzilla_data .get ("bugs" ) or []
116+ if bugs :
117+ # why [0] only here?
118+ severity = bugs [ 0 ]. get ( "severity" )
119+ if severity :
120+ bugzilla_severity = VulnerabilitySeverity (
121+ system = severity_systems .REDHAT_BUGZILLA ,
122+ value = severity ,
123+ )
124+ references . append (
125+ Reference (
126+ severities = [ bugzilla_severity ],
127+ url = url ,
128+ reference_id = bugzilla ,
129+ )
132130 )
133- )
134131
135132 for rh_adv in advisory_data .get ("advisories" ) or []:
136133 # RH provides 3 types of advisories RHSA, RHBA, RHEA. Only RHSA's contain severity score.
@@ -141,8 +138,10 @@ def to_advisory(advisory_data):
141138 continue
142139
143140 if "RHSA" in rh_adv .upper ():
144- rhsa_data = get_rhsa_data (rh_adv )
145-
141+ rhsa_url = f"https://access.redhat.com/hydra/rest/securitydata/cvrf/{ rh_adv } .json"
142+ rhsa_data = get_data_from_url (rhsa_url )
143+ if not rhsa_data :
144+ continue
146145 rhsa_aggregate_severities = []
147146 if rhsa_data .get ("cvrfdoc" ):
148147 # not all RHSA errata have a corresponding CVRF document
@@ -189,7 +188,9 @@ def to_advisory(advisory_data):
189188 alias = advisory_data .get ("CVE" )
190189 if alias :
191190 aliases .append (alias )
192- references .append (Reference (severities = redhat_scores , url = advisory_data ["resource_url" ]))
191+ resource_url = advisory_data .get ("resource_url" )
192+ if resource_url :
193+ references .append (Reference (severities = redhat_scores , url = resource_url ))
193194 return AdvisoryData (
194195 aliases = aliases ,
195196 summary = advisory_data .get ("bugzilla_description" ) or "" ,
0 commit comments