:py:mod:`own_comments.helpers` ============================== .. py:module:: own_comments.helpers Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: own_comments.helpers.get_db own_comments.helpers.require_admin own_comments.helpers.is_admin own_comments.helpers.get_basic_auth own_comments.helpers.check_update_key own_comments.helpers.get_comment_if_authorized Attributes ~~~~~~~~~~ .. autoapisummary:: own_comments.helpers.security .. py:data:: security .. py:function:: get_db() .. py:function:: require_admin(credentials: fastapi.security.HTTPBasicCredentials = Depends(security)) Helper to be used as a fastapi dependency Raise 401 is not HTTP Basic auth is present, and 403 if credentials are not valid .. py:function:: is_admin(credentials: Optional[fastapi.security.HTTPBasicCredentials]) Verify admin credentials. Safe against timing attacks. .. py:function:: get_basic_auth(request: starlette.requests.Request) Extract username and password from a request headers .. py:function:: check_update_key(comment: own_comments.models.Comment, comment_update: own_comments.schemas.CommentUpdateMixin) Compare an update key to a stored update key. Safe against timing attacks. .. py:function:: get_comment_if_authorized(db: sqlalchemy.orm.Session, comment_id: int, credentials: Optional[fastapi.security.HTTPBasicCredentials], comment_update: Optional[Union[own_comments.schemas.CommentPatch, own_comments.schemas.CommentDelete]]) Get a comment from the DB. Raises 404 if the comment cannot be found. Raises 403 if no update key is present in the comment_update schema and no valid admin credentials are provided.