diff --git a/api.py b/api.py index 72e741e..ffdfc28 100644 --- a/api.py +++ b/api.py @@ -179,10 +179,10 @@ app.include_router(entreprises_router) @app.get("/clients", response_model=List[ClientDetails], tags=["Clients"]) async def obtenir_clients( query: Optional[str] = Query(None), - # sage: SageGatewayClient = Depends(get_sage_client_for_user), + sage: SageGatewayClient = Depends(get_sage_client_for_user), ): try: - clients = sage_client.lister_clients(filtre=query or "") + clients = sage.lister_clients(filtre=query or "") return [ClientDetails(**c) for c in clients] except Exception as e: logger.error(f"Erreur recherche clients: {e}") diff --git a/routes/auth.py b/routes/auth.py index 0d18349..5fc2554 100644 --- a/routes/auth.py +++ b/routes/auth.py @@ -101,7 +101,7 @@ async def check_rate_limit( ) failed_attempts = result.scalars().all() - if len(failed_attempts) >= 5: + if len(failed_attempts) >= 15: return False, "Trop de tentatives échouées. Réessayez dans 15 minutes." return True, "" @@ -286,7 +286,7 @@ async def login( if user: user.failed_login_attempts += 1 - if user.failed_login_attempts >= 5: + if user.failed_login_attempts >= 15: user.locked_until = datetime.now() + timedelta(minutes=15) await session.commit() raise HTTPException( diff --git a/tools/cleaner.py b/tools/cleaner.py new file mode 100644 index 0000000..6da2e19 --- /dev/null +++ b/tools/cleaner.py @@ -0,0 +1,15 @@ +from pathlib import Path + + +def supprimer_commentaires_ligne(fichier): + path = Path(fichier) + lignes = path.read_text(encoding="utf-8").splitlines() + lignes_sans_commentaires = [line for line in lignes if not line.lstrip().startswith("#")] + path.write_text("\n".join(lignes_sans_commentaires), encoding="utf-8") + + +if __name__ == "__main__": + base_dir = Path(__file__).resolve().parent.parent + fichier_api = base_dir / "data/data.py" + + supprimer_commentaires_ligne(fichier_api) diff --git a/tools/extract_pydantic_models.py b/tools/extract_pydantic_models.py new file mode 100644 index 0000000..595e15f --- /dev/null +++ b/tools/extract_pydantic_models.py @@ -0,0 +1,54 @@ +import ast +import os +import textwrap + +SOURCE_FILE = "main.py" +MODELS_DIR = "../models" + +os.makedirs(MODELS_DIR, exist_ok=True) + +with open(SOURCE_FILE, "r", encoding="utf-8") as f: + source_code = f.read() + +tree = ast.parse(source_code) + +pydantic_classes = [] +other_nodes = [] + +for node in tree.body: + if isinstance(node, ast.ClassDef): + if any( + isinstance(base, ast.Name) and base.id == "BaseModel" for base in node.bases + ): + pydantic_classes.append(node) + continue + other_nodes.append(node) + +# --- Extraction des classes --- +imports = """ +from pydantic import BaseModel, Field +from typing import Optional, List +""" + +for cls in pydantic_classes: + class_name = cls.name + file_name = f"{class_name.lower()}.py" + file_path = os.path.join(MODELS_DIR, file_name) + + class_code = ast.get_source_segment(source_code, cls) + class_code = textwrap.dedent(class_code) + + with open(file_path, "w", encoding="utf-8") as f: + f.write(imports.strip() + "\n\n") + f.write(class_code) + + print(f"✅ Modèle extrait : {class_name} → {file_path}") + +# --- Réécriture du fichier source sans les modèles --- +new_tree = ast.Module(body=other_nodes, type_ignores=[]) +new_source = ast.unparse(new_tree) + +with open(SOURCE_FILE, "w", encoding="utf-8") as f: + f.write(new_source) + +print("\n🎉 Extraction terminée")