Skip to content

Commit

Permalink
Use the Butler to retrieve a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirving committed May 8, 2024
1 parent 8517bc1 commit 585fa5d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/butlerexampleservice/handlers/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from typing import Annotated

from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException
from lsst.daf.butler import LabeledButlerFactory
from safir.dependencies.gafaelfawr import auth_delegated_token_dependency
from safir.dependencies.logger import logger_dependency
from safir.metadata import get_metadata
from structlog.stdlib import BoundLogger
Expand All @@ -15,8 +17,6 @@
external_router = APIRouter()
"""FastAPI router for all external handlers."""

from lsst.daf.butler import LabeledButlerFactory
from safir.dependencies.gafaelfawr import auth_delegated_token_dependency

_BUTLER_FACTORY = LabeledButlerFactory()
_BUTLER_REPOSITORY = "dp02"
Expand All @@ -32,7 +32,14 @@ def get_coadd_url(
label=_BUTLER_REPOSITORY, access_token=delegated_token
)

return f"http://stub.example/{tract}/{patch}"
ref = butler.find_dataset(
"deepCoadd",
dataId={"tract": tract, "patch": patch, "band": "i", "skymap": "DC2"},
collections="2.2i/runs/DP0.2",
)
if ref is None:
raise HTTPException(status_code=404, detail="Coadd not found")
return str(butler.getURI(ref))


@external_router.get(
Expand Down

0 comments on commit 585fa5d

Please sign in to comment.