|
25 | 25 | import logging
|
26 | 26 | import os
|
27 | 27 | import requests
|
| 28 | +from google.protobuf import json_format |
28 | 29 | from requests.adapters import HTTPAdapter
|
29 | 30 | import shutil
|
30 | 31 | import threading
|
|
42 | 43 |
|
43 | 44 | import osv
|
44 | 45 | import osv.logs
|
| 46 | +from osv import vulnerability_pb2 |
45 | 47 |
|
46 | 48 | DEFAULT_WORK_DIR = '/work'
|
47 | 49 | DEFAULT_PUBLIC_LOGGING_BUCKET = 'osv-public-import-logs'
|
@@ -847,7 +849,7 @@ def _process_deletions_bucket(self,
|
847 | 849 |
|
848 | 850 | def _process_updates_rest(self, source_repo: osv.SourceRepository):
|
849 | 851 | """Process updates from REST API.
|
850 |
| - |
| 852 | +
|
851 | 853 | To find new updates, first makes a HEAD request to check the 'Last-Modified'
|
852 | 854 | header, and skips processing if it's before the source's last_modified_date
|
853 | 855 | (and ignore_last_import_time isn't set).
|
@@ -903,11 +905,17 @@ def _process_updates_rest(self, source_repo: osv.SourceRepository):
|
903 | 905 | except Exception:
|
904 | 906 | logging.exception('Exception querying REST API:')
|
905 | 907 | return
|
906 |
| - # Parse vulns into Vulnerability objects from the REST API request. |
907 |
| - vulns = osv.parse_vulnerabilities_from_data( |
908 |
| - request.text, |
909 |
| - source_repo.extension, |
910 |
| - strict=source_repo.strict_validation and self._strict_validation) |
| 908 | + |
| 909 | + data = json.loads(request.text) |
| 910 | + vulns = [] |
| 911 | + for datum in data: |
| 912 | + vulnerability = vulnerability_pb2.Vulnerability() |
| 913 | + json_format.ParseDict(datum, vulnerability, ignore_unknown_fields=True) |
| 914 | + if not vulnerability.id: |
| 915 | + raise ValueError('Missing id field. Invalid vulnerability.') |
| 916 | + if not vulnerability.modified: |
| 917 | + raise ValueError('Missing modified field. Invalid vulnerability.') |
| 918 | + vulns.append(vulnerability) |
911 | 919 |
|
912 | 920 | vulns_last_modified = last_update_date
|
913 | 921 | logging.info('%d records to consider', len(vulns))
|
|
0 commit comments