collapse "db" subpkg, clean install router
This commit is contained in:
parent
e76de17ff5
commit
112d86d827
6 changed files with 27 additions and 16 deletions
|
@ -6,7 +6,7 @@ from typing import Optional
|
|||
from peewee import (BooleanField, CharField, DateTimeField, ForeignKeyField,
|
||||
Model)
|
||||
|
||||
from ..config import CRYPT_CONTEXT, DB
|
||||
from .config import CRYPT_CONTEXT, DB
|
||||
|
||||
|
||||
class BaseModel(Model):
|
|
@ -20,7 +20,7 @@ api = FastAPI(
|
|||
"url": "https://opensource.org/licenses/mit-license.php",
|
||||
},
|
||||
docs_url="/docs" if not PRODUCTION_MODE else None,
|
||||
redoc_url=None,
|
||||
redoc_url="/redoc" if not PRODUCTION_MODE else None,
|
||||
)
|
||||
|
||||
api.include_router(install.router)
|
||||
|
|
|
@ -7,7 +7,7 @@ from pydantic import BaseModel
|
|||
|
||||
from ..config import (ACCESS_TOKEN_EXPIRE_MINUTES, ALGORITHM, CRYPT_CONTEXT,
|
||||
SECRET_KEY)
|
||||
from ..db.model import User
|
||||
from ..db import User
|
||||
|
||||
router = APIRouter(prefix="/auth")
|
||||
SCHEME = OAuth2PasswordBearer(
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi import APIRouter, Depends, status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from ..config import DB, CRYPT_CONTEXT
|
||||
from ..db.model import Certificate, DistinguishedName, User, UserCapability
|
||||
from ..config import CRYPT_CONTEXT, DB
|
||||
from ..db import Certificate, DistinguishedName, User, UserCapability
|
||||
|
||||
router = APIRouter(prefix="/install")
|
||||
|
||||
|
@ -10,20 +11,30 @@ async def is_installed():
|
|||
return DB.table_exists(User)
|
||||
|
||||
|
||||
@router.get("/check_installed")
|
||||
@router.get("/check_installed", responses={
|
||||
status.HTTP_200_OK: {
|
||||
"model": bool,
|
||||
},
|
||||
})
|
||||
async def check_installed(is_installed: bool = Depends(is_installed)):
|
||||
return {"is_installed": is_installed}
|
||||
return is_installed
|
||||
|
||||
|
||||
@router.get("/create_db")
|
||||
@router.get("/create_db", responses={
|
||||
status.HTTP_200_OK: {
|
||||
"description": "Database created",
|
||||
"content": None,
|
||||
},
|
||||
status.HTTP_400_BAD_REQUEST: {
|
||||
"description": "Could not create Database",
|
||||
"content": None,
|
||||
}
|
||||
})
|
||||
async def create_db(is_installed: bool = Depends(is_installed)):
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
if is_installed:
|
||||
raise credentials_exception
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
DB.create_tables([Certificate, DistinguishedName, User, UserCapability])
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from jose import JWTError, jwt
|
|||
from pydantic import BaseModel
|
||||
|
||||
from ..config import ALGORITHM, SECRET_KEY
|
||||
from ..db.model import User as db_User
|
||||
from ..db import User as db_User
|
||||
from .auth import SCHEME
|
||||
|
||||
router = APIRouter(prefix="/user")
|
||||
|
|
Loading…
Reference in a new issue