Commit dff53995 authored by Ayres, Andrew's avatar Ayres, Andrew
Browse files

Merge branch 'interactive_url' into 'dev'

Interactive url

See merge request !68
parents 8d2b69d3 3a901adf
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -143,7 +143,10 @@ class MockApp(di.Container, GalaxyDataTestApp):
        self.auth_manager = AuthManager(self.config)
        self.user_manager = UserManager(cast(BasicSharedApp, self))
        self.execution_timer_factory = Bunch(get_timer=StructuredExecutionTimer)
        self.interactivetool_manager = Bunch(create_interactivetool=lambda *args, **kwargs: None)
        self.interactivetool_manager = Bunch(
            create_interactivetool=lambda *args, **kwargs: None,
            get_job_subdomain=lambda *args, **kwargs: None
        )
        self.is_job_handler = False
        self.biotools_metadata_source = None
        set_thread_app(self)
+5 −3
Original line number Diff line number Diff line
@@ -1243,6 +1243,11 @@ class MinimalJobWrapper(HasResourceParameters):
            self.__prepare_upload_paramfile(job)

        tool_evaluator = self._get_tool_evaluator(job)
        if hasattr(self.app, "interactivetool_manager"):
            self.interactivetools = tool_evaluator.populate_interactivetools()
            self.app.interactivetool_manager.create_interactivetool(job, self.tool, self.interactivetools)
            job.interactive_url = self.app.interactivetool_manager.get_job_subdomain(job)

        compute_environment = compute_environment or self.default_compute_environment(job)
        tool_evaluator.set_compute_environment(compute_environment, get_special=get_special)
        (
@@ -1252,9 +1257,6 @@ class MinimalJobWrapper(HasResourceParameters):
            self.environment_variables,
        ) = tool_evaluator.build()
        job.command_line = self.command_line
        if hasattr(self.app, "interactivetool_manager"):
            self.interactivetools = tool_evaluator.populate_interactivetools()
            self.app.interactivetool_manager.create_interactivetool(job, self.tool, self.interactivetools)

        # Ensure galaxy_lib_dir is set in case there are any later chdirs
        self.galaxy_lib_dir  # noqa: B018
+15 −7
Original line number Diff line number Diff line
@@ -175,6 +175,11 @@ class InteractiveToolManager:
            with transaction(self.sa_session):
                self.sa_session.commit()

    def get_job_subdomain(self, job):
        # returns the url for the first entry point
        for ep in job.interactivetool_entry_points:
            return self.calculate_entry_point(self.app.security.encode_id, ep)

    def configure_entry_point(self, job, tool_port=None, host=None, port=None, protocol=None):
        return self.configure_entry_points(
            job, {tool_port: dict(tool_port=tool_port, host=host, port=port, protocol=protocol)}
@@ -296,6 +301,15 @@ class InteractiveToolManager:
                self.sa_session.commit()
        self.propagator.remove_entry_point(entry_point)

    def calculate_entry_point(self, encode_id, entry_point):
        entry_point_encoded_id = encode_id(entry_point.id)
        entry_point_class = entry_point.__class__.__name__.lower()
        entry_point_prefix = self.app.config.interactivetools_prefix
        entry_point_token = entry_point.token
        if self.app.config.interactivetools_shorten_url:
            return f"{entry_point_encoded_id}-{entry_point_token[:10]}.{entry_point_prefix}"
        return f"{entry_point_encoded_id}-{entry_point_token}.{entry_point_class}.{entry_point_prefix}"

    def target_if_active(self, trans, entry_point):
        if entry_point.active and not entry_point.deleted:
            request_host = trans.request.host
@@ -313,13 +327,7 @@ class InteractiveToolManager:
            return rval

    def get_entry_point_subdomain(self, trans, entry_point):
        entry_point_encoded_id = trans.security.encode_id(entry_point.id)
        entry_point_class = entry_point.__class__.__name__.lower()
        entry_point_prefix = self.app.config.interactivetools_prefix
        entry_point_token = entry_point.token
        if self.app.config.interactivetools_shorten_url:
            return f"{entry_point_encoded_id}-{entry_point_token[:10]}.{entry_point_prefix}"
        return f"{entry_point_encoded_id}-{entry_point_token}.{entry_point_class}.{entry_point_prefix}"
        return self.calculate_entry_point(trans.security.encode_id, entry_point)

    def get_entry_point_path(self, trans, entry_point):
        entry_point_encoded_id = trans.security.encode_id(entry_point.id)
+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ from typing import (
    Optional,
    Union,
)
from urllib.parse import urlparse

from galaxy import model
from galaxy.authnz.util import provider_name_to_backend
@@ -195,6 +196,9 @@ class ToolEvaluator:
        if self._history:
            param_dict["__history_id__"] = self.app.security.encode_id(self._history.id)
        param_dict["__galaxy_url__"] = self.compute_environment.galaxy_url()
        if hasattr(self.job, "interactive_url") and isinstance(self.job.interactive_url, str):
            param_dict["__tool_url_prefix__"] = ''.join([self.job.interactive_url, ".", urlparse(self.compute_environment.galaxy_url()).hostname])

        param_dict.update(self.tool.template_macro_params)
        # All parameters go into the param_dict
        param_dict.update(incoming)