diff --git a/README.md b/README.md index 27d06fd..7dc73e0 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,12 @@ import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) -aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=False) +proxies = { + 'http': 'socks5://127.0.0.1:1080', + 'https': 'socks5://127.0.0.1:1080' +} + +aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=False, proxies=proxies) try: aciclient.login() diff --git a/aciClient/aci.py b/aciClient/aci.py index 69f848b..0a74536 100644 --- a/aciClient/aci.py +++ b/aciClient/aci.py @@ -31,11 +31,12 @@ class ACI: # ============================================================================== # constructor # ============================================================================== - def __init__(self, apicIp, apicUser, apicPasword, refresh=False): + def __init__(self, apicIp, apicUser, apicPasword, refresh=False, proxies=None): self.__logger.debug('Constructor called') self.apicIp = apicIp self.apicUser = apicUser self.apicPassword = apicPasword + self.proxies = proxies self.baseUrl = 'https://' + self.apicIp + '/api/' self.__logger.debug(f'BaseUrl set to: {self.baseUrl}') @@ -75,6 +76,9 @@ def login(self) -> bool: self.session.mount('https://', adapter) self.__logger.debug('Session Object Created') + if self.proxies is not None: + self.session.proxies = self.proxies + # create credentials structure userPass = json.dumps({'aaaUser': {'attributes': {'name': self.apicUser, 'pwd': self.apicPassword}}}) diff --git a/requirements.txt b/requirements.txt index 9ae3bda..fb966c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ pyOpenSSL>=23.0.0, <26 -requests>=2.26.0 , <3 +requests[socks]>=2.26.0 , <3 requests-mock pytest flake8 +pysocks==1.7.1 diff --git a/setup.py b/setup.py index 281eaf8..b46fe63 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ author_email='nc_dev@netcloud.ch', license='MIT', packages=['aciClient'], - install_requires=['requests>=2.26.0 , <3', 'pyOpenSSL>=23.0.0, <26'], + install_requires=['requests[socks]>=2.26.0 , <3', 'pyOpenSSL>=23.0.0, <26', 'PySocks>=1.7.1, <2'], long_description=long_description, long_description_content_type='text/markdown', python_requires=">=3.6",