Skip to content

Commit

Permalink
Get request url based on environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ximenesuk committed Mar 6, 2024
1 parent bcfdc74 commit 6b05225
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tempfile
import shutil
import requests
import os

from enum import StrEnum
from pathlib import Path
Expand All @@ -24,6 +25,9 @@
BOREHOLE_INDEX_URL = ("https://ogcapi.bgs.ac.uk/collections/agsboreholeindex/items?f=json"
"&properties=bgs_loca_id&filter=INTERSECTS(shape,{polygon})&limit=10")

# Get AGS_API_ENV, defaults to DEVELOP if not set or not recognised.
AGS_API_ENV = os.getenv("AGS_API_ENV", "DEVELOP").upper()

router = APIRouter()

log_responses = dict(error_responses)
Expand Down Expand Up @@ -225,7 +229,7 @@ def prepare_validation_response(request, data):
response_data = {
'msg': f'{len(data)} files validated',
'type': 'success',
'self': str(request.url),
'self': get_request_url(request),
'data': data,
}
return ValidationResponse(**response_data, media_type="application/json")
Expand Down Expand Up @@ -472,7 +476,16 @@ def prepare_count_response(request, count):
response_data = {
'msg': 'Borehole count',
'type': 'success',
'self': str(request.url),
'self': get_request_url(request),
'count': count
}
return BoreholeCountResponse(**response_data, media_type="application/json")


def get_request_url(request):
""" External calls need https to be returned, so check environment."""
request_url = str(request.url)
if AGS_API_ENV == 'PRODUCTION' and request_url.startswith('http:'):
request_url = request_url.replace('http:', 'https:')

return request_url

0 comments on commit 6b05225

Please sign in to comment.