Skip to content

APIKeyHeader

fastagency.api.openapi.security.APIKeyHeader #

Bases: BaseSecurity

API Key Header security class.

in_value class-attribute #

in_value: Literal['header'] = 'header'

name instance-attribute #

name: str

type class-attribute #

type: Literal['apiKey'] = 'apiKey'

Parameters #

Bases: BaseModel

API Key Header security parameters class.

value instance-attribute #

value: str

apply #

apply(
    q_params: dict[str, Any],
    body_dict: dict[str, Any],
    security: BaseSecurity,
) -> None
Source code in fastagency/api/openapi/security.py
def apply(
    self,
    q_params: dict[str, Any],
    body_dict: dict[str, Any],
    security: BaseSecurity,
) -> None:
    api_key_header: APIKeyHeader = security  # type: ignore[assignment]

    if "headers" not in body_dict:
        body_dict["headers"] = {}

    body_dict["headers"][api_key_header.name] = self.value

get_security_class #

get_security_class() -> type[BaseSecurity]
Source code in fastagency/api/openapi/security.py
def get_security_class(self) -> type[BaseSecurity]:
    return APIKeyHeader

accept #

accept(security_params: BaseSecurityParameters) -> bool
Source code in fastagency/api/openapi/security.py
def accept(self, security_params: "BaseSecurityParameters") -> bool:
    return isinstance(self, security_params.get_security_class())

get_security_class classmethod #

get_security_class(
    type: str, schema_parameters: dict[str, Any]
) -> BaseSecurityType
Source code in fastagency/api/openapi/security.py
@classmethod
def get_security_class(
    cls, type: str, schema_parameters: dict[str, Any]
) -> BaseSecurityType:
    sub_classes = cls.__subclasses__()

    for sub_class in sub_classes:
        if sub_class.is_supported(type, schema_parameters):
            return sub_class

    logger.error(
        f"Unsupported type '{type}' and schema_parameters '{schema_parameters}' combination"
    )
    return UnsuportedSecurityStub

get_security_parameters classmethod #

get_security_parameters(
    schema_parameters: dict[str, Any]
) -> str
Source code in fastagency/api/openapi/security.py
@classmethod
def get_security_parameters(cls, schema_parameters: dict[str, Any]) -> str:
    return f"{cls.__name__}(name=\"{schema_parameters.get('name')}\")"

is_supported classmethod #

is_supported(
    type: str, schema_parameters: dict[str, Any]
) -> bool
Source code in fastagency/api/openapi/security.py
@classmethod
def is_supported(cls, type: str, schema_parameters: dict[str, Any]) -> bool:
    return cls.type == type and cls.in_value == schema_parameters.get("in")