|
19 | 19 | import ssl
|
20 | 20 |
|
21 | 21 | import certifi
|
| 22 | + |
22 | 23 | # python 2 and python 3 compatibility library
|
23 | 24 | import six
|
24 |
| -from six.moves.urllib.parse import urlencode |
25 | 25 | import urllib3
|
| 26 | +from requests.utils import should_bypass_proxies |
| 27 | +from six.moves.urllib.parse import urlencode |
26 | 28 |
|
27 | 29 | from kubernetes.client.exceptions import ApiException, ApiValueError
|
28 |
| -from requests.utils import should_bypass_proxies |
| 30 | + |
| 31 | +try: |
| 32 | + from urllib3.contrib.socks import SOCKSProxyManager |
| 33 | +except ImportError: |
| 34 | + |
| 35 | + def SOCKSProxyManager(*args, **kwargs): |
| 36 | + raise InvalidSchema("Missing dependencies for SOCKS support.") |
29 | 37 |
|
30 | 38 |
|
31 | 39 | logger = logging.getLogger(__name__)
|
@@ -85,17 +93,29 @@ def __init__(self, configuration, pools_size=4, maxsize=None):
|
85 | 93 |
|
86 | 94 | # https pool manager
|
87 | 95 | if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
88 |
| - self.pool_manager = urllib3.ProxyManager( |
89 |
| - num_pools=pools_size, |
90 |
| - maxsize=maxsize, |
91 |
| - cert_reqs=cert_reqs, |
92 |
| - ca_certs=ca_certs, |
93 |
| - cert_file=configuration.cert_file, |
94 |
| - key_file=configuration.key_file, |
95 |
| - proxy_url=configuration.proxy, |
96 |
| - proxy_headers=configuration.proxy_headers, |
97 |
| - **addition_pool_args |
98 |
| - ) |
| 96 | + if configuration.proxy.lower().startswith("socks"): |
| 97 | + self.pool_manager = SOCKSProxyManager( |
| 98 | + num_pools=pools_size, |
| 99 | + maxsize=maxsize, |
| 100 | + cert_reqs=cert_reqs, |
| 101 | + ca_certs=ca_certs, |
| 102 | + cert_file=configuration.cert_file, |
| 103 | + key_file=configuration.key_file, |
| 104 | + proxy_url=configuration.proxy, |
| 105 | + **addition_pool_args |
| 106 | + ) |
| 107 | + else: |
| 108 | + self.pool_manager = urllib3.ProxyManager( |
| 109 | + num_pools=pools_size, |
| 110 | + maxsize=maxsize, |
| 111 | + cert_reqs=cert_reqs, |
| 112 | + ca_certs=ca_certs, |
| 113 | + cert_file=configuration.cert_file, |
| 114 | + key_file=configuration.key_file, |
| 115 | + proxy_url=configuration.proxy, |
| 116 | + proxy_headers=configuration.proxy_headers, |
| 117 | + **addition_pool_args |
| 118 | + ) |
99 | 119 | else:
|
100 | 120 | self.pool_manager = urllib3.PoolManager(
|
101 | 121 | num_pools=pools_size,
|
|
0 commit comments