Skip to content

Support configuring HTTP / HTTPS proxy #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pydomo/Transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class DomoAPITransport:
serialization and deserialization of objects.
"""

def __init__(self, client_id, client_secret, api_host, use_https, logger, request_timeout):
def __init__(self, client_id, client_secret, api_host, use_https, logger, request_timeout, proxies, verify):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (112 > 79 characters)

self.apiHost = self._build_apihost(api_host, use_https)
self.clientId = client_id
self.clientSecret = client_secret
self.logger = logger
self.request_timeout = request_timeout
self.proxies = proxies
self.verify = verify
self._renew_access_token()

@staticmethod
Expand Down Expand Up @@ -73,7 +75,10 @@ def request(self, url, method, headers, params=None, body=None):
'params': params, 'data': body, 'stream': True}
if self.request_timeout:
request_args['timeout'] = self.request_timeout

if self.proxies:
request_args['proxies'] = self.proxies
if self.verify is not None:
request_args['verify'] = self.verify
# Expiration date should be in UTC
if datetime.now(timezone.utc).timestamp() > self.token_expiration:
self.logger.debug("Access token is expired")
Expand All @@ -91,6 +96,10 @@ def _renew_access_token(self):
}
if self.request_timeout:
request_args['timeout'] = self.request_timeout
if self.proxies:
request_args['proxies'] = self.proxies
if self.verify is not None:
request_args['verify'] = self.verify

response = requests.request(**request_args)
if response.status_code == requests.codes.OK:
Expand Down
6 changes: 4 additions & 2 deletions pydomo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ def __init__(self, client_id, client_secret, api_host='api.domo.com', **kwargs):
self.logger = parent_logger

timeout = kwargs.get('request_timeout', None)
proxies = kwargs.get('proxies', None)
verify = kwargs.get('verify', True)

if kwargs.get('log_level'):
self.logger.setLevel(kwargs['log_level'])
self.logger.debug("\n" + DOMO + "\n")

self.transport = DomoAPITransport(client_id, client_secret, api_host, kwargs.get('use_https', True), self.logger, request_timeout = timeout)
self.transport = DomoAPITransport(client_id, client_secret, api_host, kwargs.get('use_https', True), self.logger, request_timeout = timeout, proxies = proxies, verify = verify)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (184 > 79 characters)
E251 unexpected spaces around keyword / parameter equals

self.datasets = DataSetClient(self.transport, self.logger)
self.groups = GroupClient(self.transport, self.logger)
self.pages = PageClient(self.transport, self.logger)
Expand All @@ -112,7 +114,7 @@ def ds_meta(self, dataset_id):
def ds_delete(self, dataset_id, prompt_before_delete=True):
"""
Delete a DataSet naming convention equivalent with rdomo

:Parameters:
- `dataset_id`: id of a dataset (str)
"""
Expand Down