| 12345678910111213141516171819202122232425262728293031323334353637 |
- """
- Seed script: Create a test API application for Open API testing.
- Run: python scripts/seed_open_api_app.py
- """
- import sys
- import uuid
- import secrets
- sys.path.insert(0, ".")
- from database import get_db_connection
- def seed_test_app(app_name: str = "模型训练平台测试", description: str = "测试用接入应用"):
- app_id = f"app_id_{secrets.token_hex(8)}"
- app_secret = secrets.token_hex(16)
- with get_db_connection() as conn:
- cursor = conn.cursor()
- cursor.execute(
- """
- INSERT INTO api_applications
- (id, app_id, app_name, app_secret, status, description)
- VALUES (%s, %s, %s, %s, %s, %s)
- """,
- (str(uuid.uuid4()), app_id, app_name, app_secret, "active", description),
- )
- print("=" * 60)
- print("测试接入应用已创建!请妥善保存以下凭证:")
- print("=" * 60)
- print(f" app_id: {app_id}")
- print(f" app_secret: {app_secret}")
- print("=" * 60)
- if __name__ == "__main__":
- seed_test_app()
|