seed_open_api_app.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. Seed script: Create a test API application for Open API testing.
  3. Run: python scripts/seed_open_api_app.py
  4. """
  5. import sys
  6. import uuid
  7. import secrets
  8. sys.path.insert(0, ".")
  9. from database import get_db_connection
  10. def seed_test_app(app_name: str = "模型训练平台测试", description: str = "测试用接入应用"):
  11. app_id = f"app_id_{secrets.token_hex(8)}"
  12. app_secret = secrets.token_hex(16)
  13. with get_db_connection() as conn:
  14. cursor = conn.cursor()
  15. cursor.execute(
  16. """
  17. INSERT INTO api_applications
  18. (id, app_id, app_name, app_secret, status, description)
  19. VALUES (%s, %s, %s, %s, %s, %s)
  20. """,
  21. (str(uuid.uuid4()), app_id, app_name, app_secret, "active", description),
  22. )
  23. print("=" * 60)
  24. print("测试接入应用已创建!请妥善保存以下凭证:")
  25. print("=" * 60)
  26. print(f" app_id: {app_id}")
  27. print(f" app_secret: {app_secret}")
  28. print("=" * 60)
  29. if __name__ == "__main__":
  30. seed_test_app()