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

Add --source-apikey to load private resources #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions ckanapi/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,12 @@ def _upload_resources(ckan,obj,arguments):
for resource in resources:
if resource.get('url_type') != 'upload':
continue

f = requests.get(resource['url'],stream=True)
headers = {}
source_apikey = arguments.get('--source-apikey')
if source_apikey:
headers['X-CKAN-API-Key'] = apikey
headers['Authorization'] = apikey
f = requests.get(resource['url'], headers=headers, stream=True)
name = resource['url'].rsplit('/',1)[-1]
ckan.call_action('resource_patch',
{'id':resource['id']},
Expand Down
3 changes: 2 additions & 1 deletion ckanapi/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ckanapi load datasets
[--upload-resources] [-I JSONL_INPUT] [-s START] [-m MAX]
[-p PROCESSES] [-l LOG_FILE] [-n | -o] [-qwz]
[[-c CONFIG] [-u USER] | -r SITE_URL [-a APIKEY] [--insecure]]
[[-c CONFIG] [-u USER] | -r SITE_URL [-a APIKEY] [-k SOURCE_APIKEY] [--insecure]]
ckanapi load (groups | organizations)
[--upload-logo] [-I JSONL_INPUT] [-s START] [-m MAX]
[-p PROCESSES] [-l LOG_FILE] [-n | -o] [-qwz]
Expand Down Expand Up @@ -45,6 +45,7 @@
-j --output-json output plain json instead of pretty-printed json
-J --output-jsonl output list responses as json lines instead of
pretty-printed json
-k --source-apikey API key to use for loading external datasets
-d --datastore-fields export datastore field information along with
resource metadata as datastore_fields lists
-D --datapackages=DIR download resources and output as datapackages
Expand Down