| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- """
- Test de l'API consumption Scaleway (Billing).
- À supprimer : script de test manuel pour vérifier l'appel à l'API Billing.
- """
- import os
- import sys
- # Ajouter le chemin agent_docker pour importer le service
- agent_docker = os.path.join(os.path.dirname(__file__), "..", "agent_docker")
- sys.path.insert(0, agent_docker)
- # Charger le .env de agent_docker
- from dotenv import load_dotenv
- load_dotenv(os.path.join(agent_docker, ".env"))
- from src.service.scaleway_billing_service import get_scaleway_consumption
- if __name__ == "__main__":
- # Vérifier que les variables d'environnement sont définies
- if not os.getenv("SCW_API_KEY") and not os.getenv("SCW_SECRET_KEY"):
- print("Erreur : définir SCW_API_KEY ou SCW_SECRET_KEY dans .env")
- sys.exit(1)
- if not os.getenv("SCW_ORGANIZATION_ID") and not os.getenv("SCW_ENDPOINT"):
- print("Erreur : définir SCW_ORGANIZATION_ID ou SCW_ENDPOINT (project_id) dans .env")
- sys.exit(1)
- print("Appel API Billing Scaleway (mois courant)...")
- result = get_scaleway_consumption(timeout=10)
- if result is None:
- print("Aucun résultat (config manquante)")
- sys.exit(1)
- if result.get("error"):
- print(f"Erreur : {result['error']}")
- sys.exit(1)
- print(f"Période : {result.get('period', 'N/A')}")
- print(f"Total : {result.get('total_eur', 0):.2f} {result.get('currency', 'EUR')}")
- if result.get("consumptions"):
- print("Détail par catégorie :")
- for c in result["consumptions"]:
- print(f" - {c['category']}: {c['amount_eur']:.2f} €")
- else:
- print("Aucune consommation détaillée.")
- print("OK")
|