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 committed Jan 29, 2020
1 parent 8f61859 commit 2920de8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bioblend/galaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class GalaxyInstance(GalaxyClient):
def __init__(self, url, key=None, email=None, password=None, verify=True):
def __init__(self, url, key=None, email=None, password=None, verify=True, user_agent=None):
"""
A base representation of a connection to a Galaxy instance, identified
by the server URL and user credentials.
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(self, url, key=None, email=None, password=None, verify=True):
:param verify: Whether to verify the server's TLS certificate
:type verify: bool
"""
super().__init__(url, key, email, password, verify=verify)
super().__init__(url, key, email, password, verify=verify, user_agent=user_agent)
self.libraries = libraries.LibraryClient(self)
self.histories = histories.HistoryClient(self)
self.workflows = workflows.WorkflowClient(self)
Expand Down
10 changes: 9 additions & 1 deletion bioblend/galaxyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class GalaxyClient(object):

def __init__(self, url, key=None, email=None, password=None, verify=True, timeout=None):
def __init__(self, url, key=None, email=None, password=None, verify=True, timeout=None, user_agent=None):
"""
:param verify: Whether to verify the server's TLS certificate
:type verify: bool
Expand All @@ -42,7 +42,12 @@ def __init__(self, url, key=None, email=None, password=None, verify=True, timeou
self._key = None
self.email = email
self.password = password
self.user_agent = user_agent
self.json_headers = {'Content-Type': 'application/json'}
self.non_json_headers = {}
if self.user_agent:
self.json_headers['User-Agent'] = self.user_agent
self.non_json_headers = {'User-Agent': self.user_agent}
self.verify = verify
self.timeout = timeout

Expand Down Expand Up @@ -70,6 +75,9 @@ def make_get_request(self, url, **kwargs):
kwargs['params'] = params
kwargs.setdefault('verify', self.verify)
kwargs.setdefault('timeout', self.timeout)
if self.non_json_headers:
kwargs.setdefault('headers', {})
kwargs['headers'].update(self.non_json_headers)
r = requests.get(url, **kwargs)
return r

Expand Down
4 changes: 2 additions & 2 deletions bioblend/toolshed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class ToolShedInstance(GalaxyClient):
def __init__(self, url, key=None, email=None, password=None, verify=True):
def __init__(self, url, key=None, email=None, password=None, verify=True, user_agent=None):
"""
A base representation of a connection to a ToolShed instance, identified
by the ToolShed URL and user credentials.
Expand Down Expand Up @@ -46,7 +46,7 @@ def __init__(self, url, key=None, email=None, password=None, verify=True):
:param verify: Whether to verify the server's TLS certificate
:type verify: bool
"""
super().__init__(url, key, email, password, verify=verify)
super().__init__(url, key, email, 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 2920de8

Please sign in to comment.