forked from loafle/openapi-generator-original
Add socks5 proxy support for OpenAPI generated python client (#16918)
* add socks5 proxy support (requires additional import) * updated examples * build samples. updated to support pydantic python option * rename sock to socks for correct protocol name * add proxy headers for pydantic * fixed param changes from conflict resolution
This commit is contained in:
parent
2c25443260
commit
2ca958642b
@ -16,6 +16,18 @@ from {{packageName}}.exceptions import ApiException, UnauthorizedException, Forb
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
@ -71,17 +83,29 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
num_pools=pools_size,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
maxsize=maxsize,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
cert_file=configuration.cert_file,
|
cert_file=configuration.cert_file,
|
||||||
key_file=configuration.key_file,
|
key_file=configuration.key_file,
|
||||||
proxy_url=configuration.proxy,
|
proxy_url=configuration.proxy,
|
||||||
proxy_headers=configuration.proxy_headers,
|
headers=configuration.proxy_headers,
|
||||||
**addition_pool_args
|
**addition_pool_args
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
num_pools=pools_size,
|
||||||
|
maxsize=maxsize,
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
|
@ -11,8 +11,20 @@ import urllib3
|
|||||||
|
|
||||||
from {{packageName}}.exceptions import ApiException, ApiValueError
|
from {{packageName}}.exceptions import ApiException, ApiValueError
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
RESTResponseType = urllib3.HTTPResponse
|
RESTResponseType = urllib3.HTTPResponse
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
def __init__(self, resp) -> None:
|
def __init__(self, resp) -> None:
|
||||||
@ -67,15 +79,27 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
cert_reqs=cert_reqs,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_file=configuration.cert_file,
|
cert_reqs=cert_reqs,
|
||||||
key_file=configuration.key_file,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
proxy_url=configuration.proxy,
|
cert_file=configuration.cert_file,
|
||||||
proxy_headers=configuration.proxy_headers,
|
key_file=configuration.key_file,
|
||||||
**addition_pool_args
|
proxy_url=configuration.proxy,
|
||||||
)
|
headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
|
@ -22,8 +22,20 @@ import urllib3
|
|||||||
|
|
||||||
from openapi_client.exceptions import ApiException, ApiValueError
|
from openapi_client.exceptions import ApiException, ApiValueError
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
RESTResponseType = urllib3.HTTPResponse
|
RESTResponseType = urllib3.HTTPResponse
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
def __init__(self, resp) -> None:
|
def __init__(self, resp) -> None:
|
||||||
@ -78,15 +90,27 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
cert_reqs=cert_reqs,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_file=configuration.cert_file,
|
cert_reqs=cert_reqs,
|
||||||
key_file=configuration.key_file,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
proxy_url=configuration.proxy,
|
cert_file=configuration.cert_file,
|
||||||
proxy_headers=configuration.proxy_headers,
|
key_file=configuration.key_file,
|
||||||
**addition_pool_args
|
proxy_url=configuration.proxy,
|
||||||
)
|
headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
|
@ -27,6 +27,18 @@ from openapi_client.exceptions import ApiException, UnauthorizedException, Forbi
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
@ -82,17 +94,29 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
num_pools=pools_size,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
maxsize=maxsize,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
cert_file=configuration.cert_file,
|
cert_file=configuration.cert_file,
|
||||||
key_file=configuration.key_file,
|
key_file=configuration.key_file,
|
||||||
proxy_url=configuration.proxy,
|
proxy_url=configuration.proxy,
|
||||||
proxy_headers=configuration.proxy_headers,
|
headers=configuration.proxy_headers,
|
||||||
**addition_pool_args
|
**addition_pool_args
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
num_pools=pools_size,
|
||||||
|
maxsize=maxsize,
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
|
@ -22,8 +22,20 @@ import urllib3
|
|||||||
|
|
||||||
from openapi_client.exceptions import ApiException, ApiValueError
|
from openapi_client.exceptions import ApiException, ApiValueError
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
RESTResponseType = urllib3.HTTPResponse
|
RESTResponseType = urllib3.HTTPResponse
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
def __init__(self, resp) -> None:
|
def __init__(self, resp) -> None:
|
||||||
@ -78,15 +90,27 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
cert_reqs=cert_reqs,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_file=configuration.cert_file,
|
cert_reqs=cert_reqs,
|
||||||
key_file=configuration.key_file,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
proxy_url=configuration.proxy,
|
cert_file=configuration.cert_file,
|
||||||
proxy_headers=configuration.proxy_headers,
|
key_file=configuration.key_file,
|
||||||
**addition_pool_args
|
proxy_url=configuration.proxy,
|
||||||
)
|
headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
|
@ -26,6 +26,18 @@ from petstore_api.exceptions import ApiException, UnauthorizedException, Forbidd
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
@ -81,17 +93,29 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
num_pools=pools_size,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
maxsize=maxsize,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
cert_file=configuration.cert_file,
|
cert_file=configuration.cert_file,
|
||||||
key_file=configuration.key_file,
|
key_file=configuration.key_file,
|
||||||
proxy_url=configuration.proxy,
|
proxy_url=configuration.proxy,
|
||||||
proxy_headers=configuration.proxy_headers,
|
headers=configuration.proxy_headers,
|
||||||
**addition_pool_args
|
**addition_pool_args
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
num_pools=pools_size,
|
||||||
|
maxsize=maxsize,
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
|
@ -21,8 +21,20 @@ import urllib3
|
|||||||
|
|
||||||
from petstore_api.exceptions import ApiException, ApiValueError
|
from petstore_api.exceptions import ApiException, ApiValueError
|
||||||
|
|
||||||
|
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||||
RESTResponseType = urllib3.HTTPResponse
|
RESTResponseType = urllib3.HTTPResponse
|
||||||
|
|
||||||
|
|
||||||
|
def is_socks_proxy_url(url):
|
||||||
|
if url is None:
|
||||||
|
return False
|
||||||
|
split_section = url.split("://")
|
||||||
|
if len(split_section) < 2:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||||
|
|
||||||
|
|
||||||
class RESTResponse(io.IOBase):
|
class RESTResponse(io.IOBase):
|
||||||
|
|
||||||
def __init__(self, resp) -> None:
|
def __init__(self, resp) -> None:
|
||||||
@ -77,15 +89,27 @@ class RESTClientObject:
|
|||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy:
|
if configuration.proxy:
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
if is_socks_proxy_url(configuration.proxy):
|
||||||
cert_reqs=cert_reqs,
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
ca_certs=configuration.ssl_ca_cert,
|
self.pool_manager = SOCKSProxyManager(
|
||||||
cert_file=configuration.cert_file,
|
cert_reqs=cert_reqs,
|
||||||
key_file=configuration.key_file,
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
proxy_url=configuration.proxy,
|
cert_file=configuration.cert_file,
|
||||||
proxy_headers=configuration.proxy_headers,
|
key_file=configuration.key_file,
|
||||||
**addition_pool_args
|
proxy_url=configuration.proxy,
|
||||||
)
|
headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
|
cert_reqs=cert_reqs,
|
||||||
|
ca_certs=configuration.ssl_ca_cert,
|
||||||
|
cert_file=configuration.cert_file,
|
||||||
|
key_file=configuration.key_file,
|
||||||
|
proxy_url=configuration.proxy,
|
||||||
|
proxy_headers=configuration.proxy_headers,
|
||||||
|
**addition_pool_args
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user