deps#

Dependencies for the endpoints.

The goal is to create all dependencies using a Config class so that the app can be configured differently for testing and production.




Functions#

filter_valid_token

Return the token if it is valid, otherwise return None.

get_async_session

Initiate a DB session that will be closed when a request finishes.

get_authorized_user_email_or_anon

raises AuthServiceError

if the token is not wellformed

get_current_user

Retrieve the data of the current user from the database.

get_graphql_context

Prepare the context object used by GraphQL resolvers.

get_session

Initiate a DB session that will be closed when a request finishes.

register_user

Add the user information to the database.

filter_valid_token()#

async rootski.main.deps.filter_valid_token(request: starlette.requests.Request, credentials: fastapi.security.http.HTTPAuthorizationCredentials = Security(HTTPBearer)) Optional[str][source]#

Return the token if it is valid, otherwise return None. None is taken to be the anon user.

get_async_session()#

async rootski.main.deps.get_async_session(request: starlette.requests.Request) Generator[sqlalchemy.ext.asyncio.session.AsyncSession, None, None][source]#

Initiate a DB session that will be closed when a request finishes.

get_authorized_user_email_or_anon()#

async rootski.main.deps.get_authorized_user_email_or_anon(request: starlette.requests.Request, token: str = Depends(filter_valid_token)) str[source]#
Raises

AuthServiceError – if the token is not wellformed

get_current_user()#

async rootski.main.deps.get_current_user(db: sqlalchemy.orm.session.Session = Depends(get_session), email: str = Depends(get_authorized_user_email_or_anon)) rootski.schemas.user.User[source]#

Retrieve the data of the current user from the database.

get_graphql_context()#

rootski.main.deps.get_graphql_context(request: starlette.requests.Request, db: sqlalchemy.orm.session.Session = Depends(get_async_session), user: rootski.schemas.user.User = Depends(get_current_user)) rootski.gql.context.RootskiGraphQLContext[source]#

Prepare the context object used by GraphQL resolvers.

get_session()#

rootski.main.deps.get_session(request: starlette.requests.Request) Generator[sqlalchemy.orm.session.Session, None, None][source]#

Initiate a DB session that will be closed when a request finishes.

register_user()#

rootski.main.deps.register_user(session: sqlalchemy.orm.session.Session, email: str, is_admin: bool = False) rootski.schemas.user.User[source]#

Add the user information to the database.

Parameters
  • session – used to check if the user already exists and add the user to the db

  • email – email of the user

  • is_admin – sets the “is_admin” field of the user to this value in the db

Raises

UserAlreadyRegisteredError – if the user is already registered, the caller of this function should have checked this in advance

Returns

model of the registered user