Warning

This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for galaxy.webapps.galaxy.api.tours

"""
API Controller providing Galaxy Tours
"""
import logging

from fastapi import Depends
from fastapi_utils.cbv import cbv
from fastapi_utils.inferring_router import InferringRouter as APIRouter

from galaxy.tours import (
    TourDetails,
    TourList,
    ToursRegistry,
)
from galaxy.web import (
    expose_api_anonymous_and_sessionless,
    legacy_expose_api,
    require_admin
)
from galaxy.webapps.base.controller import BaseAPIController
from . import (
    get_admin_user,
    get_app,
)

log = logging.getLogger(__name__)


router = APIRouter(tags=['tours'])


[docs]def get_tours_registry(app=Depends(get_app)) -> ToursRegistry: return app.tour_registry
[docs]@cbv(router) class FastAPITours: registry: ToursRegistry = Depends(get_tours_registry)
[docs] @router.get('/api/tours') def index(self) -> TourList: """Return list of available tours.""" return self.registry.get_tours()
[docs] @router.get('/api/tours/{tour_id}') def show(self, tour_id: str) -> TourDetails: """Return a tour definition.""" return self.registry.tour_contents(tour_id)
[docs] @router.post('/api/tours/{tour_id}', dependencies=[Depends(get_admin_user)]) def update_tour(self, tour_id: str) -> TourDetails: """Return a tour definition.""" return self.registry.load_tour(tour_id)
[docs]class ToursController(BaseAPIController):
[docs] def __init__(self, app): super().__init__(app)
[docs] @expose_api_anonymous_and_sessionless def index(self, trans, **kwd): """ GET /api/tours/ Displays available tours """ return self.app.tour_registry.get_tours()
[docs] @expose_api_anonymous_and_sessionless def show(self, trans, tour_id, **kwd): """ GET /api/tours/{tour_id} Read a YAML file containing the specified tour definition. :returns: tour definition :rtype: dictionary """ return self.app.tour_registry.tour_contents(tour_id)
[docs] @require_admin @legacy_expose_api def update_tour(self, trans, tour_id, **kwd): """This simply reloads tours right now. It's a quick hack.""" # TODO: allow creation of new tours (which get written to the # filesystem). return self.app.tour_registry.load_tour(tour_id)