Initialisation depot
This commit is contained in:
85
samba-api/main.py
Normal file
85
samba-api/main.py
Normal file
@@ -0,0 +1,85 @@
|
||||
from fastapi import FastAPI, HTTPException, Depends
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.security import HTTPBearer
|
||||
import uvicorn
|
||||
import logging
|
||||
|
||||
from src.routers import users, groups, ous, computers, auth
|
||||
from src.core.config import settings
|
||||
from src.core.exceptions import setup_exception_handlers
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Initialize FastAPI app
|
||||
app = FastAPI(
|
||||
title="Samba API",
|
||||
description="REST API for Samba Active Directory management",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc"
|
||||
)
|
||||
|
||||
# Configure CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.ALLOWED_HOSTS,
|
||||
allow_credentials=True,
|
||||
allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Setup exception handlers
|
||||
setup_exception_handlers(app)
|
||||
|
||||
# Include routers
|
||||
app.include_router(auth.router, prefix="/api/v1/auth", tags=["Authentication"])
|
||||
app.include_router(users.router, prefix="/api/v1/users", tags=["Users"])
|
||||
app.include_router(groups.router, prefix="/api/v1/groups", tags=["Groups"])
|
||||
app.include_router(ous.router, prefix="/api/v1/ous", tags=["Organizational Units"])
|
||||
app.include_router(computers.router, prefix="/api/v1/computers", tags=["Computers"])
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Samba API is running", "version": "1.0.0"}
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
return {"status": "healthy", "service": "samba-api"}
|
||||
|
||||
if __name__ == "__main__":
|
||||
import ssl
|
||||
import os
|
||||
|
||||
# Check if SSL certificates exist
|
||||
ssl_keyfile = "/app/ssl/server.key"
|
||||
ssl_certfile = "/app/ssl/server.crt"
|
||||
|
||||
if os.path.exists(ssl_keyfile) and os.path.exists(ssl_certfile):
|
||||
# HTTPS configuration
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
ssl_context.load_cert_chain(ssl_certfile, ssl_keyfile)
|
||||
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host=settings.HOST,
|
||||
port=settings.HTTPS_PORT if hasattr(settings, 'HTTPS_PORT') else 8443,
|
||||
reload=settings.DEBUG,
|
||||
log_level="info",
|
||||
ssl_keyfile=ssl_keyfile,
|
||||
ssl_certfile=ssl_certfile
|
||||
)
|
||||
else:
|
||||
# HTTP fallback
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host=settings.HOST,
|
||||
port=settings.PORT,
|
||||
reload=settings.DEBUG,
|
||||
log_level="info"
|
||||
)
|
||||
Reference in New Issue
Block a user