2022-03-30 21:19:06 +00:00
|
|
|
"""
|
|
|
|
/service endpoints.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
|
|
|
2022-04-01 15:40:08 +00:00
|
|
|
from ..db import User
|
|
|
|
from ..easyrsa import CertificateType, EasyRSA
|
2022-04-01 17:15:56 +00:00
|
|
|
from ._common import Responses, get_current_user
|
2022-03-30 21:19:06 +00:00
|
|
|
|
|
|
|
router = APIRouter(prefix="/service", tags=["service"])
|
|
|
|
|
|
|
|
|
|
|
|
@router.put(
|
|
|
|
"/pki/init",
|
|
|
|
responses={
|
2022-04-07 11:59:42 +00:00
|
|
|
status.HTTP_200_OK: Responses.OK_NONE,
|
2022-03-30 21:19:06 +00:00
|
|
|
status.HTTP_400_BAD_REQUEST: Responses.NOT_INSTALLED,
|
2022-04-01 17:15:56 +00:00
|
|
|
status.HTTP_401_UNAUTHORIZED: Responses.NEEDS_USER,
|
2022-03-30 21:19:06 +00:00
|
|
|
status.HTTP_403_FORBIDDEN: Responses.NEEDS_PERMISSION,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
async def init_pki(
|
2022-04-01 15:40:08 +00:00
|
|
|
current_user: User = Depends(get_current_user),
|
2022-03-30 21:19:06 +00:00
|
|
|
) -> None:
|
2022-04-01 15:40:08 +00:00
|
|
|
|
|
|
|
if not current_user.is_admin:
|
|
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
|
|
|
|
|
|
|
easy_rsa = EasyRSA()
|
|
|
|
|
|
|
|
easy_rsa.init_pki()
|
|
|
|
easy_rsa.build_ca()
|
|
|
|
easy_rsa.issue(CertificateType.server)
|