Skip to content

Commit

Permalink
Remove cbv from api.drs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Dec 14, 2023
1 parent 39e93a1 commit 59bde46
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions lib/galaxy/webapps/galaxy/api/drs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,73 +38,73 @@
DRS_SERVICE_DESCRIPTION = "Serves Galaxy datasets according to the GA4GH DRS specification"


@router.cbv
class DrsApi:
service: DatasetsService = depends(DatasetsService)
config: GalaxyAppConfiguration = depends(GalaxyAppConfiguration)
@router.get("/ga4gh/drs/v1/service-info")
def service_info(request: Request, config: GalaxyAppConfiguration = depends(GalaxyAppConfiguration)) -> Service:
components = request.url.components
hostname = components.hostname
assert hostname
default_organization_id = ".".join(reversed(hostname.split(".")))
organization_id = config.ga4gh_service_id or default_organization_id
organization_name = config.organization_name or organization_id
organization_url = config.organization_url or f"{components.scheme}://{components.netloc}"

@router.get("/ga4gh/drs/v1/service-info")
def service_info(self, request: Request) -> Service:
components = request.url.components
hostname = components.hostname
assert hostname
default_organization_id = ".".join(reversed(hostname.split(".")))
config = self.config
organization_id = config.ga4gh_service_id or default_organization_id
organization_name = config.organization_name or organization_id
organization_url = config.organization_url or f"{components.scheme}://{components.netloc}"
organization = ServiceOrganization(
url=organization_url,
name=organization_name,
)
service_type = ServiceType(
group="org.ga4gh",
artifact="drs",
version="1.2.0",
)
extra_kwds = {}
if environment := config.ga4gh_service_environment:
extra_kwds["environment"] = environment
return Service(
id=organization_id + ".drs",
name=DRS_SERVICE_NAME,
description=DRS_SERVICE_DESCRIPTION,
organization=organization,
type=service_type,
version=VERSION,
**extra_kwds,
)

organization = ServiceOrganization(
url=organization_url,
name=organization_name,
)
service_type = ServiceType(
group="org.ga4gh",
artifact="drs",
version="1.2.0",
)
extra_kwds = {}
if environment := config.ga4gh_service_environment:
extra_kwds["environment"] = environment
return Service(
id=organization_id + ".drs",
name=DRS_SERVICE_NAME,
description=DRS_SERVICE_DESCRIPTION,
organization=organization,
type=service_type,
version=VERSION,
**extra_kwds,
)

@router.get("/ga4gh/drs/v1/objects/{object_id}")
@router.post("/ga4gh/drs/v1/objects/{object_id}") # spec specifies both get and post should work.
def get_object(
self,
request: Request,
trans: ProvidesHistoryContext = DependsOnTrans,
object_id: str = ObjectIDParam,
) -> DrsObject:
return self.service.get_drs_object(trans, object_id, request_url=request.url)
@router.get("/ga4gh/drs/v1/objects/{object_id}")
@router.post("/ga4gh/drs/v1/objects/{object_id}") # spec specifies both get and post should work.
def get_object(
request: Request,
trans: ProvidesHistoryContext = DependsOnTrans,
object_id: str = ObjectIDParam,
service: DatasetsService = depends(DatasetsService),
) -> DrsObject:
return service.get_drs_object(trans, object_id, request_url=request.url)

@router.get("/ga4gh/drs/v1/objects/{object_id}/access/{access_id}")
@router.post("/ga4gh/drs/v1/objects/{object_id}/access/{access_id}")
def get_access_url(
self,
request: Request,
trans: ProvidesHistoryContext = DependsOnTrans,
object_id: str = ObjectIDParam,
access_id: str = AccessIDParam,
):
raise ObjectNotFound("Access IDs are not implemented for this DRS server")

@router.get(
"/api/drs_download/{object_id}",
response_class=FileResponse,
@router.get("/ga4gh/drs/v1/objects/{object_id}/access/{access_id}")
@router.post("/ga4gh/drs/v1/objects/{object_id}/access/{access_id}")
def get_access_url(
request: Request,
trans: ProvidesHistoryContext = DependsOnTrans,
object_id: str = ObjectIDParam,
access_id: str = AccessIDParam,
):
raise ObjectNotFound("Access IDs are not implemented for this DRS server")


@router.get(
"/api/drs_download/{object_id}",
response_class=FileResponse,
)
def download(
trans: ProvidesHistoryContext = DependsOnTrans,
object_id: str = ObjectIDParam,
service: DatasetsService = depends(DatasetsService),
):
decoded_object_id, hda_ldda = service.drs_dataset_instance(object_id)
display_data, headers = service.display(
trans, DecodedDatabaseIdField(decoded_object_id), hda_ldda=hda_ldda, filename=None, raw=True
)
def download(self, trans: ProvidesHistoryContext = DependsOnTrans, object_id: str = ObjectIDParam):
decoded_object_id, hda_ldda = self.service.drs_dataset_instance(object_id)
display_data, headers = self.service.display(
trans, DecodedDatabaseIdField(decoded_object_id), hda_ldda=hda_ldda, filename=None, raw=True
)
data_io = cast(IOBase, display_data)
return FileResponse(getattr(data_io, "name", "unnamed_file"), headers=headers)
data_io = cast(IOBase, display_data)
return FileResponse(getattr(data_io, "name", "unnamed_file"), headers=headers)

0 comments on commit 59bde46

Please sign in to comment.