diff --git a/ckanapi/cli/load.py b/ckanapi/cli/load.py index 48b469a..65ff44e 100644 --- a/ckanapi/cli/load.py +++ b/ckanapi/cli/load.py @@ -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']}, diff --git a/ckanapi/cli/main.py b/ckanapi/cli/main.py index b84f461..7d54f2d 100644 --- a/ckanapi/cli/main.py +++ b/ckanapi/cli/main.py @@ -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] @@ -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