own_comments.helpers

Module Contents

Functions

get_db()

require_admin(credentials: fastapi.security.HTTPBasicCredentials = Depends(security))

Helper to be used as a fastapi dependency

is_admin(credentials: Optional[fastapi.security.HTTPBasicCredentials])

Verify admin credentials. Safe against timing attacks.

get_basic_auth(request: starlette.requests.Request)

Extract username and password from a request headers

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.

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.

Attributes

security

own_comments.helpers.security
own_comments.helpers.get_db()
own_comments.helpers.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

own_comments.helpers.is_admin(credentials: Optional[fastapi.security.HTTPBasicCredentials])

Verify admin credentials. Safe against timing attacks.

own_comments.helpers.get_basic_auth(request: starlette.requests.Request)

Extract username and password from a request headers

own_comments.helpers.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.

own_comments.helpers.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.