more asyncio
This commit is contained in:
parent
6e9cf9f920
commit
ba68692b9d
4 changed files with 9 additions and 18 deletions
|
@ -35,7 +35,7 @@ class DBConfig(BaseModel):
|
|||
db_type: DBType = DBType.sqlite
|
||||
|
||||
@property
|
||||
def db_engine(self) -> Engine:
|
||||
async def db_engine(self) -> Engine:
|
||||
return create_engine(
|
||||
"sqlite:///./tmp/vpn.db",
|
||||
connect_args={"check_same_thread": False},
|
||||
|
@ -99,7 +99,7 @@ class CryptoConfig(BaseModel):
|
|||
schemes: list[str] = ["bcrypt"]
|
||||
|
||||
@property
|
||||
def crypt_context(self) -> CryptContext:
|
||||
async def crypt_context(self) -> CryptContext:
|
||||
return CryptContext(
|
||||
schemes=self.schemes,
|
||||
deprecated="auto",
|
||||
|
@ -120,15 +120,6 @@ class Config(BaseModel):
|
|||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def set(config: Config) -> None:
|
||||
async def set(self) -> None:
|
||||
with open(Settings.get().config_file, "w") as config_file:
|
||||
config_file.write(config.json(indent=2))
|
||||
|
||||
@property
|
||||
def crypt_context(self) -> CryptContext:
|
||||
return self.crypto.crypt_context
|
||||
|
||||
@property
|
||||
def db_engine(self) -> Engine:
|
||||
return self.db.db_engine
|
||||
config_file.write(self.json(indent=2))
|
||||
|
|
|
@ -36,7 +36,7 @@ api.include_router(user.router)
|
|||
@app.on_event("startup")
|
||||
async def on_startup() -> None:
|
||||
if (current_config := await Config.get()) is not None:
|
||||
Connection.connect(current_config.db_engine)
|
||||
Connection.connect(await current_config.db.db_engine)
|
||||
|
||||
# some testing
|
||||
async for db in Connection.get():
|
||||
|
|
|
@ -31,8 +31,8 @@ async def set_config(
|
|||
if new_config.jwt.secret is None:
|
||||
new_config.jwt.secret = token_hex(32)
|
||||
|
||||
Config.set(new_config)
|
||||
Connection.connect(new_config.db_engine)
|
||||
await new_config.set()
|
||||
Connection.connect(await new_config.db.db_engine)
|
||||
|
||||
|
||||
@router.post(
|
||||
|
@ -63,5 +63,5 @@ async def add_user(
|
|||
password=user_password,
|
||||
capabilities=["admin"],
|
||||
),
|
||||
crypt_context=current_config.crypt_context,
|
||||
crypt_context=await current_config.crypto.crypt_context,
|
||||
)
|
||||
|
|
|
@ -28,7 +28,7 @@ async def login(
|
|||
db=db,
|
||||
name=form_data.username,
|
||||
password=form_data.password,
|
||||
crypt_context=config.crypt_context,
|
||||
crypt_context=await config.crypto.crypt_context,
|
||||
)
|
||||
|
||||
if user is None:
|
||||
|
|
Loading…
Reference in a new issue