Skip to content

Commit 6e6c999

Browse files
committed
Include Authorization: Bearer token in upload request
1 parent 8c925be commit 6e6c999

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/services/dicom/dicom_uploader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def __init__(self, api_endpoint: str | None = None, timeout: int = 30, verify_ss
2020
self.timeout = timeout
2121
self.verify_ssl = verify_ssl
2222

23+
def headers(self) -> dict:
24+
return {
25+
"Authorization": f"Bearer {os.getenv('CLOUD_API_TOKEN', '')}",
26+
}
27+
2328
def upload_dicom(self, sop_instance_uid: str, dicom_stream: io.BufferedReader, action_id: Optional[str]) -> bool:
2429
if not action_id:
2530
logger.error(f"No action_id for {sop_instance_uid}, upload will be rejected by server")
@@ -37,6 +42,7 @@ def upload_dicom(self, sop_instance_uid: str, dicom_stream: io.BufferedReader, a
3742
files=files,
3843
timeout=self.timeout,
3944
verify=self.verify_ssl,
45+
headers=self.headers(),
4046
)
4147

4248
if response.status_code == 201:

tests/services/dicom/test_dicom_uploader.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def test_upload_success(self, mock_put, dicom_file):
3535

3636
assert result is True
3737
mock_put.assert_called_once_with(
38-
"http://test.com/api/upload/ACTION123", files=mock_put.call_args[1]["files"], timeout=30, verify=True
38+
"http://test.com/api/upload/ACTION123",
39+
files=mock_put.call_args[1]["files"],
40+
timeout=30,
41+
verify=True,
42+
headers=uploader.headers(),
3943
)
4044

4145
call_kwargs = mock_put.call_args[1]

0 commit comments

Comments
 (0)