We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Switch ecosystem from "" to "OSS-Fuzz" for oss-fuzz sourced bugs


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gcp/api/server.py`
Content:
```
1 # Copyright 2021 Google LLC
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """API server implementation."""
15 
16 import argparse
17 from concurrent import futures
18 import functools
19 import logging
20 import os
21 import sys
22 import time
23 
24 from google.cloud import ndb
25 import grpc
26 
27 import osv
28 import osv_service_v1_pb2
29 import osv_service_v1_pb2_grpc
30 
31 _PROJECT = 'oss-vdb'
32 _OSS_FUZZ_TRACKER_URL = 'https://bugs.chromium.org/p/oss-fuzz/issues/detail?id='
33 
34 _SHUTDOWN_GRACE_DURATION = 5
35 
36 _AUTHORIZATION_HEADER_PREFIX = 'Bearer '
37 _EXPECTED_AUDIENCE = 'https://db.oss-fuzz.com'
38 
39 _ndb_client = ndb.Client()
40 
41 
42 def ndb_context(func):
43   """Wrapper to create an NDB context."""
44 
45   @functools.wraps(func)
46   def wrapper(*args, **kwargs):
47     with _ndb_client.context():
48       return func(*args, **kwargs)
49 
50   return wrapper
51 
52 
53 class BaseServicer:
54   """Base servicer."""
55 
56   def is_privileged(self, context):
57     """Check whether if the calling client is privileged."""
58     for key, _ in context.invocation_metadata():
59       # If we have this metadata value, it means it passed JWT validation.
60       if key == 'x-endpoint-api-userinfo':
61         return True
62 
63     return False
64 
65 
66 class OSVServicer(osv_service_v1_pb2_grpc.OSVServicer, BaseServicer):
67   """V1 OSV servicer."""
68 
69   @ndb_context
70   def GetVulnById(self, request, context):
71     """Return a `Vulnerability` object for a given OSV ID.
72     """
73     bug = osv.Bug.get_by_id(request.id)
74     if not bug or bug.status == osv.BugStatus.UNPROCESSED:
75       context.abort(grpc.StatusCode.NOT_FOUND, 'Bug not found.')
76       return None
77 
78     if not bug.public and not self.is_privileged(context):
79       context.abort(grpc.StatusCode.PERMISSION_DENIED, 'Permission denied.')
80       return None
81 
82     return bug_to_response(bug)
83 
84   @ndb_context
85   def QueryAffected(self, request, context):
86     """Query vulnerabilities for a particular project at a given commit or
87     version."""
88     privileged = self.is_privileged(context)
89     if request.query.HasField('package'):
90       package_name = request.query.package.name
91       ecosystem = request.query.package.ecosystem
92     else:
93       package_name = ''
94       ecosystem = ''
95 
96     if request.query.WhichOneof('param') == 'commit':
97       bugs = query_by_commit(
98           package_name,
99           ecosystem,
100           request.query.commit,
101           privileged,
102           to_response=bug_to_response)
103     elif request.query.WhichOneof('param') == 'version':
104       bugs = query_by_version(
105           package_name,
106           ecosystem,
107           request.query.version,
108           privileged,
109           to_response=bug_to_response)
110     else:
111       context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Invalid query.')
112 
113     return osv_service_v1_pb2.VulnerabilityList(vulns=bugs)
114 
115   def GetVulnByIdNew(self, request, context):
116     """Return a `Vulnerability` object for a given OSV ID.
117     """
118     return self.GetVulnById(request, context)
119 
120   def QueryAffectedNew(self, request, context):
121     """Query vulnerabilities for a particular project at a given commit or
122     version."""
123     return self.QueryAffected(request, context)
124 
125 
126 def bug_to_response(bug):
127   """Convert a Bug entity to a response object."""
128   return bug.to_vulnerability()
129 
130 
131 def _get_bugs(bug_ids, to_response=bug_to_response):
132   """Get bugs from bug ids."""
133   bugs = ndb.get_multi([ndb.Key(osv.Bug, bug_id) for bug_id in bug_ids])
134   return [
135       to_response(bug)
136       for bug in bugs
137       if bug and bug.status == osv.BugStatus.PROCESSED
138   ]
139 
140 
141 def query_by_commit(project,
142                     ecosystem,
143                     commit,
144                     privileged,
145                     to_response=bug_to_response):
146   """Query by commit."""
147   query = osv.AffectedCommit.query(osv.AffectedCommit.commit == commit)
148 
149   if project:
150     query = query.filter(osv.AffectedCommit.project == project)
151 
152   if ecosystem:
153     query = query.filter(osv.AffectedCommit.ecosystem == ecosystem)
154 
155   if not privileged:
156     query = query.filter(osv.AffectedCommit.public == True)  # pylint: disable=singleton-comparison
157 
158   bug_ids = []
159   for affected_commit in query:
160     bug_ids.append(affected_commit.bug_id)
161 
162   return _get_bugs(bug_ids, to_response=to_response)
163 
164 
165 def query_by_tag(project,
166                  ecosystem,
167                  tag,
168                  privileged,
169                  to_response=bug_to_response):
170   """Query by tag."""
171   query = osv.Bug.query(osv.Bug.project == project,
172                         osv.Bug.ecosystem == ecosystem, osv.Bug.affected == tag)
173 
174   if not privileged:
175     query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison
176 
177   bugs = []
178   for bug in query:
179     bugs.append(bug)
180 
181   return [to_response(bug) for bug in bugs]
182 
183 
184 def query_by_version(project,
185                      ecosystem,
186                      version,
187                      privileged,
188                      to_response=bug_to_response):
189   """Query by (fuzzy) version."""
190   query = osv.Bug.query(osv.Bug.status == osv.BugStatus.PROCESSED,
191                         osv.Bug.project == project,
192                         osv.Bug.ecosystem == ecosystem,
193                         osv.Bug.affected_fuzzy == osv.normalize_tag(version))
194 
195   if not privileged:
196     query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison
197 
198   bugs = []
199   for bug in query:
200     bugs.append(bug)
201 
202   return [to_response(bug) for bug in bugs]
203 
204 
205 def serve(port):
206   """Configures and runs the bookstore API server."""
207   server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
208   osv_service_v1_pb2_grpc.add_OSVServicer_to_server(OSVServicer(), server)
209   server.add_insecure_port('[::]:{}'.format(port))
210   server.start()
211 
212   print('Listening on port {}'.format(port))
213   try:
214     while True:
215       time.sleep(3600)
216   except KeyboardInterrupt:
217     server.stop(_SHUTDOWN_GRACE_DURATION)
218 
219 
220 def main():
221   """Entrypoint."""
222   logging.basicConfig(stream=sys.stderr)
223   logging.getLogger().setLevel(logging.INFO)
224 
225   parser = argparse.ArgumentParser(
226       formatter_class=argparse.RawDescriptionHelpFormatter)
227   parser.add_argument(
228       '--port',
229       type=int,
230       default=None,
231       help='The port to listen on.'
232       'If arg is not set, will listen on the $PORT env var.'
233       'If env var is empty, defaults to 8000.')
234 
235   args = parser.parse_args()
236   port = args.port
237   if not port:
238     port = os.environ.get('PORT')
239   if not port:
240     port = 8000
241 
242   serve(port)
243 
244 
245 if __name__ == '__main__':
246   main()
247
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gcp/api/server.py b/gcp/api/server.py
--- a/gcp/api/server.py
+++ b/gcp/api/server.py
@@ -187,11 +187,14 @@
                      privileged,
                      to_response=bug_to_response):
   """Query by (fuzzy) version."""
+
   query = osv.Bug.query(osv.Bug.status == osv.BugStatus.PROCESSED,
                         osv.Bug.project == project,
-                        osv.Bug.ecosystem == ecosystem,
                         osv.Bug.affected_fuzzy == osv.normalize_tag(version))
 
+  if ecosystem:
+    query = query.filter(osv.Bug.ecosystem == ecosystem)
+
   if not privileged:
     query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison

{"golden_diff": "diff --git a/gcp/api/server.py b/gcp/api/server.py\n--- a/gcp/api/server.py\n+++ b/gcp/api/server.py\n@@ -187,11 +187,14 @@\n                      privileged,\n                      to_response=bug_to_response):\n   \"\"\"Query by (fuzzy) version.\"\"\"\n+\n   query = osv.Bug.query(osv.Bug.status == osv.BugStatus.PROCESSED,\n                         osv.Bug.project == project,\n-                        osv.Bug.ecosystem == ecosystem,\n                         osv.Bug.affected_fuzzy == osv.normalize_tag(version))\n \n+  if ecosystem:\n+    query = query.filter(osv.Bug.ecosystem == ecosystem)\n+\n   if not privileged:\n     query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison\n", "issue": "Switch ecosystem from \"\" to \"OSS-Fuzz\" for oss-fuzz sourced bugs\n\n", "before_files": [{"content": "# Copyright 2021 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"API server implementation.\"\"\"\n\nimport argparse\nfrom concurrent import futures\nimport functools\nimport logging\nimport os\nimport sys\nimport time\n\nfrom google.cloud import ndb\nimport grpc\n\nimport osv\nimport osv_service_v1_pb2\nimport osv_service_v1_pb2_grpc\n\n_PROJECT = 'oss-vdb'\n_OSS_FUZZ_TRACKER_URL = 'https://bugs.chromium.org/p/oss-fuzz/issues/detail?id='\n\n_SHUTDOWN_GRACE_DURATION = 5\n\n_AUTHORIZATION_HEADER_PREFIX = 'Bearer '\n_EXPECTED_AUDIENCE = 'https://db.oss-fuzz.com'\n\n_ndb_client = ndb.Client()\n\n\ndef ndb_context(func):\n  \"\"\"Wrapper to create an NDB context.\"\"\"\n\n  @functools.wraps(func)\n  def wrapper(*args, **kwargs):\n    with _ndb_client.context():\n      return func(*args, **kwargs)\n\n  return wrapper\n\n\nclass BaseServicer:\n  \"\"\"Base servicer.\"\"\"\n\n  def is_privileged(self, context):\n    \"\"\"Check whether if the calling client is privileged.\"\"\"\n    for key, _ in context.invocation_metadata():\n      # If we have this metadata value, it means it passed JWT validation.\n      if key == 'x-endpoint-api-userinfo':\n        return True\n\n    return False\n\n\nclass OSVServicer(osv_service_v1_pb2_grpc.OSVServicer, BaseServicer):\n  \"\"\"V1 OSV servicer.\"\"\"\n\n  @ndb_context\n  def GetVulnById(self, request, context):\n    \"\"\"Return a `Vulnerability` object for a given OSV ID.\n    \"\"\"\n    bug = osv.Bug.get_by_id(request.id)\n    if not bug or bug.status == osv.BugStatus.UNPROCESSED:\n      context.abort(grpc.StatusCode.NOT_FOUND, 'Bug not found.')\n      return None\n\n    if not bug.public and not self.is_privileged(context):\n      context.abort(grpc.StatusCode.PERMISSION_DENIED, 'Permission denied.')\n      return None\n\n    return bug_to_response(bug)\n\n  @ndb_context\n  def QueryAffected(self, request, context):\n    \"\"\"Query vulnerabilities for a particular project at a given commit or\n    version.\"\"\"\n    privileged = self.is_privileged(context)\n    if request.query.HasField('package'):\n      package_name = request.query.package.name\n      ecosystem = request.query.package.ecosystem\n    else:\n      package_name = ''\n      ecosystem = ''\n\n    if request.query.WhichOneof('param') == 'commit':\n      bugs = query_by_commit(\n          package_name,\n          ecosystem,\n          request.query.commit,\n          privileged,\n          to_response=bug_to_response)\n    elif request.query.WhichOneof('param') == 'version':\n      bugs = query_by_version(\n          package_name,\n          ecosystem,\n          request.query.version,\n          privileged,\n          to_response=bug_to_response)\n    else:\n      context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Invalid query.')\n\n    return osv_service_v1_pb2.VulnerabilityList(vulns=bugs)\n\n  def GetVulnByIdNew(self, request, context):\n    \"\"\"Return a `Vulnerability` object for a given OSV ID.\n    \"\"\"\n    return self.GetVulnById(request, context)\n\n  def QueryAffectedNew(self, request, context):\n    \"\"\"Query vulnerabilities for a particular project at a given commit or\n    version.\"\"\"\n    return self.QueryAffected(request, context)\n\n\ndef bug_to_response(bug):\n  \"\"\"Convert a Bug entity to a response object.\"\"\"\n  return bug.to_vulnerability()\n\n\ndef _get_bugs(bug_ids, to_response=bug_to_response):\n  \"\"\"Get bugs from bug ids.\"\"\"\n  bugs = ndb.get_multi([ndb.Key(osv.Bug, bug_id) for bug_id in bug_ids])\n  return [\n      to_response(bug)\n      for bug in bugs\n      if bug and bug.status == osv.BugStatus.PROCESSED\n  ]\n\n\ndef query_by_commit(project,\n                    ecosystem,\n                    commit,\n                    privileged,\n                    to_response=bug_to_response):\n  \"\"\"Query by commit.\"\"\"\n  query = osv.AffectedCommit.query(osv.AffectedCommit.commit == commit)\n\n  if project:\n    query = query.filter(osv.AffectedCommit.project == project)\n\n  if ecosystem:\n    query = query.filter(osv.AffectedCommit.ecosystem == ecosystem)\n\n  if not privileged:\n    query = query.filter(osv.AffectedCommit.public == True)  # pylint: disable=singleton-comparison\n\n  bug_ids = []\n  for affected_commit in query:\n    bug_ids.append(affected_commit.bug_id)\n\n  return _get_bugs(bug_ids, to_response=to_response)\n\n\ndef query_by_tag(project,\n                 ecosystem,\n                 tag,\n                 privileged,\n                 to_response=bug_to_response):\n  \"\"\"Query by tag.\"\"\"\n  query = osv.Bug.query(osv.Bug.project == project,\n                        osv.Bug.ecosystem == ecosystem, osv.Bug.affected == tag)\n\n  if not privileged:\n    query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison\n\n  bugs = []\n  for bug in query:\n    bugs.append(bug)\n\n  return [to_response(bug) for bug in bugs]\n\n\ndef query_by_version(project,\n                     ecosystem,\n                     version,\n                     privileged,\n                     to_response=bug_to_response):\n  \"\"\"Query by (fuzzy) version.\"\"\"\n  query = osv.Bug.query(osv.Bug.status == osv.BugStatus.PROCESSED,\n                        osv.Bug.project == project,\n                        osv.Bug.ecosystem == ecosystem,\n                        osv.Bug.affected_fuzzy == osv.normalize_tag(version))\n\n  if not privileged:\n    query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison\n\n  bugs = []\n  for bug in query:\n    bugs.append(bug)\n\n  return [to_response(bug) for bug in bugs]\n\n\ndef serve(port):\n  \"\"\"Configures and runs the bookstore API server.\"\"\"\n  server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))\n  osv_service_v1_pb2_grpc.add_OSVServicer_to_server(OSVServicer(), server)\n  server.add_insecure_port('[::]:{}'.format(port))\n  server.start()\n\n  print('Listening on port {}'.format(port))\n  try:\n    while True:\n      time.sleep(3600)\n  except KeyboardInterrupt:\n    server.stop(_SHUTDOWN_GRACE_DURATION)\n\n\ndef main():\n  \"\"\"Entrypoint.\"\"\"\n  logging.basicConfig(stream=sys.stderr)\n  logging.getLogger().setLevel(logging.INFO)\n\n  parser = argparse.ArgumentParser(\n      formatter_class=argparse.RawDescriptionHelpFormatter)\n  parser.add_argument(\n      '--port',\n      type=int,\n      default=None,\n      help='The port to listen on.'\n      'If arg is not set, will listen on the $PORT env var.'\n      'If env var is empty, defaults to 8000.')\n\n  args = parser.parse_args()\n  port = args.port\n  if not port:\n    port = os.environ.get('PORT')\n  if not port:\n    port = 8000\n\n  serve(port)\n\n\nif __name__ == '__main__':\n  main()\n", "path": "gcp/api/server.py"}], "after_files": [{"content": "# Copyright 2021 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"API server implementation.\"\"\"\n\nimport argparse\nfrom concurrent import futures\nimport functools\nimport logging\nimport os\nimport sys\nimport time\n\nfrom google.cloud import ndb\nimport grpc\n\nimport osv\nimport osv_service_v1_pb2\nimport osv_service_v1_pb2_grpc\n\n_PROJECT = 'oss-vdb'\n_OSS_FUZZ_TRACKER_URL = 'https://bugs.chromium.org/p/oss-fuzz/issues/detail?id='\n\n_SHUTDOWN_GRACE_DURATION = 5\n\n_AUTHORIZATION_HEADER_PREFIX = 'Bearer '\n_EXPECTED_AUDIENCE = 'https://db.oss-fuzz.com'\n\n_ndb_client = ndb.Client()\n\n\ndef ndb_context(func):\n  \"\"\"Wrapper to create an NDB context.\"\"\"\n\n  @functools.wraps(func)\n  def wrapper(*args, **kwargs):\n    with _ndb_client.context():\n      return func(*args, **kwargs)\n\n  return wrapper\n\n\nclass BaseServicer:\n  \"\"\"Base servicer.\"\"\"\n\n  def is_privileged(self, context):\n    \"\"\"Check whether if the calling client is privileged.\"\"\"\n    for key, _ in context.invocation_metadata():\n      # If we have this metadata value, it means it passed JWT validation.\n      if key == 'x-endpoint-api-userinfo':\n        return True\n\n    return False\n\n\nclass OSVServicer(osv_service_v1_pb2_grpc.OSVServicer, BaseServicer):\n  \"\"\"V1 OSV servicer.\"\"\"\n\n  @ndb_context\n  def GetVulnById(self, request, context):\n    \"\"\"Return a `Vulnerability` object for a given OSV ID.\n    \"\"\"\n    bug = osv.Bug.get_by_id(request.id)\n    if not bug or bug.status == osv.BugStatus.UNPROCESSED:\n      context.abort(grpc.StatusCode.NOT_FOUND, 'Bug not found.')\n      return None\n\n    if not bug.public and not self.is_privileged(context):\n      context.abort(grpc.StatusCode.PERMISSION_DENIED, 'Permission denied.')\n      return None\n\n    return bug_to_response(bug)\n\n  @ndb_context\n  def QueryAffected(self, request, context):\n    \"\"\"Query vulnerabilities for a particular project at a given commit or\n    version.\"\"\"\n    privileged = self.is_privileged(context)\n    if request.query.HasField('package'):\n      package_name = request.query.package.name\n      ecosystem = request.query.package.ecosystem\n    else:\n      package_name = ''\n      ecosystem = ''\n\n    if request.query.WhichOneof('param') == 'commit':\n      bugs = query_by_commit(\n          package_name,\n          ecosystem,\n          request.query.commit,\n          privileged,\n          to_response=bug_to_response)\n    elif request.query.WhichOneof('param') == 'version':\n      bugs = query_by_version(\n          package_name,\n          ecosystem,\n          request.query.version,\n          privileged,\n          to_response=bug_to_response)\n    else:\n      context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Invalid query.')\n\n    return osv_service_v1_pb2.VulnerabilityList(vulns=bugs)\n\n  def GetVulnByIdNew(self, request, context):\n    \"\"\"Return a `Vulnerability` object for a given OSV ID.\n    \"\"\"\n    return self.GetVulnById(request, context)\n\n  def QueryAffectedNew(self, request, context):\n    \"\"\"Query vulnerabilities for a particular project at a given commit or\n    version.\"\"\"\n    return self.QueryAffected(request, context)\n\n\ndef bug_to_response(bug):\n  \"\"\"Convert a Bug entity to a response object.\"\"\"\n  return bug.to_vulnerability()\n\n\ndef _get_bugs(bug_ids, to_response=bug_to_response):\n  \"\"\"Get bugs from bug ids.\"\"\"\n  bugs = ndb.get_multi([ndb.Key(osv.Bug, bug_id) for bug_id in bug_ids])\n  return [\n      to_response(bug)\n      for bug in bugs\n      if bug and bug.status == osv.BugStatus.PROCESSED\n  ]\n\n\ndef query_by_commit(project,\n                    ecosystem,\n                    commit,\n                    privileged,\n                    to_response=bug_to_response):\n  \"\"\"Query by commit.\"\"\"\n  query = osv.AffectedCommit.query(osv.AffectedCommit.commit == commit)\n\n  if project:\n    query = query.filter(osv.AffectedCommit.project == project)\n\n  if ecosystem:\n    query = query.filter(osv.AffectedCommit.ecosystem == ecosystem)\n\n  if not privileged:\n    query = query.filter(osv.AffectedCommit.public == True)  # pylint: disable=singleton-comparison\n\n  bug_ids = []\n  for affected_commit in query:\n    bug_ids.append(affected_commit.bug_id)\n\n  return _get_bugs(bug_ids, to_response=to_response)\n\n\ndef query_by_tag(project,\n                 ecosystem,\n                 tag,\n                 privileged,\n                 to_response=bug_to_response):\n  \"\"\"Query by tag.\"\"\"\n  query = osv.Bug.query(osv.Bug.project == project,\n                        osv.Bug.ecosystem == ecosystem, osv.Bug.affected == tag)\n\n  if not privileged:\n    query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison\n\n  bugs = []\n  for bug in query:\n    bugs.append(bug)\n\n  return [to_response(bug) for bug in bugs]\n\n\ndef query_by_version(project,\n                     ecosystem,\n                     version,\n                     privileged,\n                     to_response=bug_to_response):\n  \"\"\"Query by (fuzzy) version.\"\"\"\n\n  query = osv.Bug.query(osv.Bug.status == osv.BugStatus.PROCESSED,\n                        osv.Bug.project == project,\n                        osv.Bug.affected_fuzzy == osv.normalize_tag(version))\n\n  if ecosystem:\n    query = query.filter(osv.Bug.ecosystem == ecosystem)\n\n  if not privileged:\n    query = query.filter(osv.Bug.public == True)  # pylint: disable=singleton-comparison\n\n  bugs = []\n  for bug in query:\n    bugs.append(bug)\n\n  return [to_response(bug) for bug in bugs]\n\n\ndef serve(port):\n  \"\"\"Configures and runs the bookstore API server.\"\"\"\n  server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))\n  osv_service_v1_pb2_grpc.add_OSVServicer_to_server(OSVServicer(), server)\n  server.add_insecure_port('[::]:{}'.format(port))\n  server.start()\n\n  print('Listening on port {}'.format(port))\n  try:\n    while True:\n      time.sleep(3600)\n  except KeyboardInterrupt:\n    server.stop(_SHUTDOWN_GRACE_DURATION)\n\n\ndef main():\n  \"\"\"Entrypoint.\"\"\"\n  logging.basicConfig(stream=sys.stderr)\n  logging.getLogger().setLevel(logging.INFO)\n\n  parser = argparse.ArgumentParser(\n      formatter_class=argparse.RawDescriptionHelpFormatter)\n  parser.add_argument(\n      '--port',\n      type=int,\n      default=None,\n      help='The port to listen on.'\n      'If arg is not set, will listen on the $PORT env var.'\n      'If env var is empty, defaults to 8000.')\n\n  args = parser.parse_args()\n  port = args.port\n  if not port:\n    port = os.environ.get('PORT')\n  if not port:\n    port = 8000\n\n  serve(port)\n\n\nif __name__ == '__main__':\n  main()\n", "path": "gcp/api/server.py"}]}