Skip to content

Commit

Permalink
Allow specifying the User-Agent when creating a GalaxyClient
Browse files Browse the repository at this point in the history
  • Loading branch information
blankenberg authored and nsoranzo committed Jul 4, 2024
1 parent 6bbcf77 commit 15478f4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bioblend/galaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion bioblend/galaxy/objects/galaxy_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions bioblend/galaxyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,6 +82,8 @@ def __init__(
self.email = email
self.password = password
self.json_headers: Dict[str, Union[str, bytes, None]] = {"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.
Expand Down
3 changes: 2 additions & 1 deletion bioblend/toolshed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 15478f4

Please sign in to comment.