ci: dockerise l'API + connexion DB et CORS configurables par env

- config.py: connexion SQL via DB_* (driver 18, auth SQL), fallback Windows local
- main.py: origines CORS via CORS_ORIGINS
- Dockerfile (python 3.12 + msodbcsql18) + workflow Gitea Actions (build/push image)
This commit is contained in:
neckfire
2026-06-20 12:21:47 +02:00
parent e0b314ee76
commit 51d041c0da
4 changed files with 97 additions and 7 deletions
+28 -6
View File
@@ -3,28 +3,50 @@
# Data Sentinel | COYAUD Anthony | 2026
# ============================================================
import os
import pyodbc
from contextlib import contextmanager
class Config:
# Chaîne de connexion SQL Server
DB_CONNECTION_STRING = (
def _build_connection_string() -> str:
"""
En déploiement (variables d'environnement présentes), on se connecte en
authentification SQL. Sinon, on garde la connexion Windows locale par défaut
(poste de dev).
"""
server = os.getenv("DB_SERVER")
if server:
driver = os.getenv("DB_DRIVER", "ODBC Driver 18 for SQL Server")
port = os.getenv("DB_PORT", "1433")
return (
f"Driver={{{driver}}};"
f"Server={server},{port};"
f"Database={os.getenv('DB_NAME', 'DataSentinel')};"
f"UID={os.getenv('DB_USER')};"
f"PWD={os.getenv('DB_PASSWORD')};"
"Encrypt=yes;TrustServerCertificate=yes;"
)
return (
"Driver={ODBC Driver 17 for SQL Server};"
"Server=LaptopCA\\SQLEXPRESS;"
"Database=DataSentinel;"
"Trusted_Connection=yes;"
)
class Config:
# Chaîne de connexion SQL Server (env en prod, Windows en local)
DB_CONNECTION_STRING = _build_connection_string()
# Paramètres API
API_TITLE = "Data Sentinel API"
API_VERSION = "1.0.0"
API_DESCRIPTION = "API de monitoring de la qualité des données — XEFI"
# Sécurité JWT
SECRET_KEY = "data-sentinel-secret-change-in-prod"
ALGORITHM = "HS256"
TOKEN_EXPIRE_MINUTES = 60
SECRET_KEY = os.getenv("JWT_SECRET", "data-sentinel-secret-change-in-prod")
ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256")
TOKEN_EXPIRE_MINUTES = int(os.getenv("JWT_EXPIRE_MINUTES", "60"))
# ----------------------------------------------------------------