Skip to content

Commit

Permalink
[dogshell] enable proxy (#415)
Browse files Browse the repository at this point in the history
* [dogshell] enable proxy

* Update datadog/dogshell/common.py

Co-Authored-By: Hippolyte HENRY <zippolyte@users.noreply.github.com>
  • Loading branch information
ian28223 and zippolyte committed Aug 27, 2019
1 parent 42b578c commit d870776
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions datadog/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
"""


class ProxyError(Exception):
"""
HTTP connection to the configured proxy server failed.
"""
def __init__(self, method, url, exception):
message = u"Could not request {method} {url}: Unable to connect to proxy. "\
u"Please check the proxy configuration and try again.".format(
method=method, url=url
)
super(ProxyError, self).__init__(message)


class ClientError(Exception):
"""
HTTP connection to Datadog endpoint is not possible.
Expand Down
4 changes: 3 additions & 1 deletion datadog/api/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
urlfetch, urlfetch_errors = None, None

# datadog
from datadog.api.exceptions import ClientError, HTTPError, HttpTimeout
from datadog.api.exceptions import ProxyError, ClientError, HTTPError, HttpTimeout


log = logging.getLogger('datadog.api')
Expand Down Expand Up @@ -85,6 +85,8 @@ def request(cls, method, url, headers, params, data, timeout, proxies, verify, m

result.raise_for_status()

except requests.exceptions.ProxyError as e:
raise _remove_context(ProxyError(method, url, e))
except requests.ConnectionError as e:
raise _remove_context(ClientError(method, url, e))
except requests.exceptions.Timeout:
Expand Down
2 changes: 2 additions & 0 deletions datadog/dogshell/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def load(self, config_file, api_key, app_key):

self['api_key'] = config.get('Connection', 'apikey')
self['app_key'] = config.get('Connection', 'appkey')
if config.has_section('Proxy'):
self['proxies'] = dict(config.items('Proxy'))
if config.has_option('Connection', 'host_name'):
self['host_name'] = config.get('Connection', 'host_name')
if config.has_option('Connection', 'api_host'):
Expand Down

0 comments on commit d870776

Please sign in to comment.