From 0c852d26ec32e7dedda28d260290023ea98f3b7e Mon Sep 17 00:00:00 2001 From: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com> Date: Fri, 19 May 2023 17:00:37 -0400 Subject: [PATCH] duo: add proxy config (#1179) Add the ability to set the duo client's proxy configuration from the standard `HTTP_PROXY` environment variable, if set. --- cartography/intel/duo/__init__.py | 19 ++++++++++++++++++- setup.py | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cartography/intel/duo/__init__.py b/cartography/intel/duo/__init__.py index 4b63d7a8cd..bd2f9644a8 100644 --- a/cartography/intel/duo/__init__.py +++ b/cartography/intel/duo/__init__.py @@ -1,4 +1,7 @@ import logging +import os +from base64 import b64encode +from urllib.parse import urlparse import duo_client import neo4j @@ -22,11 +25,25 @@ def get_client(config: Config) -> duo_client.Admin: ''' Return a duo Admin client with the creds in the config object ''' - return duo_client.Admin( + client = duo_client.Admin( ikey=config.duo_api_key, skey=config.duo_api_secret, host=config.duo_api_hostname, ) + # Duo's library does not automatically respect the HTTP_PROXY env variable + proxy_url = os.environ.get('HTTP_PROXY') + if proxy_url: + proxy_config = urlparse(proxy_url) + headers = {} + if proxy_config.username: + proxy_auth_token = b64encode(f"{proxy_config.username}:{proxy_config.password}".encode()).decode('ascii') + headers['Proxy-Authorization'] = f'Basic {proxy_auth_token}' + client.set_proxy( + host=proxy_config.hostname, + port=proxy_config.port, + headers=headers, + ) + return client @timeit diff --git a/setup.py b/setup.py index ef6bda3d9c..62846a3c65 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import find_packages from setuptools import setup -__version__ = '0.79.1' +__version__ = '0.79.2' setup(