Skip to content

Commit 8243fef

Browse files
committed
'key' used for both v1 and v2
1 parent fa4dd8b commit 8243fef

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

pyclowder/api/v2/files.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
# pylint: disable=too-many-arguments
32-
def download(connector, host, key, fileid, intermediatefileid=None, ext="", token=None):
32+
def download(connector, host, key, fileid, intermediatefileid=None, ext=""):
3333
"""Download file to be processed from Clowder.
3434
3535
Keyword arguments:
@@ -50,7 +50,7 @@ def download(connector, host, key, fileid, intermediatefileid=None, ext="", toke
5050
intermediatefileid = fileid
5151

5252
url = '%sapi/v2/files/%s' % (host, intermediatefileid)
53-
headers = {"Authorization": "Bearer " + token}
53+
headers = {"Authorization": "Bearer " + key}
5454
result = connector.get(url, stream=True, verify=connector.ssl_verify if connector else True, headers=headers)
5555

5656
(inputfile, inputfilename) = tempfile.mkstemp(suffix=ext)
@@ -65,7 +65,7 @@ def download(connector, host, key, fileid, intermediatefileid=None, ext="", toke
6565
raise
6666

6767

68-
def download_info(connector, host, key, fileid, token=None):
68+
def download_info(connector, host, key, fileid):
6969
"""Download file summary metadata from Clowder.
7070
7171
Keyword arguments:
@@ -76,7 +76,7 @@ def download_info(connector, host, key, fileid, token=None):
7676
"""
7777

7878
url = '%sapi/v2/files/%s/metadata' % (host, fileid)
79-
headers = {"Authorization": "Bearer " + token}
79+
headers = {"Authorization": "Bearer " + key}
8080
# fetch data
8181
result = connector.get(url, stream=True, verify=connector.ssl_verify if connector else True, headers=headers)
8282

@@ -179,7 +179,7 @@ def submit_extractions_by_collection(connector, host, key, collectionid, extract
179179
submit_extractions_by_collection(connector, host, key, coll['id'], extractorname, ext, recursive)
180180

181181

182-
def upload_metadata(connector, host, key, fileid, metadata, token=None):
182+
def upload_metadata(connector, host, key, fileid, metadata):
183183
"""Upload file JSON-LD metadata to Clowder.
184184
185185
Keyword arguments:
@@ -191,12 +191,8 @@ def upload_metadata(connector, host, key, fileid, metadata, token=None):
191191
"""
192192

193193
connector.message_process({"type": "file", "id": fileid}, "Uploading file metadata.")
194-
if token:
195-
headers = {'Content-Type': 'application/json',
196-
'Authorization':'Bearer ' + token}
197-
else:
198-
headers = {'Content-Type': 'application/json',
199-
'Authorization':'Bearer ' + key}
194+
headers = {'Content-Type': 'application/json',
195+
'Authorization':'Bearer ' + key}
200196
print(metadata)
201197
as_json = json.dumps(metadata)
202198
url = '%sapi/v2/files/%s/metadata' % (host, fileid)

pyclowder/connectors.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,6 @@ def _process_message(self, body):
413413
if not source_host.endswith('/'): source_host += '/'
414414
if not host.endswith('/'): host += '/'
415415
secret_key = body.get('secretKey', '')
416-
if clowder_version >= 2.0:
417-
secret_key = body.get('token', '')
418-
token = body.get('token', ' ')
419416
retry_count = 0 if 'retry_count' not in body else body['retry_count']
420417
resource = self._build_resource(body, host, secret_key)
421418
if not resource:
@@ -430,7 +427,7 @@ def _process_message(self, body):
430427
if url not in Connector.registered_clowder:
431428
Connector.registered_clowder.append(url)
432429
if clowder_version >= 2.0:
433-
self.register_extractor("%s" % (url), token=token)
430+
self.register_extractor("%s" % (url), token=secret_key)
434431
else:
435432
self.register_extractor("%s?key=%s" % (url, secret_key))
436433

@@ -453,15 +450,15 @@ def _process_message(self, body):
453450
try:
454451
if check_result != pyclowder.utils.CheckMessage.bypass:
455452
if clowder_version >= 2.0:
456-
file_metadata = pyclowder.files.download_info(self, host, secret_key, resource["id"], token=token)
453+
file_metadata = pyclowder.files.download_info(self, host, secret_key, resource["id"])
457454
else:
458455
file_metadata = pyclowder.files.download_info(self, host, secret_key, resource["id"])
459456
file_path = self._check_for_local_file(file_metadata)
460457
if not file_path:
461458
if clowder_version >= 2.0:
462459
file_path = pyclowder.files.download(self, host, secret_key, resource["id"],
463460
resource["intermediate_id"],
464-
resource["file_ext"], token=token)
461+
resource["file_ext"])
465462
else:
466463
file_path = pyclowder.files.download(self, host, secret_key, resource["id"],
467464
resource["intermediate_id"],

pyclowder/files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def download(connector, host, key, fileid, intermediatefileid=None, ext="", toke
4242
ext -- the file extension, the downloaded file will end with this extension
4343
"""
4444
if clowder_version >= 2.0:
45-
inputfilename = v2files.download(connector, host, key, fileid, intermediatefileid, ext, token)
45+
inputfilename = v2files.download(connector, host, key, fileid, intermediatefileid, ext)
4646
else:
47-
inputfilename = v2files.download(connector, host, key, fileid, intermediatefileid, ext, token)
47+
inputfilename = v1files.download(connector, host, key, fileid, intermediatefileid, ext)
4848
return inputfilename
4949

5050

@@ -59,7 +59,7 @@ def download_info(connector, host, key, fileid, token=None):
5959
"""
6060

6161
if clowder_version >= 2.0:
62-
result = v2files.download_info(connector, host, key, fileid, token)
62+
result = v2files.download_info(connector, host, key, fileid)
6363
else:
6464
result = v1files.download_info(connector, host, key, fileid)
6565
return result.json()

0 commit comments

Comments
 (0)