Skip to content

Commit

Permalink
duo: add proxy config (#1179)
Browse files Browse the repository at this point in the history
Add the ability to set the duo client's proxy configuration from the
standard `HTTP_PROXY` environment variable, if set.
  • Loading branch information
ramonpetgrave64 authored May 19, 2023
1 parent 8655fea commit 0c852d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion cartography/intel/duo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging
import os
from base64 import b64encode
from urllib.parse import urlparse

import duo_client
import neo4j
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import find_packages
from setuptools import setup

__version__ = '0.79.1'
__version__ = '0.79.2'


setup(
Expand Down

0 comments on commit 0c852d2

Please sign in to comment.