Skip to content

Commit

Permalink
Fix/qdr token header (#8)
Browse files Browse the repository at this point in the history
* fix: use qdr access token as bearer token

* update version
  • Loading branch information
mfshao authored Jul 10, 2024
1 parent 3708bf4 commit c6dcf41
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions heal/qdr_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def get_syracuse_qdr_files(

idp_access_token = get_idp_access_token(wts_hostname, auth, file_metadata)
request_headers = get_request_headers(idp_access_token)
if "X-Dataverse-key" not in request_headers:
logger.critical("WARNING Request headers do not include 'X-Dataverse-key'.")
if "Authorization" not in request_headers:
logger.critical("WARNING Request headers do not include a bearer token.")

logger.debug(f"Request headers = {request_headers}")

Expand Down Expand Up @@ -254,15 +254,15 @@ def get_request_headers(idp_access_token: str) -> Dict:
Generate the request headers.
Args:
idp_access_token (str): QDR token is included in X-Dataverse-key header
idp_access_token (str): QDR access token is included in request header as bearer token
file_metadata (Dict)
Returns:
Dictionary of request headers
"""
headers = {}
if idp_access_token:
headers["X-Dataverse-key"] = idp_access_token
headers["Authorization"] = f"Bearer {idp_access_token}"

return headers

Expand Down
13 changes: 7 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "heal"
version = "0.1.1"
version = "0.1.2"
description = "HEAL Platform SDK"
authors = ["Center for Translational Data Science at the University of Chicago <[email protected]>"]
license = "Apache-2.0"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_qdr_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def test_get_idp_access_token(wts_hostname):
def test_get_request_headers_for_study_or_file():
mock_idp_token = "some-idp-token"

# idp_token is present - just the X-Dataverse-key
expected_headers = {"X-Dataverse-key": mock_idp_token}
# idp_token is present - just the bearer token
expected_headers = {"Authorization": f"Bearer {mock_idp_token}"}
assert get_request_headers(idp_access_token=mock_idp_token) == expected_headers

# missing idp token - empty headers
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_get_filename_from_headers_invalid():


def test_download_from_url(download_dir):
request_headers = {"X-Dataverse-key": "some-idp-token"}
request_headers = {"Authorization": "Bearer some-idp-token"}
mock_data = "foo"

with requests_mock.Mocker() as m:
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_download_from_url(download_dir):


def test_download_from_url_failures(download_dir):
request_headers = {"X-Dataverse-key": "some-idp-token"}
request_headers = {"Authorization": "Bearer some-idp-token"}
valid_response_headers = {"Content-Type": "application/zip"}
mock_data = "foo"
mock_zip_file_name = "dataverse_files.zip"
Expand Down

0 comments on commit c6dcf41

Please sign in to comment.