(
account: str,
container: str,
datasources_collection: AgnosticCollection = Depends(datasource_repo.collection),
access_allowed=Depends(check_access),
)
| 56 | "/api/datasources/{account}/{container}/image", response_class=StreamingResponse |
| 57 | ) |
| 58 | async def get_datasource_image( |
| 59 | account: str, |
| 60 | container: str, |
| 61 | datasources_collection: AgnosticCollection = Depends(datasource_repo.collection), |
| 62 | access_allowed=Depends(check_access), |
| 63 | ): |
| 64 | if access_allowed is None: |
| 65 | raise HTTPException(status_code=403, detail="No Access") |
| 66 | |
| 67 | # Create the imageURL with sasToken |
| 68 | datasource = await datasources_collection.find_one( |
| 69 | { |
| 70 | "account": account, |
| 71 | "container": container, |
| 72 | } |
| 73 | ) |
| 74 | if not datasource: |
| 75 | raise HTTPException(status_code=404, detail="Datasource not found") |
| 76 | |
| 77 | if not datasource["sasToken"]: |
| 78 | datasource["sasToken"] = "" # set to empty str if null |
| 79 | |
| 80 | imageURL = add_URL_sasToken( |
| 81 | account, container, datasource["sasToken"], "", ApiType.IMAGE |
| 82 | ) |
| 83 | |
| 84 | async with httpx.AsyncClient() as client: |
| 85 | response = await client.get(imageURL.get_secret_value()) |
| 86 | if response.status_code != 200: |
| 87 | raise HTTPException(status_code=404, detail="Image not found") |
| 88 | |
| 89 | return StreamingResponse( |
| 90 | response.iter_bytes(), media_type=response.headers["Content-Type"] |
| 91 | ) |
| 92 | |
| 93 | |
| 94 | @router.get( |
nothing calls this directly
no test coverage detected