From 31b5d353c194537a1e3bbd0a8aa876c16bd27dd0 Mon Sep 17 00:00:00 2001 From: Jonathan Ballet Date: Tue, 22 Aug 2023 22:28:19 +0200 Subject: [PATCH] [python] Allow clients to define TLS Server name (SNI) (aiohttp) This configures the same as in #15283 but for the aiohttp backend. --- .../src/main/resources/python/asyncio/rest.mustache | 5 +++++ .../client/petstore/python-aiohttp/petstore_api/rest.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache index 98c811e513e0..0949c1d4aee4 100644 --- a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache @@ -47,6 +47,8 @@ class RESTClientObject(object): configuration.cert_file, keyfile=configuration.key_file ) + self.server_hostname = configuration.tls_server_name + if not configuration.verify_ssl: ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE @@ -122,6 +124,9 @@ class RESTClientObject(object): if query_params: args["url"] += '?' + urlencode(query_params) + if self.server_hostname: + args["server_hostname"] = self.server_hostname + # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if re.search('json', headers['Content-Type'], re.IGNORECASE): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py index d5c9ade5621e..d973f63122da 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py @@ -57,6 +57,8 @@ def __init__(self, configuration, pools_size=4, maxsize=None): configuration.cert_file, keyfile=configuration.key_file ) + self.server_hostname = configuration.tls_server_name + if not configuration.verify_ssl: ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE @@ -132,6 +134,9 @@ async def request(self, method, url, query_params=None, headers=None, if query_params: args["url"] += '?' + urlencode(query_params) + if self.server_hostname: + args["server_hostname"] = self.server_hostname + # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if re.search('json', headers['Content-Type'], re.IGNORECASE):