Skip to content

Commit d135641

Browse files
committed
Add --source-apikey to load private resources
1 parent 74996d9 commit d135641

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

ckanapi/cli/load.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,12 @@ def _upload_resources(ckan,obj,arguments):
285285
for resource in resources:
286286
if resource.get('url_type') != 'upload':
287287
continue
288-
289-
f = requests.get(resource['url'],stream=True)
288+
headers = {}
289+
source_apikey = arguments.get('--source-apikey')
290+
if source_apikey:
291+
headers['X-CKAN-API-Key'] = apikey
292+
headers['Authorization'] = apikey
293+
f = requests.get(resource['url'], headers=headers, stream=True)
290294
name = resource['url'].rsplit('/',1)[-1]
291295
ckan.call_action('resource_patch',
292296
{'id':resource['id']},

ckanapi/cli/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ckanapi load datasets
99
[--upload-resources] [-I JSONL_INPUT] [-s START] [-m MAX]
1010
[-p PROCESSES] [-l LOG_FILE] [-n | -o] [-qwz]
11-
[[-c CONFIG] [-u USER] | -r SITE_URL [-a APIKEY] [--insecure]]
11+
[[-c CONFIG] [-u USER] | -r SITE_URL [-a APIKEY] [-k SOURCE_APIKEY] [--insecure]]
1212
ckanapi load (groups | organizations)
1313
[--upload-logo] [-I JSONL_INPUT] [-s START] [-m MAX]
1414
[-p PROCESSES] [-l LOG_FILE] [-n | -o] [-qwz]
@@ -45,6 +45,7 @@
4545
-j --output-json output plain json instead of pretty-printed json
4646
-J --output-jsonl output list responses as json lines instead of
4747
pretty-printed json
48+
-k --source-apikey API key to use for loading external datasets
4849
-d --datastore-fields export datastore field information along with
4950
resource metadata as datastore_fields lists
5051
-D --datapackages=DIR download resources and output as datapackages

0 commit comments

Comments
 (0)