Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow White Listed DS Sources #30

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_white_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_white_list', '').split()
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
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
Loading