dependencies
Module that contains the methods used by FastApi dependency injection.
Module Contents
Classes
Callable class that checks if user has permission on document |
|
Callable class that checks if user has permission on project |
|
Callable class that checks if user has system permission |
Functions
Get a session for the database |
|
Creates the database and tables |
|
|
Creates an access token |
|
Gets the current user from the token |
|
Gets the current user from dependencies |
|
Gets the project named project_name from the database |
|
Gets the document named document_name from the database |
|
Gets the ms project named ms_project_name from the database |
|
Checks if user has permission on document, raises 401 if not authorized |
|
Checks if user has permission on project, raises 401 if not authorized |
|
Checks if user has system permission, raises 401 if not authorized |
|
Gets request body from request and returns it as dict, parsing both json and yaml |
|
Checks if document satisfies constraints of processes, raises 428 if not satisfied |
|
Validates document body against document schema, raises 400 if not valid |
Attributes
- dependencies.oauth2_scheme
- dependencies.sqlite_file_name = ./db/database.db
- dependencies.sqlite_url
- dependencies.connect_args
- dependencies.engine
- dependencies.get_session()
Get a session for the database
- Returns
session
- dependencies.create_db_and_tables()
Creates the database and tables
- dependencies.create_access_token(data, expires_delta=None)
Creates an access token
- Parameters
data (dict) – data to include in the token
expires_delta (timedelta | None) – expiration time of token
- Returns
token
- async dependencies.get_current_user(token=Depends(oauth2_scheme), session=Depends(get_session))
Gets the current user from the token
- Parameters
token (str) – token
session (sqlmodel.Session) – database session from dependencies
- Returns
current user
- async dependencies.get_current_active_user(current_user=Depends(get_current_user))
Gets the current user from dependencies
- Parameters
current_user (datatypes.models.User) – current user from dependencies
- Returns
current user
- dependencies.get_project(project_name=None, session=Depends(get_session))
Gets the project named project_name from the database If project_name is None, returns None If project is not found, raises 404 exception
- Parameters
project_name (str | None) – project name, from path params
session (sqlmodel.Session) – database session from dependencies
- Returns
project
- dependencies.get_document(project_name=None, document_name=None, session=Depends(get_session))
Gets the document named document_name from the database If project_name or document_name are None, returns None If document is not found, raises 404 exception
- Parameters
project_name (str | None) – project name, from path params
document_name (str | None) – document name, from path params
session (sqlmodel.Session) – database session from dependencies
- Returns
document
- dependencies.get_ms_project(project_name=None, ms_project_name=None, session=Depends(get_session))
Gets the ms project named ms_project_name from the database If project_name or ms_project_name are None, returns None If ms_project is not found, raises 404 exception
- Parameters
project_name (str | None) – project name, from path params
ms_project_name (str | None) – ms project name, from path params
session (sqlmodel.Session) – database session from dependencies
- Returns
ms project
- class dependencies.CheckDocumentPermission(permission)
Callable class that checks if user has permission on document
- Parameters
permission (auth.Permissions) –
- __call__(self, session=Depends(get_session), user=Depends(get_current_active_user), db_project=Depends(get_project), db_doc=Depends(get_document))
- Parameters
session (sqlmodel.Session) –
user (datatypes.models.User) –
db_project (datatypes.models.Project) –
db_doc (datatypes.models.Document) –
- dependencies.require_document_permission(permission)
Checks if user has permission on document, raises 401 if not authorized
- Parameters
permission (auth.Permissions) – permission to check
- class dependencies.CheckProjectPermission(permission)
Callable class that checks if user has permission on project
- Parameters
permission (auth.Permissions) –
- __call__(self, session=Depends(get_session), user=Depends(get_current_active_user), db_project=Depends(get_project))
- Parameters
session (sqlmodel.Session) –
user (datatypes.models.User) –
db_project (Project | None) –
- dependencies.require_project_permission(permission)
Checks if user has permission on project, raises 401 if not authorized
- Parameters
permission (auth.Permissions) – permission to check
- class dependencies.CheckSystemPermission(permission)
Callable class that checks if user has system permission
- Parameters
permission (auth.Permissions) –
- __call__(self, session=Depends(get_session), user=Depends(get_current_active_user))
- Parameters
session (sqlmodel.Session) –
user (datatypes.models.User) –
- dependencies.require_system_permission(permission)
Checks if user has system permission, raises 401 if not authorized
- Parameters
permission (auth.Permissions) – permission to check
- async dependencies.get_request_body(request)
Gets request body from request and returns it as dict, parsing both json and yaml
- Parameters
request (starlette.requests.Request) – request from body
- Returns
dict with request body
- dependencies.check_document_process(db_doc=Depends(get_document))
Checks if document satisfies constraints of processes, raises 428 if not satisfied
- Parameters
db_doc (datatypes.models.Document) – document from path, returned by dependencies
- dependencies.validate_document(db_doc=Depends(get_document), document_body=Depends(get_request_body))
Validates document body against document schema, raises 400 if not valid
- Parameters
db_doc (datatypes.models.Document) – document from path, returned by dependencies
document_body (Dict) – document body from request