from urllib3 import make_headers
from typing import Dict
[docs]
class ProxyConfig:
"""
This class is used to hold the proxy configuration details
"""
def __init__(self, address, username=None, password=None):
"""
:param str address: The address of the proxy including the port e.g. https://myproxy.com:8080
:param str username: The username for the proxy
:param str password: The password for the proxy
"""
self.address = address
self.__username = username
self.__password = password
@property
def address(self):
return self.__address
@address.setter
def address(self, address):
if "http://" not in address and "https://" not in address:
raise ValueError(
f"The provided proxy address of {address} does not contain a protocol, please specify in the full format e.g. http://myproxy.com:8080"
)
self.__address = address
@property
def username(self):
return self.__username
@property
def password(self):
return self.__password
@property
def headers(self) -> Dict[str, str]:
"""Return Proxy auth headers
Returns
-------
Any
Proxy auth headers
"""
if self.__username is not None and self.__password is not None:
return make_headers(
proxy_basic_auth=f"{self.__username}:{self.__password}"
)
else:
return {}