Skip to content

Commit

Permalink
Merge pull request #30 from open-data/feature/ds-source-domains
Browse files Browse the repository at this point in the history
Allow White Listed DS Sources
  • Loading branch information
JVickery-TBS authored Dec 16, 2024
2 parents 26e9bdb + 4ff79a1 commit 0a8ea29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions changes/30.canada.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow remote DataStore sources. White list domains with `ckanext.canada.datastore_source_domain_allow_list`
17 changes: 9 additions & 8 deletions ckanext/xloader/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,18 @@ def _download_resource_data(resource, data, logger):
url_parts = urlsplit(url)
scheme = url_parts.scheme

# check if it is an uploaded file
domain = url_parts.netloc
site_url = config.get('ckan.site_url')
if resource.get('url_type') != 'upload' and domain != site_url:
raise JobError('Only uploaded files can be added to the Data Store.')
# (canada fork only): uploaded and white listed only
allowed_domains = config.get('ckanext.canada.datastore_source_domain_allow_list', [])
if (resource.get('url_type') != 'upload' and url_parts.netloc not in allowed_domains):
raise JobError('Only uploaded resources and white listed sources can be uploaded to the DataStore.')

# get url from uploader (canada fork only)
#TODO: upstream contribution??
upload = get_resource_uploader(resource)
url = upload.get_path(resource['id'])
logger.info('Resource %s using uploader: %s', resource['id'], type(upload).__name__)
if resource.get('url_type') == 'upload':
upload = get_resource_uploader(resource)
url = upload.get_path(resource['id'])
logger.info('Resource %s using uploader: %s', resource['id'], type(upload).__name__)


# check scheme
url_parts = urlsplit(url)
Expand Down

0 comments on commit 0a8ea29

Please sign in to comment.