Skip to content

Commit

Permalink
fix(website): replace confusing utils.is_prod() function (#2898)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
michaelkedar authored Nov 26, 2024
1 parent e1ad1ba commit 5d8c55b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 90 deletions.
2 changes: 1 addition & 1 deletion gcp/website/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import utils

if utils.is_prod():
if utils.is_cloud_run():
instance = flask_caching.Cache(
config={
'CACHE_TYPE': 'RedisCache',
Expand Down
12 changes: 3 additions & 9 deletions gcp/website/frontend_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class VulnerabilityNotImported(VulnerabilityNotFound):
"""Plumb the vulnerability ID with import findings to the error handler."""


if utils.is_prod():
if utils.is_cloud_run():
redis_host = os.environ.get('REDISHOST', 'localhost')
redis_port = int(os.environ.get('REDISPORT', 6379))
limiter = rate_limiter.RateLimiter(
Expand Down Expand Up @@ -250,10 +250,7 @@ def vulnerability(vuln_id):
"""Vulnerability page."""
vuln = osv_get_by_id(vuln_id)

if utils.is_prod():
api_url = 'api.osv.dev'
else:
api_url = 'api.test.osv.dev'
api_url = utils.api_url()

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

if utils.is_prod():
api_url = 'api.osv.dev'
else:
api_url = 'api.test.osv.dev'
api_url = utils.api_url()
return redirect(f'https://{api_url}/v1/vulns/{bug["id"]}')


Expand Down
2 changes: 1 addition & 1 deletion gcp/website/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def middleware(environ, start_response):

def create_app():
"""Create flask app."""
if utils.is_prod():
if utils.is_cloud_run():
logging_client = google.cloud.logging.Client()
logging_client.setup_logging()

Expand Down
Loading

0 comments on commit 5d8c55b

Please sign in to comment.