Bases: BaseSecurity
HTTP Bearer security class.
in_value class-attribute
in_value: Literal['basic'] = 'basic'
Parameters
Bases: BaseModel
HTTP Basic security parameters class.
password instance-attribute
username instance-attribute
apply
Source code in fastagency/api/openapi/security.py
| def apply(
self,
q_params: dict[str, Any],
body_dict: dict[str, Any],
security: BaseSecurity,
) -> None:
if "headers" not in body_dict:
body_dict["headers"] = {}
credentials = f"{self.username}:{self.password}"
encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode(
"utf-8"
)
body_dict["headers"]["Authorization"] = f"Basic {encoded_credentials}"
|
get_security_class
Source code in fastagency/api/openapi/security.py
| def get_security_class(self) -> type[BaseSecurity]:
return HTTPBasic
|
accept
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
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("scheme")
|