Skip to content

Commit c71eb3c

Browse files
committed
A few further alliance URL updates:
* Adding alliance download URLs to the list of trusted URLs * Correcting the download URL to point to the proxy location RE:#208
1 parent ccfedf7 commit c71eb3c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

clipping-service/app/app.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@
5757
SOURCE_LOGGER = logging.getLogger('pygeoprocessing')
5858
SOURCE_LOGGER.setLevel(logging.DEBUG)
5959
GOOGLE_STORAGE_URL = 'https://storage.googleapis.com'
60-
TRUSTED_BUCKET = f'{GOOGLE_STORAGE_URL}/natcap-data-cache'
60+
DATAHUB_URL = 'https://data.naturalcapitalalliance.stanford.edu'
61+
TRUSTED_URL_PREFIXES = (
62+
f'{GOOGLE_STORAGE_URL}/natcap-data-cache',
63+
f'{DATAHUB_URL}/download',
64+
'https://data.naturalcapitalproject.stanford.edu/download',
65+
)
6166
TARGET_FILE_BUCKET = 'gs://jupyter-app-temp-storage'
6267
TARGET_BUCKET_SUBDIR = 'clipped'
63-
TARGET_BUCKET_URL = f'{GOOGLE_STORAGE_URL}/jupyter-app-temp-storage/{TARGET_BUCKET_SUBDIR}'
68+
TARGET_DOWNLOAD_URL = f'{DATAHUB_URL}/download/{TARGET_BUCKET_SUBDIR}'
6469
WORKSPACE_DIR = os.environ.get('WORKSPACE_DIR', os.getcwd())
6570
app.logger.info("WORKSPACE_DIR: %s", WORKSPACE_DIR)
6671
pygeoprocessing.geoprocessing._LOGGING_PERIOD = 1.0
@@ -276,8 +281,8 @@ def clip():
276281
parameters = request.get_json()
277282
app.logger.info(parameters)
278283

279-
if not parameters['file_url'].startswith(TRUSTED_BUCKET):
280-
app.logger.error("Invalid source file, not in the known bucket: %s",
284+
if not parameters['file_url'].startswith(TRUSTED_URL_PREFIXES):
285+
app.logger.error("Invalid source file, not from a trusted host: %s",
281286
parameters['file_url'])
282287
raise ValueError("Invalid source file provided.")
283288

@@ -376,7 +381,7 @@ def clip():
376381
app.logger.info(f"Deleting local file {target_file_path}")
377382
os.remove(target_file_path)
378383

379-
downloadable_raster_path = f"{TARGET_BUCKET_URL}/{bucket_filename}"
384+
downloadable_raster_path = f"{TARGET_DOWNLOAD_URL}/{bucket_filename}"
380385
app.logger.info("Returning URL: %s", downloadable_raster_path)
381386
return jsonify({'url': downloadable_raster_path,
382387
'size': filesize})

0 commit comments

Comments
 (0)