Skip to content

Commit

Permalink
Add --source-apikey to load private resources
Browse files Browse the repository at this point in the history
  • Loading branch information
frafra committed Feb 1, 2022
1 parent 74996d9 commit 3716ae6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit 3716ae6

Please sign in to comment.