Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type annotations for helpers #989

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DIFF_BRANCH=origin/master
FORMATTED_AREAS=\
aiokafka/codec.py \
aiokafka/errors.py \
aiokafka/helpers.py \
aiokafka/structs.py \
aiokafka/util.py \
tests/test_codec.py
Expand Down
2 changes: 2 additions & 0 deletions aiokafka/consumer/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ async def commit(self, offsets=None):
Will now raise :exc:`~aiokafka.errors.CommitFailedError` in case
membership changed, as (possibly) this partition is handled by
another consumer.

.. _kafka-python: https://github.com/dpkp/kafka-python
"""
if self._group_id is None:
raise IllegalOperation("Requires group_id")
Expand Down
28 changes: 16 additions & 12 deletions aiokafka/helpers.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
"""
.. _kafka-python: https://github.com/dpkp/kafka-python
"""
from __future__ import annotations

import logging
from ssl import Purpose, create_default_context
from os import PathLike
from ssl import Purpose, SSLContext, create_default_context
from typing import Callable, Union

from typing_extensions import Buffer

log = logging.getLogger(__name__)


def create_ssl_context(
*,
cafile=None,
capath=None,
cadata=None,
certfile=None,
keyfile=None,
password=None,
crlfile=None,
):
cafile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
capath: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
cadata: Union[str, Buffer, None] = None,
certfile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
keyfile: Union[str, bytes, PathLike[str], PathLike[bytes], None] = None,
password: Union[
Callable[[], Union[str, bytes, bytearray]], str, bytes, bytearray, None
] = None,
) -> SSLContext:
"""
Simple helper, that creates an :class:`~ssl.SSLContext` based on params similar to
those in `kafka-python`_, but with some restrictions like:
Expand Down Expand Up @@ -54,6 +57,7 @@
:meth:`~ssl.SSLContext.load_cert_chain`.
Default: :data:`None`.

.. _kafka-python: https://github.com/dpkp/kafka-python
"""
if cafile or capath:
log.info("Loading SSL CA from %s", cafile or capath)
Expand All @@ -66,7 +70,7 @@
)
# Load certificate if one is specified.
if certfile is not None:
log.info("Loading SSL Cert from %s", certfile)

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (certificate)
as clear text.
This expression logs
sensitive data (certificate)
as clear text.
This expression logs
sensitive data (certificate)
as clear text.
if keyfile:
if password is not None:
log.info("Loading SSL Key from %s with password", keyfile)
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_version(release):

# General information about the project.
project = 'aiokafka'
copyright = '2015-2017, Aio-libs contributors'
copyright = '2015-2024, Aio-libs contributors'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -119,6 +119,7 @@ def get_version(release):
("py:class", "KT"),
("py:class", "Optional[~ VT]"),
("py:class", "VT"),
("py:class", "typing_extensions.Buffer"),
]

# If true, '()' will be appended to :func: etc. cross-reference text.
Expand Down
Loading