first commit
This commit is contained in:
commit
cce9a8c9ba
73 changed files with 8665 additions and 0 deletions
28
backend/app/deps/dns_setup_auth.py
Normal file
28
backend/app/deps/dns_setup_auth.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import secrets
|
||||
|
||||
from fastapi import Depends, HTTPException, status
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
security = HTTPBasic()
|
||||
|
||||
|
||||
async def require_dns_setup_auth(
|
||||
credentials: HTTPBasicCredentials = Depends(security),
|
||||
) -> None:
|
||||
settings = get_settings()
|
||||
username_ok = secrets.compare_digest(
|
||||
credentials.username,
|
||||
settings.dns_setup_username,
|
||||
)
|
||||
password_ok = secrets.compare_digest(
|
||||
credentials.password,
|
||||
settings.dns_setup_password,
|
||||
)
|
||||
if not (username_ok and password_ok):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid DNS setup credentials.",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue