Improve the demo feature of the project
This commit is contained in:
@@ -27,8 +27,7 @@ COPY --from=shared /shared /app/shared
|
||||
# Copy application code
|
||||
COPY services/auth/ .
|
||||
|
||||
# Copy scripts directory
|
||||
COPY scripts/ /app/scripts/
|
||||
|
||||
|
||||
# Add shared libraries to Python path
|
||||
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
# ================================================================
|
||||
# services/auth/docker-compose.yml (For standalone testing)
|
||||
# ================================================================
|
||||
|
||||
services:
|
||||
auth-db:
|
||||
image: postgres:15-alpine
|
||||
container_name: auth-db
|
||||
environment:
|
||||
POSTGRES_DB: auth_db
|
||||
POSTGRES_USER: auth_user
|
||||
POSTGRES_PASSWORD: auth_pass123
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- auth_db_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U auth_user -d auth_db"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: auth-redis
|
||||
ports:
|
||||
- "6379:6379"
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:3-management-alpine
|
||||
container_name: auth-rabbitmq
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: bakery
|
||||
RABBITMQ_DEFAULT_PASS: forecast123
|
||||
ports:
|
||||
- "5672:5672"
|
||||
- "15672:15672"
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "ping"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
auth-service:
|
||||
build: .
|
||||
container_name: auth-service
|
||||
environment:
|
||||
- DATABASE_URL=postgresql+asyncpg://auth_user:auth_pass123@auth-db:5432/auth_db
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
- RABBITMQ_URL=amqp://bakery:forecast123@rabbitmq:5672/
|
||||
- DEBUG=true
|
||||
- LOG_LEVEL=INFO
|
||||
ports:
|
||||
- "8001:8000"
|
||||
depends_on:
|
||||
auth-db:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- .:/app
|
||||
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
|
||||
|
||||
volumes:
|
||||
auth_db_data:
|
||||
121
services/auth/scripts/demo/seed_demo_users.py
Normal file
121
services/auth/scripts/demo/seed_demo_users.py
Normal file
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Seed Demo Users
|
||||
Creates demo user accounts for production demo environment
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
project_root = Path(__file__).parent.parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
import os
|
||||
os.environ.setdefault("AUTH_DATABASE_URL", os.getenv("AUTH_DATABASE_URL"))
|
||||
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
||||
from sqlalchemy import select
|
||||
import structlog
|
||||
import uuid
|
||||
|
||||
logger = structlog.get_logger()
|
||||
|
||||
# Demo user configurations (public credentials for prospects)
|
||||
DEMO_USERS = [
|
||||
{
|
||||
"id": "c1a2b3c4-d5e6-47a8-b9c0-d1e2f3a4b5c6",
|
||||
"email": "demo.individual@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi", # DemoSanPablo2024!
|
||||
"full_name": "María García López",
|
||||
"phone": "+34 912 345 678",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "owner",
|
||||
"is_active": True,
|
||||
"is_verified": True,
|
||||
"is_demo": True
|
||||
},
|
||||
{
|
||||
"id": "d2e3f4a5-b6c7-48d9-e0f1-a2b3c4d5e6f7",
|
||||
"email": "demo.central@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi", # DemoLaEspiga2024!
|
||||
"full_name": "Carlos Martínez Ruiz",
|
||||
"phone": "+34 913 456 789",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "owner",
|
||||
"is_active": True,
|
||||
"is_verified": True,
|
||||
"is_demo": True
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
async def seed_demo_users():
|
||||
"""Seed demo users into auth database"""
|
||||
|
||||
database_url = os.getenv("AUTH_DATABASE_URL")
|
||||
if not database_url:
|
||||
logger.error("AUTH_DATABASE_URL environment variable not set")
|
||||
return False
|
||||
|
||||
logger.info("Connecting to auth database", url=database_url.split("@")[-1])
|
||||
|
||||
engine = create_async_engine(database_url, echo=False)
|
||||
session_factory = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
try:
|
||||
async with session_factory() as session:
|
||||
# Import User model
|
||||
try:
|
||||
from app.models.users import User
|
||||
except ImportError:
|
||||
from services.auth.app.models.users import User
|
||||
from datetime import datetime, timezone
|
||||
|
||||
for user_data in DEMO_USERS:
|
||||
# Check if user already exists
|
||||
result = await session.execute(
|
||||
select(User).where(User.email == user_data["email"])
|
||||
)
|
||||
existing_user = result.scalar_one_or_none()
|
||||
|
||||
if existing_user:
|
||||
logger.info(f"Demo user already exists: {user_data['email']}")
|
||||
continue
|
||||
|
||||
# Create new demo user
|
||||
user = User(
|
||||
id=uuid.UUID(user_data["id"]),
|
||||
email=user_data["email"],
|
||||
hashed_password=user_data["password_hash"],
|
||||
full_name=user_data["full_name"],
|
||||
phone=user_data.get("phone"),
|
||||
language=user_data.get("language", "es"),
|
||||
timezone=user_data.get("timezone", "Europe/Madrid"),
|
||||
role=user_data.get("role", "owner"),
|
||||
is_active=user_data.get("is_active", True),
|
||||
is_verified=user_data.get("is_verified", True),
|
||||
created_at=datetime.now(timezone.utc),
|
||||
updated_at=datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
session.add(user)
|
||||
logger.info(f"Created demo user: {user_data['email']}")
|
||||
|
||||
await session.commit()
|
||||
logger.info("Demo users seeded successfully")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to seed demo users: {str(e)}")
|
||||
return False
|
||||
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = asyncio.run(seed_demo_users())
|
||||
sys.exit(0 if result else 1)
|
||||
Reference in New Issue
Block a user