cryptContext source
This commit is contained in:
parent
2861b2fb0d
commit
c8ede06c26
1 changed files with 4 additions and 2 deletions
|
@ -5,7 +5,7 @@ from secrets import token_hex
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
from peewee import Database
|
from peewee import Database
|
||||||
|
|
||||||
from ..config import CRYPT_CONTEXT, BaseConfig
|
from ..config import BaseConfig
|
||||||
from ..db import Certificate, DistinguishedName, User, UserCapability
|
from ..db import Certificate, DistinguishedName, User, UserCapability
|
||||||
|
|
||||||
router = APIRouter(prefix="/install")
|
router = APIRouter(prefix="/install")
|
||||||
|
@ -109,6 +109,7 @@ async def check_db(
|
||||||
async def create_db(
|
async def create_db(
|
||||||
admin_name: str,
|
admin_name: str,
|
||||||
admin_password: str,
|
admin_password: str,
|
||||||
|
config: BaseConfig = Depends(load_config),
|
||||||
db: Database = Depends(connect_db),
|
db: Database = Depends(connect_db),
|
||||||
):
|
):
|
||||||
if await has_tables(db):
|
if await has_tables(db):
|
||||||
|
@ -116,8 +117,9 @@ async def create_db(
|
||||||
|
|
||||||
db.create_tables([Certificate, DistinguishedName, User, UserCapability])
|
db.create_tables([Certificate, DistinguishedName, User, UserCapability])
|
||||||
|
|
||||||
|
cryptContext = await config.crypto.cryptContext
|
||||||
admin = User.create(
|
admin = User.create(
|
||||||
name=admin_name,
|
name=admin_name,
|
||||||
password=CRYPT_CONTEXT.hash(admin_password),
|
password=cryptContext.hash(admin_password),
|
||||||
)
|
)
|
||||||
UserCapability.create(user=admin, capability="admin")
|
UserCapability.create(user=admin, capability="admin")
|
||||||
|
|
Loading…
Reference in a new issue