From d34286f57012ffc98dfc382ae97afe9f804db47b Mon Sep 17 00:00:00 2001 From: William Smith Date: Sat, 2 Sep 2023 10:29:55 +0100 Subject: [PATCH] Add functionaility for session based get requests To allow for the cookie from the reverse proxy to propogate through the bioblend API requests - still need to do for all other requests Good start through --- bioblend/galaxy/__init__.py | 3 +++ bioblend/galaxy/objects/galaxy_instance.py | 3 +++ bioblend/galaxyclient.py | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bioblend/galaxy/__init__.py b/bioblend/galaxy/__init__.py index 937b23d28..ea2cd47cb 100644 --- a/bioblend/galaxy/__init__.py +++ b/bioblend/galaxy/__init__.py @@ -3,6 +3,7 @@ """ from typing import Optional +import requests from bioblend.galaxy import ( config, container_resolution, @@ -39,6 +40,7 @@ def __init__( email: Optional[str] = None, password: Optional[str] = None, verify: bool = True, + session: requests.sessions.Session() = None, ) -> None: """ A base representation of a connection to a Galaxy instance, identified @@ -106,6 +108,7 @@ def __init__( self.tool_data = tool_data.ToolDataClient(self) self.folders = folders.FoldersClient(self) self.tool_dependencies = tool_dependencies.ToolDependenciesClient(self) + self.session = session def __repr__(self) -> str: """ diff --git a/bioblend/galaxy/objects/galaxy_instance.py b/bioblend/galaxy/objects/galaxy_instance.py index ddde94831..00102aacf 100644 --- a/bioblend/galaxy/objects/galaxy_instance.py +++ b/bioblend/galaxy/objects/galaxy_instance.py @@ -11,6 +11,7 @@ import bioblend import bioblend.galaxy +import requests from bioblend.galaxy.datasets import TERMINAL_STATES from . import ( client, @@ -57,6 +58,7 @@ def __init__( email: Optional[str] = None, password: Optional[str] = None, verify: bool = True, + session: requests.sessions.Session() = None, ) -> None: self.gi = bioblend.galaxy.GalaxyInstance(url, api_key, email, password, verify) self.log = bioblend.log @@ -68,6 +70,7 @@ def __init__( self.invocations = client.ObjInvocationClient(self) self.tools = client.ObjToolClient(self) self.jobs = client.ObjJobClient(self) + self.session = session def _wait_datasets( self, datasets: Iterable[wrappers.Dataset], polling_interval: float, break_on_error: bool = True diff --git a/bioblend/galaxyclient.py b/bioblend/galaxyclient.py index 3a6c168e0..41569f175 100644 --- a/bioblend/galaxyclient.py +++ b/bioblend/galaxyclient.py @@ -38,6 +38,7 @@ def __init__( password: Optional[str] = None, verify: bool = True, timeout: Optional[float] = None, + session: requests.sessions.Session() = None, ) -> None: """ :param verify: Whether to verify the server's TLS certificate @@ -133,7 +134,7 @@ def make_get_request(self, url: str, **kwargs: Any) -> requests.Response: headers = self.json_headers kwargs.setdefault("timeout", self.timeout) kwargs.setdefault("verify", self.verify) - r = requests.get(url, headers=headers, **kwargs) + r = self.session.get(url, headers=headers, **kwargs) return r def make_post_request(