From a41cd2d08f41e038396f4e92b6bdf49ffd647a3a Mon Sep 17 00:00:00 2001 From: Charlie Kim Date: Wed, 29 Nov 2023 14:10:48 -0500 Subject: [PATCH] Added socks5 proxy support --- README.md | 7 ++++++- aciClient/aci.py | 6 +++++- requirements.txt | 3 ++- setup.py | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b5bf26f..d00af46 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 135b8df..cbfcff9 100644 --- a/aciClient/aci.py +++ b/aciClient/aci.py @@ -28,11 +28,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}') @@ -60,6 +61,9 @@ def login(self) -> bool: self.session = requests.Session() 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 f7ce48b..7225029 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ pyOpenSSL>=23.0.0, <24 -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 fa54740..3d521ef 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,14 @@ long_description = f.read() setup(name='aciClient', - version='1.5', + version='1.6', description='aci communication helper class', url='http://www.netcloud.ch', author='mze', author_email='nc_dev@netcloud.ch', license='MIT', packages=['aciClient'], - install_requires=['requests>=2.26.0 , <3', 'pyOpenSSL>=23.0.0, <24'], + install_requires=['requests[socks]>=2.26.0 , <3', 'pyOpenSSL>=23.0.0, <24', 'PySocks>=1.7.1, <2'], long_description=long_description, long_description_content_type='text/markdown', python_requires=">=3.6",