Skip to content

BaseSecurity

faststream.security.BaseSecurity #

BaseSecurity(
    ssl_context: Optional[SSLContext] = None,
    use_ssl: Optional[bool] = None,
)

Base class for defining security configurations.

This class provides a base for defining security configurations for communication with a broker. It allows setting SSL encryption and provides methods to retrieve security requirements and schemas.

PARAMETER DESCRIPTION
ssl_context

An SSLContext object for SSL encryption. If None, SSL encryption is disabled.

TYPE: Optional[SSLContext] DEFAULT: None

use_ssl

A boolean indicating whether to use SSL encryption. Defaults to True.

TYPE: Optional[bool] DEFAULT: None

METHOD DESCRIPTION
get_requirement

Get the security requirements in the form of a list of dictionaries.

get_schema

Get the security schema as a dictionary.

Source code in faststream/security.py
def __init__(
    self,
    ssl_context: Optional[SSLContext] = None,
    use_ssl: Optional[bool] = None,
):
    if use_ssl is None:
        use_ssl = True

    if use_ssl and ssl_context is None:
        raise RuntimeError(ssl_not_set_error_msg)

    self.use_ssl = use_ssl
    self.ssl_context = ssl_context

ssl_context instance-attribute #

ssl_context = ssl_context

use_ssl instance-attribute #

use_ssl = use_ssl

get_requirement #

get_requirement() -> List[AnyDict]

Get the security requirements.

RETURNS DESCRIPTION
List[AnyDict]

List[AnyDict]: A list of dictionaries representing security requirements.

Source code in faststream/security.py
def get_requirement(self) -> List[AnyDict]:
    """
    Get the security requirements.

    Returns:
        List[AnyDict]: A list of dictionaries representing security requirements.
    """
    return []

get_schema #

get_schema() -> Dict[str, Dict[str, str]]

Get the security schema.

RETURNS DESCRIPTION
Dict[str, Dict[str, str]]

Dict[str, Dict[str, str]]: A dictionary representing the security schema.

Source code in faststream/security.py
def get_schema(self) -> Dict[str, Dict[str, str]]:
    """
    Get the security schema.

    Returns:
        Dict[str, Dict[str, str]]: A dictionary representing the security schema.
    """
    return {}

Last update: 2023-11-13