Example #1
0
  def _request_analysis_external(self,
                                 source_repo,
                                 original_sha256,
                                 path,
                                 deleted=False,
                                 vulnerability=None):
    """Request analysis."""
    self._publisher.publish(
        _TASKS_TOPIC,
        data=b'',
        type='update',
        source=source_repo.name,
        path=path,
        original_sha256=original_sha256,
        deleted=str(deleted).lower())

    if not vulnerability:
      return

    ecosystem_push_topic = _ECOSYSTEM_PUSH_TOPICS.get(
        vulnerability.package.ecosystem)
    if ecosystem_push_topic:
      self._publisher.publish(
          ecosystem_push_topic,
          data=json.dumps(osv.vulnerability_to_dict(vulnerability)).encode())
Example #2
0
def bug_to_response(bug, detailed=True):
    """Convert a Bug entity to a response object."""
    response = osv.vulnerability_to_dict(bug.to_vulnerability())
    response.update({
        'isFixed': bug.is_fixed,
        'invalid': bug.status == osv.BugStatus.INVALID
    })

    if detailed:
        add_links(response)
        add_source_info(bug, response)
    return response
Example #3
0
    def export_oss_fuzz(vulnerability, testcase_id, issue_id):
      """Export a single vulnerability."""
      try:
        blob = bucket.blob(f'testcase/{testcase_id}.json')
        data = json.dumps(osv.vulnerability_to_dict(vulnerability))
        blob.upload_from_string(data)

        if not issue_id:
          return

        blob = bucket.blob(f'issue/{issue_id}.json')
        blob.upload_from_string(data)
      except Exception as e:
        logging.error('Failed to export: %s', e)