6ae017b142
- Auto-format all Python files with black and isort - Remove unused imports with autoflake - Fix flake8 issues (missing newlines, blank lines, etc.) - Fix nonlocal/global scope issues in main.py - Fix security.py import order (E402) - Remove f-string without placeholders - Add nosec comment for intentional exception handling - Fix test imports to match refactored DMARCParser API Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
|
|
from fastapi import APIRouter, HTTPException, status
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
router = APIRouter()
|
|
|
|
# Simple in-memory storage for setup status (for Milestone 1)
|
|
setup_status = {
|
|
"is_setup_complete": False,
|
|
"admin_email": None,
|
|
"app_name": "DMARQ",
|
|
}
|
|
|
|
|
|
class SetupStatusResponse(BaseModel):
|
|
"""Setup status response"""
|
|
|
|
is_setup_complete: bool
|
|
app_name: str
|
|
|
|
|
|
class AdminSetupRequest(BaseModel):
|
|
"""Admin user setup request body"""
|
|
|
|
email: EmailStr
|
|
username: str
|
|
password: str
|
|
|
|
|
|
class SystemConfigRequest(BaseModel):
|
|
"""System configuration setup request body"""
|
|
|
|
app_name: str
|
|
base_url: str
|
|
|
|
|
|
@router.get("/status", response_model=SetupStatusResponse)
|
|
async def get_setup_status():
|
|
"""Get the current setup status"""
|
|
return SetupStatusResponse(
|
|
is_setup_complete=setup_status["is_setup_complete"], app_name=setup_status["app_name"]
|
|
)
|
|
|
|
|
|
@router.post("/admin", status_code=201)
|
|
async def setup_admin(request: AdminSetupRequest):
|
|
"""
|
|
Setup admin user during initial system configuration.
|
|
For Milestone 1, this simply stores the admin email in memory.
|
|
"""
|
|
if setup_status["is_setup_complete"]:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST, detail="Setup already completed"
|
|
)
|
|
|
|
# Store admin email
|
|
setup_status["admin_email"] = request.email
|
|
|
|
return {"message": "Admin user setup completed"}
|
|
|
|
|
|
@router.post("/system", status_code=200)
|
|
async def setup_system(request: SystemConfigRequest):
|
|
"""
|
|
Setup system configuration.
|
|
For Milestone 1, this simply stores the app name in memory.
|
|
"""
|
|
# Store app name
|
|
setup_status["app_name"] = request.app_name
|
|
setup_status["is_setup_complete"] = True
|
|
|
|
return {"message": "System settings saved successfully"}
|