From 2d3ad09ff8a8acccf3a4b0775e62887bfde77b17 Mon Sep 17 00:00:00 2001 From: Daniel Blankenberg Date: Wed, 29 Jan 2020 16:49:26 -0500 Subject: [PATCH] Allow specifying the User-Agent when creating a GalaxyClient --- bioblend/galaxy/__init__.py | 3 ++- bioblend/galaxy/objects/galaxy_instance.py | 5 ++++- bioblend/galaxyclient.py | 3 +++ bioblend/toolshed/__init__.py | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bioblend/galaxy/__init__.py b/bioblend/galaxy/__init__.py index 8c5a652fb..e23d8d930 100644 --- a/bioblend/galaxy/__init__.py +++ b/bioblend/galaxy/__init__.py @@ -41,6 +41,7 @@ def __init__( password: Optional[str] = None, *, verify: bool = True, + user_agent: Optional[str] = None, ) -> None: """ A base representation of a connection to a Galaxy instance, identified @@ -83,7 +84,7 @@ def __init__( :param verify: Whether to verify the server's TLS certificate :type verify: bool """ - super().__init__(url, key=key, email=email, password=password, verify=verify) + super().__init__(url, key=key, email=email, password=password, verify=verify, user_agent=user_agent) self.libraries = libraries.LibraryClient(self) self.histories = histories.HistoryClient(self) self.workflows = workflows.WorkflowClient(self) diff --git a/bioblend/galaxy/objects/galaxy_instance.py b/bioblend/galaxy/objects/galaxy_instance.py index 470d7a11c..2da9648bc 100644 --- a/bioblend/galaxy/objects/galaxy_instance.py +++ b/bioblend/galaxy/objects/galaxy_instance.py @@ -58,8 +58,11 @@ def __init__( password: Optional[str] = None, *, verify: bool = True, + user_agent: Optional[str] = None, ) -> None: - self.gi = bioblend.galaxy.GalaxyInstance(url, key=api_key, email=email, password=password, verify=verify) + self.gi = bioblend.galaxy.GalaxyInstance( + url, key=api_key, email=email, password=password, verify=verify, user_agent=user_agent + ) self.log = bioblend.log self.datasets = client.ObjDatasetClient(self) self.dataset_collections = client.ObjDatasetCollectionClient(self) diff --git a/bioblend/galaxyclient.py b/bioblend/galaxyclient.py index d369bfec1..cc08e1ab0 100644 --- a/bioblend/galaxyclient.py +++ b/bioblend/galaxyclient.py @@ -42,6 +42,7 @@ def __init__( *, verify: bool = True, timeout: Optional[float] = None, + user_agent: Optional[str] = None, ) -> None: """ :param verify: Whether to verify the server's TLS certificate @@ -81,6 +82,8 @@ def __init__( self.email = email self.password = password self.json_headers: Dict[str, Union[str, bytes]] = {"Content-Type": "application/json"} + if user_agent: + self.json_headers["User-Agent"] = user_agent # json_headers needs to be set before key can be defined, otherwise authentication with email/password causes an error self.json_headers["x-api-key"] = self.key # Number of attempts before giving up on a GET request. diff --git a/bioblend/toolshed/__init__.py b/bioblend/toolshed/__init__.py index 4408864c4..4644babde 100644 --- a/bioblend/toolshed/__init__.py +++ b/bioblend/toolshed/__init__.py @@ -21,6 +21,7 @@ def __init__( password: Optional[str] = None, *, verify: bool = True, + user_agent: Optional[str] = None, ) -> None: """ A base representation of a connection to a ToolShed instance, identified @@ -61,7 +62,7 @@ def __init__( :param verify: Whether to verify the server's TLS certificate :type verify: bool """ - super().__init__(url, key=key, email=email, password=password, verify=verify) + super().__init__(url, key=key, email=email, password=password, verify=verify, user_agent=user_agent) self.categories = categories.ToolShedCategoryClient(self) self.repositories = repositories.ToolShedRepositoryClient(self) self.tools = tools.ToolShedToolClient(self)