Added comments

This commit is contained in:
StNicolay 2022-10-14 15:41:55 +03:00
parent 3ebe4240bf
commit 29b7125a4d
3 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@ def add_account(
enc_login: bytes,
enc_pass: bytes,
) -> bool:
"""Adds account to db. Returns true, if on success"""
account = models.Account(
user_id=user_id, name=name, salt=salt, enc_login=enc_login, enc_pass=enc_pass
)
@ -27,6 +28,7 @@ def add_account(
def add_master_pass(engine: Engine, user_id: int, salt: bytes, passwd: bytes) -> bool:
"""Adds master password to db. Returns true, if on success"""
master_pass = models.MasterPass(user_id=user_id, salt=salt, passwd=passwd)
try:
with sqlmodel.Session(engine) as session:

View File

@ -5,6 +5,7 @@ from . import models
def get_master_pass(engine: Engine, user_id: int) -> tuple[bytes, bytes] | None:
"""Gets master pass. Returns tuple of salt and password"""
statement = sqlmodel.select(models.MasterPass).where(
models.MasterPass.user_id == user_id
)
@ -17,6 +18,7 @@ def get_master_pass(engine: Engine, user_id: int) -> tuple[bytes, bytes] | None:
def get_accounts(engine: Engine, user_id: int) -> list[str]:
"""Gets list of account names"""
statement = sqlmodel.select(models.Account).where(models.Account.user_id == user_id)
with sqlmodel.Session(engine) as session:
result = session.exec(statement)
@ -26,6 +28,7 @@ def get_accounts(engine: Engine, user_id: int) -> list[str]:
def get_account_info(
engine: Engine, user_id: int, name: str
) -> tuple[bytes, bytes, bytes]:
"""Gets account info. Returns tuple of salt, login and password"""
statement = sqlmodel.select(models.Account).where(
models.Account.user_id == user_id and models.Account.name == name
)

View File

@ -13,4 +13,4 @@ def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
def prepare(engine: Engine) -> None:
sqlmodel.SQLModel.metadata.create_all(engine)
sqlmodel.SQLModel.metadata.create_all(engine, [models.Account, models.MasterPass])