diff --git a/did/plugins/github.py b/did/plugins/github.py index e10cb8a8..d6ce16f8 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -41,6 +41,10 @@ timeout = 10 +Use ``proxy`` to configure the proxy. See the `Proxies`__ documentation +for the format of proxy url. + +__ https://requests.readthedocs.io/en/latest/user/advanced/#proxies """ # noqa: W505,E501 # pylint:disable=line-too-long import json @@ -75,10 +79,11 @@ class GitHub(): # pylint: disable=too-few-public-methods def __init__(self, *, url, token=None, user=None, - org=None, repo=None, exclude_org=None, timeout=TIMEOUT): + org=None, repo=None, exclude_org=None, timeout=TIMEOUT, proxy=None): """ Initialize url and headers """ self.url = url.rstrip("/") self.timeout = timeout + self.proxy = {"all": proxy} if token is not None: self.headers = {'Authorization': f'token {token}'} else: @@ -134,8 +139,7 @@ def request(self, url): reraise=True): with attempt: response = requests.get( - url, headers=self.headers, timeout=self.timeout - ) + url, headers=self.headers, timeout=self.timeout, proxies=self.proxy) log.debug("Response headers:\n%s", response.headers) except (requests.exceptions.RequestException, RetryError) as error: log.debug(error) @@ -377,7 +381,9 @@ def __init__(self, option, name=None, parent=None, user=None): user=config.get("user"), repo=config.get("repo"), exclude_org=config.get("exclude_org"), - timeout=config.get("timeout")) + timeout=config.get("timeout"), + proxy=config.get("proxy"), + ) # Create the list of stats self.stats = [ diff --git a/did/plugins/gitlab.py b/did/plugins/gitlab.py index a8ade232..e38ffe5a 100644 --- a/did/plugins/gitlab.py +++ b/did/plugins/gitlab.py @@ -10,6 +10,7 @@ token_file = login = ssl_verify = true + proxy = The authentication token is required. Create it in the GitLab web interface (select ``api`` as the desired scope). See the `GitLab API`__ @@ -27,6 +28,10 @@ __ https://docs.gitlab.com/ce/api/ +Use ``proxy`` to configure the proxy. See the `Proxies`__ documentation +for the format of proxy url. + +__ https://requests.readthedocs.io/en/latest/user/advanced/#proxies """ from time import sleep @@ -61,7 +66,13 @@ class GitLab(): """ GitLab Investigator """ - def __init__(self, url, token, ssl_verify=GITLAB_SSL_VERIFY, timeout=TIMEOUT): + def __init__( + self, + url, + token, + ssl_verify=GITLAB_SSL_VERIFY, + timeout=TIMEOUT, + proxy=None): """ Initialize url and headers """ self.url = url.rstrip("/") self.headers = {'PRIVATE-TOKEN': token} @@ -73,6 +84,7 @@ def __init__(self, url, token, ssl_verify=GITLAB_SSL_VERIFY, timeout=TIMEOUT): self.project_mrs = {} self.project_issues = {} self.timeout = timeout + self.proxy = {"all": proxy} def _get_gitlab_api_raw(self, url): log.debug("Connecting to GitLab API at '%s'.", url) @@ -81,7 +93,7 @@ def _get_gitlab_api_raw(self, url): try: api_raw = requests.get( url, headers=self.headers, verify=self.ssl_verify, - timeout=self.timeout) + timeout=self.timeout, proxies=self.proxy) api_raw.raise_for_status() return api_raw except requests.exceptions.HTTPError as http_err: @@ -427,7 +439,11 @@ def __init__(self, option, name=None, parent=None, user=None): if not self.ssl_verify: urllib3.disable_warnings(InsecureRequestWarning) self.gitlab = GitLab( - self.url, self.token, self.ssl_verify, timeout=config.get("timeout")) + self.url, + self.token, + self.ssl_verify, + timeout=config.get("timeout"), + proxy=config.get("proxy")) # Create the list of stats self.stats = [ IssuesCreated(