Skip to content

Commit

Permalink
Update app and proxy for GCP integration (Project-MONAI#1019)
Browse files Browse the repository at this point in the history
* Update app and proxy for GCP integration

Signed-off-by: Andres <[email protected]>

* Fix UnboundLocalError: local variable dw_client

Signed-off-by: Andres <[email protected]>

* Remove else condition

Signed-off-by: Andres <[email protected]>

* Fix Unbound error

Signed-off-by: Andres <[email protected]>

* Return to original change proposal

Signed-off-by: Andres <[email protected]>

* Fix conditional

Signed-off-by: Andres <[email protected]>

* Fix unit test (mock method)

Signed-off-by: Sachidanand Alle <[email protected]>

Signed-off-by: Andres <[email protected]>
Signed-off-by: Sachidanand Alle <[email protected]>
Co-authored-by: SACHIDANAND ALLE <[email protected]>
  • Loading branch information
diazandr3s and SachidanandAlle authored Oct 4, 2022
1 parent e974572 commit 19cbecf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
7 changes: 7 additions & 0 deletions monailabel/endpoints/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ async def proxy_dicom(op: str, path: str, response: Response):
else settings.MONAI_LABEL_QIDO_PREFIX
if op == "qido"
else settings.MONAI_LABEL_STOW_PREFIX
if op == "stow"
else ""
)

# some version of ohif requests metadata using qido so change it to wado
Expand All @@ -80,6 +82,11 @@ async def proxy_dicom(op: str, path: str, response: Response):
return response


@router.get("/dicom/{path:path}", include_in_schema=False)
async def proxy(path: str, response: Response, user: User = Depends(get_basic_user)):
return await proxy_dicom("", path, response)


@router.get("/dicom/wado/{path:path}", include_in_schema=False)
async def proxy_wado(path: str, response: Response, user: User = Depends(get_basic_user)):
return await proxy_dicom("wado", path, response)
Expand Down
27 changes: 16 additions & 11 deletions monailabel/interfaces/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import requests
import schedule
import torch
from dicomweb_client import DICOMwebClient

# added to support connecting to DICOM Store Google Cloud
from dicomweb_client.ext.gcp.session_utils import create_session_from_gcp_credentials
Expand Down Expand Up @@ -149,21 +150,25 @@ def _init_dicomweb_datastore(self) -> Datastore:

dw_session = None
if "googleapis.com" in self.studies:
# google auth case
logger.info("Creating DICOM Credentials for Google Cloud")
dw_session = create_session_from_gcp_credentials()
elif settings.MONAI_LABEL_DICOMWEB_USERNAME and settings.MONAI_LABEL_DICOMWEB_PASSWORD:
dw_session = create_session_from_user_pass(
settings.MONAI_LABEL_DICOMWEB_USERNAME, settings.MONAI_LABEL_DICOMWEB_PASSWORD
dw_client = DICOMwebClient(url=self.studies, session=dw_session)
else:
if settings.MONAI_LABEL_DICOMWEB_USERNAME and settings.MONAI_LABEL_DICOMWEB_PASSWORD:
# userID/passwd case
dw_session = create_session_from_user_pass(
settings.MONAI_LABEL_DICOMWEB_USERNAME, settings.MONAI_LABEL_DICOMWEB_PASSWORD
)
# create dw_client using either dw_session with userID/passwd or None
dw_client = DICOMwebClientX(
url=self.studies,
session=dw_session,
qido_url_prefix=settings.MONAI_LABEL_QIDO_PREFIX,
wado_url_prefix=settings.MONAI_LABEL_WADO_PREFIX,
stow_url_prefix=settings.MONAI_LABEL_STOW_PREFIX,
)

dw_client = DICOMwebClientX(
url=self.studies,
session=dw_session,
qido_url_prefix=settings.MONAI_LABEL_QIDO_PREFIX,
wado_url_prefix=settings.MONAI_LABEL_WADO_PREFIX,
stow_url_prefix=settings.MONAI_LABEL_STOW_PREFIX,
)

self._download_dcmqi_tools()

cache_path = settings.MONAI_LABEL_DICOMWEB_CACHE_PATH
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/endpoints/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MockHttpClient(MagicMock):
def __init__(self, auth):
pass

async def get(self, url):
async def get(self, url, **kwargs):
return SimpleNamespace(content=b"xyz", status_code=400)

async def __aenter__(self):
Expand Down

0 comments on commit 19cbecf

Please sign in to comment.