Unverified Commit 55cc4116 authored by mvdbeek's avatar mvdbeek
Browse files

Enable generating urls for WSGI routes within FastAPI routes

parent 6a00e754
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -97,7 +97,10 @@ from galaxy.util.task import IntervalTask
from galaxy.visualization.data_providers.registry import DataProviderRegistry
from galaxy.visualization.genomes import Genomes
from galaxy.visualization.plugins.registry import VisualizationsRegistry
from galaxy.web import url_for
from galaxy.web import (
    legacy_url_for,
    url_for,
)
from galaxy.web.proxy import ProxyManager
from galaxy.web_stack import application_stack_instance, ApplicationStack
from galaxy.webhooks import WebhooksRegistry
@@ -610,10 +613,12 @@ class UniverseApplication(StructuredApp, GalaxyManagerApplication):
        # Inject url_for for components to more easily optionally depend
        # on url_for.
        self.url_for = url_for
        self.legacy_url_for = legacy_url_for

        self.server_starttime = int(time.time())  # used for cachebusting
        # Limit lifetime of tool shed repository cache to app startup
        self.tool_shed_repository_cache = None
        self.legacy_mapper = None
        log.info(f"Galaxy app startup finished {startup_timer}")

    def _shutdown_queue_worker(self):
+10 −7
Original line number Diff line number Diff line
@@ -53,13 +53,16 @@ class DisplayApplicationLink:

    def get_display_url(self, data, trans):
        dataset_hash, user_hash = encode_dataset_user(trans, data, None)
        return trans.app.url_for(controller='dataset',
        return trans.app.legacy_url_for(
            mapper=trans.app.legacy_mapper,
            controller="dataset",
            action="display_application",
            dataset_id=dataset_hash,
            user_id=user_hash,
            app_name=quote_plus(self.display_application.id),
            link_name=quote_plus(self.id),
                                 app_action=None)
            app_action=None,
        )

    def get_inital_values(self, data, trans):
        if self.other_values:
+27 −9
Original line number Diff line number Diff line
@@ -2,7 +2,10 @@
The Galaxy web application framework
"""

from .framework import url_for
from .framework import (
    legacy_url_for,
    url_for,
)
from .framework.base import httpexceptions
from .framework.decorators import (
    do_not_cache,
@@ -25,11 +28,26 @@ from .framework.decorators import (
    require_login,
)

__all__ = ('do_not_cache', 'error', 'expose', 'expose_api',
        'expose_api_anonymous', 'expose_api_anonymous_and_sessionless',
        'expose_api_raw', 'expose_api_raw_anonymous',
        'expose_api_raw_anonymous_and_sessionless',
        'format_return_as_json', 'httpexceptions', 'json', 'json_pretty',
        'legacy_expose_api', 'legacy_expose_api_anonymous',
        'legacy_expose_api_raw', 'legacy_expose_api_raw_anonymous',
        'require_admin', 'require_login', 'url_for')
__all__ = (
    "do_not_cache",
    "error",
    "expose",
    "expose_api",
    "expose_api_anonymous",
    "expose_api_anonymous_and_sessionless",
    "expose_api_raw",
    "expose_api_raw_anonymous",
    "expose_api_raw_anonymous_and_sessionless",
    "format_return_as_json",
    "httpexceptions",
    "json",
    "json_pretty",
    "legacy_expose_api",
    "legacy_expose_api_anonymous",
    "legacy_expose_api_raw",
    "legacy_expose_api_raw_anonymous",
    "require_admin",
    "require_login",
    "legacy_url_for",
    "url_for",
)
+11 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@
Galaxy web application framework
"""

from routes import request_config

from . import base

DEPRECATED_URL_ATTRIBUTE_MESSAGE = "*deprecated attribute, URL not filled in by server*"
@@ -19,4 +21,13 @@ def handle_url_for(*args, **kwargs) -> str:
        return DEPRECATED_URL_ATTRIBUTE_MESSAGE


def legacy_url_for(mapper, *args, **kwargs) -> str:
    """
    Re-establishes the mapper for legacy WSGI routes.
    """
    rc = request_config()
    rc.mapper = mapper
    return base.routes.url_for(*args, **kwargs)


url_for = handle_url_for
+1 −0
Original line number Diff line number Diff line
@@ -205,6 +205,7 @@ def app_pair(global_conf, load_app_kwds=None, wsgi_preflight=True, **kwargs):
    # ==== Done
    # Indicate that all configuration settings have been provided
    webapp.finalize_config()
    app.legacy_mapper = webapp.mapper

    # Wrap the webapp in some useful middleware
    if kwargs.get('middleware', True):
Loading