|
1 | | -""" |
2 | | -.. _kafka-python: https://github.com/dpkp/kafka-python |
3 | | -""" |
| 1 | +from __future__ import annotations |
4 | 2 |
|
5 | 3 | import logging |
6 | | -from ssl import Purpose, create_default_context |
| 4 | +from os import PathLike |
| 5 | +from ssl import Purpose, SSLContext, create_default_context |
| 6 | +from typing import Callable, Union |
| 7 | + |
| 8 | +from typing_extensions import Buffer |
7 | 9 |
|
8 | 10 | log = logging.getLogger(__name__) |
9 | 11 |
|
10 | 12 |
|
11 | 13 | def create_ssl_context( |
12 | 14 | *, |
13 | | - cafile=None, |
14 | | - capath=None, |
15 | | - cadata=None, |
16 | | - certfile=None, |
17 | | - keyfile=None, |
18 | | - password=None, |
19 | | - crlfile=None, |
20 | | -): |
| 15 | + cafile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None, |
| 16 | + capath: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None, |
| 17 | + cadata: Union[str, Buffer, None] = None, |
| 18 | + certfile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None, |
| 19 | + keyfile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None, |
| 20 | + password: Union[ |
| 21 | + Callable[[], Union[str, bytes, bytearray]], str, bytes, bytearray, None |
| 22 | + ] = None, |
| 23 | +) -> SSLContext: |
21 | 24 | """ |
22 | 25 | Simple helper, that creates an :class:`~ssl.SSLContext` based on params similar to |
23 | 26 | those in `kafka-python`_, but with some restrictions like: |
@@ -54,6 +57,7 @@ def create_ssl_context( |
54 | 57 | :meth:`~ssl.SSLContext.load_cert_chain`. |
55 | 58 | Default: :data:`None`. |
56 | 59 |
|
| 60 | + .. _kafka-python: https://github.com/dpkp/kafka-python |
57 | 61 | """ |
58 | 62 | if cafile or capath: |
59 | 63 | log.info("Loading SSL CA from %s", cafile or capath) |
|
0 commit comments