Files
PraisonAIUI/examples/python/_shared/seed_data.py
T
4fe69554fc fix: channel config secret classification (fixes #58) (#86)
* feat: implement channel config secret security validation (fixes #58)

- Add secret field detection to prevent inline API keys/passwords in channel configs
- Implement config validation that rejects secrets, requires env:VAR_NAME references
- Add response redaction to hide secrets from GET endpoints
- Update examples 20, 22 and seed data to use secure env: pattern
- Covers major secret types: api_key, bot_token, app_password, etc.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* fix: resolve _ref keys in bot startup and add defensive validation

- Add _get_config_secret() helper to resolve bot_token_ref, api_key_ref, app_token_ref
- Update _start_channel_bot() to use new helper for token resolution
- Add defensive input validation to _validate_config_security() and _redact_config_secrets()
- Fix defensive dictionary access in API endpoints (_list, _get)
- Update _resolve_slack_app_token() and test endpoint to use new helper

Fixes critical issue where bots configured with _ref keys could not start.

Co-authored-by: Mervin Praison <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
2026-06-15 15:45:58 +01:00

81 lines
2.3 KiB
Python

"""Shared demo data seeding for examples.
Used by examples 13, 15, and 16 to avoid copy-pasting the same data.
Import and call seed_demo_data() once at module load.
NOTE: Since PraisonAIUI features now use various backends (FileScheduleStore,
ApprovalRegistry, etc.), seeding is best done via API calls in tests rather
than direct store manipulation.
"""
def seed_demo_data():
"""Populate feature stores with demo data.
Seeds data via HTTP API calls to ensure compatibility across
different backend implementations (file, DB, etc.).
"""
try:
from starlette.testclient import TestClient
from praisonaiui.server import create_app
app = create_app()
with TestClient(app) as client:
seed_via_api(client)
except ImportError:
pass
def seed_via_api(client):
"""Seed demo data via API calls (recommended approach).
Args:
client: Starlette TestClient instance
"""
# Channels
client.post("/api/channels", json={
"name": "Discord #general", "platform": "discord",
"config": {"guild_id": "123456789", "bot_token_ref": "env:DISCORD_BOT_TOKEN"}
})
client.post("/api/channels", json={
"name": "Telegram Support", "platform": "telegram",
"config": {"bot_token_ref": "env:TELEGRAM_BOT_TOKEN"}
})
client.post("/api/channels", json={
"name": "Support Email", "platform": "email",
"config": {"email_address": "[email protected]", "app_password_ref": "env:EMAIL_APP_PASSWORD"}
})
# Agents
client.post("/api/agents/definitions", json={
"name": "Summarizer",
"instructions": "You are an expert summarizer.",
"model": "gpt-4o-mini"
})
client.post("/api/agents/definitions", json={
"name": "Code Assistant",
"instructions": "You are an expert programmer.",
"model": "gpt-4o"
})
# Schedules
client.post("/api/schedules", json={
"name": "Daily Report",
"schedule": {"kind": "every", "every_seconds": 86400},
"message": "Generate daily summary"
})
# Usage
client.post("/api/usage/track", json={
"model": "gpt-4o-mini",
"input_tokens": 150,
"output_tokens": 80
})
# Jobs
client.post("/api/jobs", json={
"prompt": "Test job",
"config": {"model": "gpt-4o-mini"}
})