forked from loafle/openapi-generator-original
[Python] Add ca_cert_data
parameter (#20697)
* Add `ca_cert_data` parameter to Python client. This lets a client validate a server's CA certificate chain using a variable/constant containing PEM (`str`) or DER (`bytes`) data, rather than needing to reference a file on disk. * python: Fix `ca_cert_data` on Python 3.8
This commit is contained in:
parent
5757def39b
commit
30787a16fb
@ -47,7 +47,8 @@ class RESTClientObject:
|
|||||||
self.maxsize = configuration.connection_pool_maxsize
|
self.maxsize = configuration.connection_pool_maxsize
|
||||||
|
|
||||||
self.ssl_context = ssl.create_default_context(
|
self.ssl_context = ssl.create_default_context(
|
||||||
cafile=configuration.ssl_ca_cert
|
cafile=configuration.ssl_ca_cert,
|
||||||
|
cadata=configuration.ca_cert_data,
|
||||||
)
|
)
|
||||||
if configuration.cert_file:
|
if configuration.cert_file:
|
||||||
self.ssl_context.load_cert_chain(
|
self.ssl_context.load_cert_chain(
|
||||||
|
@ -10,7 +10,7 @@ from logging import FileHandler
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
{{/asyncio}}
|
{{/asyncio}}
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -183,6 +183,8 @@ class Configuration:
|
|||||||
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
in PEM format.
|
in PEM format.
|
||||||
:param retries: Number of retries for API requests.
|
:param retries: Number of retries for API requests.
|
||||||
|
:param ca_cert_data: verify the peer using concatenated CA certificate data
|
||||||
|
in PEM (str) or DER (bytes) format.
|
||||||
|
|
||||||
{{#hasAuthMethods}}
|
{{#hasAuthMethods}}
|
||||||
:Example:
|
:Example:
|
||||||
@ -289,6 +291,7 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
ignore_operation_servers: bool=False,
|
ignore_operation_servers: bool=False,
|
||||||
ssl_ca_cert: Optional[str]=None,
|
ssl_ca_cert: Optional[str]=None,
|
||||||
retries: Optional[int] = None,
|
retries: Optional[int] = None,
|
||||||
|
ca_cert_data: Optional[Union[str, bytes]] = None,
|
||||||
*,
|
*,
|
||||||
debug: Optional[bool] = None,
|
debug: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -373,6 +376,10 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
self.ssl_ca_cert = ssl_ca_cert
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
"""Set this to customize the certificate file to verify the peer.
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
"""
|
"""
|
||||||
|
self.ca_cert_data = ca_cert_data
|
||||||
|
"""Set this to verify the peer using PEM (str) or DER (bytes)
|
||||||
|
certificate data.
|
||||||
|
"""
|
||||||
self.cert_file = None
|
self.cert_file = None
|
||||||
"""client certificate file
|
"""client certificate file
|
||||||
"""
|
"""
|
||||||
|
@ -66,6 +66,7 @@ class RESTClientObject:
|
|||||||
"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,
|
||||||
|
"ca_cert_data": configuration.ca_cert_data,
|
||||||
}
|
}
|
||||||
if configuration.assert_hostname is not None:
|
if configuration.assert_hostname is not None:
|
||||||
pool_args['assert_hostname'] = (
|
pool_args['assert_hostname'] = (
|
||||||
|
@ -19,7 +19,7 @@ import logging
|
|||||||
from logging import FileHandler
|
from logging import FileHandler
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -163,6 +163,8 @@ class Configuration:
|
|||||||
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
in PEM format.
|
in PEM format.
|
||||||
:param retries: Number of retries for API requests.
|
:param retries: Number of retries for API requests.
|
||||||
|
:param ca_cert_data: verify the peer using concatenated CA certificate data
|
||||||
|
in PEM (str) or DER (bytes) format.
|
||||||
|
|
||||||
:Example:
|
:Example:
|
||||||
|
|
||||||
@ -200,6 +202,7 @@ conf = openapi_client.Configuration(
|
|||||||
ignore_operation_servers: bool=False,
|
ignore_operation_servers: bool=False,
|
||||||
ssl_ca_cert: Optional[str]=None,
|
ssl_ca_cert: Optional[str]=None,
|
||||||
retries: Optional[int] = None,
|
retries: Optional[int] = None,
|
||||||
|
ca_cert_data: Optional[Union[str, bytes]] = None,
|
||||||
*,
|
*,
|
||||||
debug: Optional[bool] = None,
|
debug: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -277,6 +280,10 @@ conf = openapi_client.Configuration(
|
|||||||
self.ssl_ca_cert = ssl_ca_cert
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
"""Set this to customize the certificate file to verify the peer.
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
"""
|
"""
|
||||||
|
self.ca_cert_data = ca_cert_data
|
||||||
|
"""Set this to verify the peer using PEM (str) or DER (bytes)
|
||||||
|
certificate data.
|
||||||
|
"""
|
||||||
self.cert_file = None
|
self.cert_file = None
|
||||||
"""client certificate file
|
"""client certificate file
|
||||||
"""
|
"""
|
||||||
|
@ -77,6 +77,7 @@ class RESTClientObject:
|
|||||||
"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,
|
||||||
|
"ca_cert_data": configuration.ca_cert_data,
|
||||||
}
|
}
|
||||||
if configuration.assert_hostname is not None:
|
if configuration.assert_hostname is not None:
|
||||||
pool_args['assert_hostname'] = (
|
pool_args['assert_hostname'] = (
|
||||||
|
@ -19,7 +19,7 @@ import logging
|
|||||||
from logging import FileHandler
|
from logging import FileHandler
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -163,6 +163,8 @@ class Configuration:
|
|||||||
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
in PEM format.
|
in PEM format.
|
||||||
:param retries: Number of retries for API requests.
|
:param retries: Number of retries for API requests.
|
||||||
|
:param ca_cert_data: verify the peer using concatenated CA certificate data
|
||||||
|
in PEM (str) or DER (bytes) format.
|
||||||
|
|
||||||
:Example:
|
:Example:
|
||||||
|
|
||||||
@ -200,6 +202,7 @@ conf = openapi_client.Configuration(
|
|||||||
ignore_operation_servers: bool=False,
|
ignore_operation_servers: bool=False,
|
||||||
ssl_ca_cert: Optional[str]=None,
|
ssl_ca_cert: Optional[str]=None,
|
||||||
retries: Optional[int] = None,
|
retries: Optional[int] = None,
|
||||||
|
ca_cert_data: Optional[Union[str, bytes]] = None,
|
||||||
*,
|
*,
|
||||||
debug: Optional[bool] = None,
|
debug: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -277,6 +280,10 @@ conf = openapi_client.Configuration(
|
|||||||
self.ssl_ca_cert = ssl_ca_cert
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
"""Set this to customize the certificate file to verify the peer.
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
"""
|
"""
|
||||||
|
self.ca_cert_data = ca_cert_data
|
||||||
|
"""Set this to verify the peer using PEM (str) or DER (bytes)
|
||||||
|
certificate data.
|
||||||
|
"""
|
||||||
self.cert_file = None
|
self.cert_file = None
|
||||||
"""client certificate file
|
"""client certificate file
|
||||||
"""
|
"""
|
||||||
|
@ -77,6 +77,7 @@ class RESTClientObject:
|
|||||||
"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,
|
||||||
|
"ca_cert_data": configuration.ca_cert_data,
|
||||||
}
|
}
|
||||||
if configuration.assert_hostname is not None:
|
if configuration.assert_hostname is not None:
|
||||||
pool_args['assert_hostname'] = (
|
pool_args['assert_hostname'] = (
|
||||||
|
@ -17,7 +17,7 @@ import http.client as httplib
|
|||||||
import logging
|
import logging
|
||||||
from logging import FileHandler
|
from logging import FileHandler
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -168,6 +168,8 @@ class Configuration:
|
|||||||
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
in PEM format.
|
in PEM format.
|
||||||
:param retries: Number of retries for API requests.
|
:param retries: Number of retries for API requests.
|
||||||
|
:param ca_cert_data: verify the peer using concatenated CA certificate data
|
||||||
|
in PEM (str) or DER (bytes) format.
|
||||||
|
|
||||||
:Example:
|
:Example:
|
||||||
|
|
||||||
@ -264,6 +266,7 @@ conf = petstore_api.Configuration(
|
|||||||
ignore_operation_servers: bool=False,
|
ignore_operation_servers: bool=False,
|
||||||
ssl_ca_cert: Optional[str]=None,
|
ssl_ca_cert: Optional[str]=None,
|
||||||
retries: Optional[int] = None,
|
retries: Optional[int] = None,
|
||||||
|
ca_cert_data: Optional[Union[str, bytes]] = None,
|
||||||
*,
|
*,
|
||||||
debug: Optional[bool] = None,
|
debug: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -346,6 +349,10 @@ conf = petstore_api.Configuration(
|
|||||||
self.ssl_ca_cert = ssl_ca_cert
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
"""Set this to customize the certificate file to verify the peer.
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
"""
|
"""
|
||||||
|
self.ca_cert_data = ca_cert_data
|
||||||
|
"""Set this to verify the peer using PEM (str) or DER (bytes)
|
||||||
|
certificate data.
|
||||||
|
"""
|
||||||
self.cert_file = None
|
self.cert_file = None
|
||||||
"""client certificate file
|
"""client certificate file
|
||||||
"""
|
"""
|
||||||
|
@ -57,7 +57,8 @@ class RESTClientObject:
|
|||||||
self.maxsize = configuration.connection_pool_maxsize
|
self.maxsize = configuration.connection_pool_maxsize
|
||||||
|
|
||||||
self.ssl_context = ssl.create_default_context(
|
self.ssl_context = ssl.create_default_context(
|
||||||
cafile=configuration.ssl_ca_cert
|
cafile=configuration.ssl_ca_cert,
|
||||||
|
cadata=configuration.ca_cert_data,
|
||||||
)
|
)
|
||||||
if configuration.cert_file:
|
if configuration.cert_file:
|
||||||
self.ssl_context.load_cert_chain(
|
self.ssl_context.load_cert_chain(
|
||||||
|
@ -18,7 +18,7 @@ import logging
|
|||||||
from logging import FileHandler
|
from logging import FileHandler
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
|
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
|
||||||
from typing_extensions import NotRequired, Self
|
from typing_extensions import NotRequired, Self
|
||||||
|
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -169,6 +169,8 @@ class Configuration:
|
|||||||
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
||||||
in PEM format.
|
in PEM format.
|
||||||
:param retries: Number of retries for API requests.
|
:param retries: Number of retries for API requests.
|
||||||
|
:param ca_cert_data: verify the peer using concatenated CA certificate data
|
||||||
|
in PEM (str) or DER (bytes) format.
|
||||||
|
|
||||||
:Example:
|
:Example:
|
||||||
|
|
||||||
@ -265,6 +267,7 @@ conf = petstore_api.Configuration(
|
|||||||
ignore_operation_servers: bool=False,
|
ignore_operation_servers: bool=False,
|
||||||
ssl_ca_cert: Optional[str]=None,
|
ssl_ca_cert: Optional[str]=None,
|
||||||
retries: Optional[int] = None,
|
retries: Optional[int] = None,
|
||||||
|
ca_cert_data: Optional[Union[str, bytes]] = None,
|
||||||
*,
|
*,
|
||||||
debug: Optional[bool] = None,
|
debug: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -347,6 +350,10 @@ conf = petstore_api.Configuration(
|
|||||||
self.ssl_ca_cert = ssl_ca_cert
|
self.ssl_ca_cert = ssl_ca_cert
|
||||||
"""Set this to customize the certificate file to verify the peer.
|
"""Set this to customize the certificate file to verify the peer.
|
||||||
"""
|
"""
|
||||||
|
self.ca_cert_data = ca_cert_data
|
||||||
|
"""Set this to verify the peer using PEM (str) or DER (bytes)
|
||||||
|
certificate data.
|
||||||
|
"""
|
||||||
self.cert_file = None
|
self.cert_file = None
|
||||||
"""client certificate file
|
"""client certificate file
|
||||||
"""
|
"""
|
||||||
|
@ -76,6 +76,7 @@ class RESTClientObject:
|
|||||||
"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,
|
||||||
|
"ca_cert_data": configuration.ca_cert_data,
|
||||||
}
|
}
|
||||||
if configuration.assert_hostname is not None:
|
if configuration.assert_hostname is not None:
|
||||||
pool_args['assert_hostname'] = (
|
pool_args['assert_hostname'] = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user