Skip to content

Commit 5d8c55b

Browse files
authored
fix(website): replace confusing utils.is_prod() function (#2898)
`utils.is_prod()` was actually checking if we were running on Cloud Run (returning True if running on 'oss-vdb-test'). Renamed it to `is_cloud_run()` to be less confusing. Also created `utils.api_url()` to use where `is_prod` was being used incorrectly.
1 parent e1ad1ba commit 5d8c55b

File tree

6 files changed

+101
-90
lines changed

6 files changed

+101
-90
lines changed

gcp/website/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import utils
2424

25-
if utils.is_prod():
25+
if utils.is_cloud_run():
2626
instance = flask_caching.Cache(
2727
config={
2828
'CACHE_TYPE': 'RedisCache',

gcp/website/frontend_handlers.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class VulnerabilityNotImported(VulnerabilityNotFound):
6868
"""Plumb the vulnerability ID with import findings to the error handler."""
6969

7070

71-
if utils.is_prod():
71+
if utils.is_cloud_run():
7272
redis_host = os.environ.get('REDISHOST', 'localhost')
7373
redis_port = int(os.environ.get('REDISPORT', 6379))
7474
limiter = rate_limiter.RateLimiter(
@@ -250,10 +250,7 @@ def vulnerability(vuln_id):
250250
"""Vulnerability page."""
251251
vuln = osv_get_by_id(vuln_id)
252252

253-
if utils.is_prod():
254-
api_url = 'api.osv.dev'
255-
else:
256-
api_url = 'api.test.osv.dev'
253+
api_url = utils.api_url()
257254

258255
return render_template(
259256
'vulnerability.html', vulnerability=vuln, api_url=api_url)
@@ -287,10 +284,7 @@ def vulnerability_json_redirector(potential_vuln_id):
287284
# This calls abort() on failed retrievals.
288285
bug = osv_get_by_id(potential_vuln_id)
289286

290-
if utils.is_prod():
291-
api_url = 'api.osv.dev'
292-
else:
293-
api_url = 'api.test.osv.dev'
287+
api_url = utils.api_url()
294288
return redirect(f'https://{api_url}/v1/vulns/{bug["id"]}')
295289

296290

gcp/website/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def middleware(environ, start_response):
4141

4242
def create_app():
4343
"""Create flask app."""
44-
if utils.is_prod():
44+
if utils.is_cloud_run():
4545
logging_client = google.cloud.logging.Client()
4646
logging_client.setup_logging()
4747

0 commit comments

Comments
 (0)