data seed feature for demo and prod

This commit is contained in:
2025-11-15 20:57:39 +01:00
parent 41439eed09
commit e3ed4a3295
17 changed files with 4574 additions and 1793 deletions

View File

@@ -1,25 +1,35 @@
# app/core/config.py
"""Summary description ....
"""
Application configuration using Pydantic Settings.
This module provides classes and functions for:
- ....
- ....
- ....
- Configuration management via environment variables
- Database settings
- JWT and authentication configuration
- Platform domain and multi-tenancy settings
- Admin initialization settings
Note: Environment detection is handled by app.core.environment module.
This module focuses purely on configuration storage and validation.
"""
from typing import List, Optional
from pydantic_settings import \
BaseSettings # This is the correct import for Pydantic v2
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""Settings class inheriting from BaseSettings that allows values to be overridden by environment variables."""
"""
Settings class for application configuration.
# Project information
project_name: str = "Ecommerce Backend API with Marketplace Support"
# Documentation
documentation_url: str = "http://localhost:8001" # Development default
Environment detection is delegated to app.core.environment.
This class focuses on configuration values only.
"""
# =============================================================================
# PROJECT INFORMATION
# =============================================================================
project_name: str = "Wizamart - Multi-Vendor Marketplace Platform"
version: str = "2.2.0"
# Clean description without HTML
description: str = """
@@ -34,49 +44,221 @@ class Settings(BaseSettings):
**Documentation:** Visit /documentation for complete guides
**API Testing:** Use /docs for interactive API exploration
"""
version: str = "2.2.0"
# Database
database_url: str = "sqlite:///./ecommerce.db"
# =============================================================================
# DATABASE
# =============================================================================
database_url: str = "sqlite:///./wizamart.db"
# JWT
# =============================================================================
# ADMIN INITIALIZATION (for init_production.py)
# =============================================================================
admin_email: str = "admin@wizamart.com"
admin_username: str = "admin"
admin_password: str = "admin123" # CHANGE IN PRODUCTION!
admin_first_name: str = "Platform"
admin_last_name: str = "Administrator"
# =============================================================================
# JWT AUTHENTICATION
# =============================================================================
jwt_secret_key: str = "change-this-in-production"
jwt_expire_hours: int = 24
jwt_expire_minutes: int = 30
# Middleware
allowed_hosts: List[str] = ["*"] # Configure for production
# API
# =============================================================================
# API SERVER
# =============================================================================
api_host: str = "0.0.0.0"
api_port: int = 8000
debug: bool = False
debug: bool = True
# =============================================================================
# DOCUMENTATION
# =============================================================================
documentation_url: str = "http://localhost:8001"
# =============================================================================
# MIDDLEWARE & SECURITY
# =============================================================================
allowed_hosts: List[str] = ["*"] # Configure for production
# Rate Limiting
rate_limit_enabled: bool = True
rate_limit_requests: int = 100
rate_limit_window: int = 3600
# Logging
# =============================================================================
# LOGGING
# =============================================================================
log_level: str = "INFO"
log_file: Optional[str] = None
# Platform domain configuration
platform_domain: str = "platform.com" # Your main platform domain
# =============================================================================
# PLATFORM DOMAIN CONFIGURATION
# =============================================================================
platform_domain: str = "wizamart.com"
# Custom domain features
allow_custom_domains: bool = True # Enable/disable custom domains
require_domain_verification: bool = True # Require DNS verification
allow_custom_domains: bool = True
require_domain_verification: bool = True
# SSL/TLS configuration for custom domains
ssl_provider: str = "letsencrypt" # or "cloudflare", "manual"
auto_provision_ssl: bool = False # Set to True if using automated SSL
auto_provision_ssl: bool = False
# DNS verification
dns_verification_prefix: str = "_wizamart-verify"
dns_verification_ttl: int = 3600
model_config = {"env_file": ".env"} # Updated syntax for Pydantic v2
# =============================================================================
# PLATFORM LIMITS
# =============================================================================
max_vendors_per_user: int = 5
max_team_members_per_vendor: int = 50
invitation_expiry_days: int = 7
# =============================================================================
# DEMO/SEED DATA CONFIGURATION
# =============================================================================
# Controls for demo data seeding
seed_demo_vendors: int = 3 # Number of demo vendors to create
seed_customers_per_vendor: int = 15 # Customers per vendor
seed_products_per_vendor: int = 20 # Products per vendor
seed_orders_per_vendor: int = 10 # Orders per vendor
model_config = {"env_file": ".env"}
# Singleton settings instance
settings = Settings()
# =============================================================================
# ENVIRONMENT UTILITIES - Module-level functions
# =============================================================================
# Import environment detection utilities
from app.core.environment import (
get_environment,
is_development,
is_production,
is_staging,
should_use_secure_cookies
)
def get_current_environment() -> str:
"""
Get current environment.
Convenience function that delegates to app.core.environment.
Use this when you need just the environment string.
"""
return get_environment()
def is_production_environment() -> bool:
"""
Check if running in production.
Convenience function that delegates to app.core.environment.
Use this for production-specific logic.
"""
return is_production()
def is_development_environment() -> bool:
"""
Check if running in development.
Convenience function that delegates to app.core.environment.
Use this for development-specific logic.
"""
return is_development()
def is_staging_environment() -> bool:
"""
Check if running in staging.
Convenience function that delegates to app.core.environment.
Use this for staging-specific logic.
"""
return is_staging()
# =============================================================================
# VALIDATION FUNCTIONS
# =============================================================================
def validate_production_settings() -> List[str]:
"""
Validate settings for production environment.
Returns:
List of warning messages if configuration is insecure
"""
warnings = []
if is_production():
# Check for default/insecure values
if settings.admin_password == "admin123":
warnings.append("⚠️ Using default admin password in production!")
if settings.jwt_secret_key == "change-this-in-production":
warnings.append("⚠️ Using default JWT secret key in production!")
if settings.debug:
warnings.append("⚠️ Debug mode enabled in production!")
if "*" in settings.allowed_hosts:
warnings.append("⚠️ ALLOWED_HOSTS is set to wildcard (*) in production!")
return warnings
def print_environment_info():
"""Print current environment configuration."""
print("\n" + "=" * 70)
print(f" ENVIRONMENT: {get_environment().upper()}")
print("=" * 70)
print(f" Database: {settings.database_url}")
print(f" Debug mode: {settings.debug}")
print(f" API port: {settings.api_port}")
print(f" Platform: {settings.platform_domain}")
print(f" Secure cookies: {should_use_secure_cookies()}")
print("=" * 70 + "\n")
# Show warnings if in production
if is_production():
warnings = validate_production_settings()
if warnings:
print("\n⚠️ PRODUCTION WARNINGS:")
for warning in warnings:
print(f" {warning}")
print()
# =============================================================================
# PUBLIC API
# =============================================================================
__all__ = [
# Settings singleton
'settings',
# Environment detection (re-exported from app.core.environment)
'get_environment',
'is_development',
'is_production',
'is_staging',
'should_use_secure_cookies',
# Convenience functions
'get_current_environment',
'is_production_environment',
'is_development_environment',
'is_staging_environment',
# Validation
'validate_production_settings',
'print_environment_info',
]