This project synchronizes user and team hierarchy data between the EMMA employee database and the WebUI user database. It fetches employee data from an EMMA API, builds hierarchical team names, and updates user information in the WebUI database.
- Fetches employee data from EMMA backend API
- Builds hierarchical team names (e.g., "Samsung > SIRC > Platform > DevOps")
- Matches employees with WebUI users by email, username, or full name
- Updates the
user_detailstable in the monitoring database with immediate manager group information - Creates CSV reports for analysis
- Handles domain swaps between partner.samsung.com and samsung.com email addresses
- Identifies inactive users and truly unmatched users
- Restores missing webui_logs data from backup database
-
Clone the repository:
git clone <repository-url> cd user_sync_project
-
Ensure
uvis installed:pip install uv
-
Install dependencies:
uv sync
-
Set up environment variables:
cp .env.example .env # Edit .env and fill in your API tokens
Run the main sync script:
uv run python user_sync_main.pyIf the monitoring database is missing webui_logs data (e.g., due to a database restore), you can restore it from the backup database:
uv run python restore_missing_logs.pyThis compares webui_monitoring.db with webui_monitoring.db.copy and inserts any missing log records.
fetch_employees()- Fetches employee data from EMMA APIfetch_webui_users_from_api()- Retrieves users from WebUI API (preferred)fetch_webui_users_from_db()- Retrieves users from WebUI SQLite database (fallback)build_full_team_name_and_manager()- Constructs hierarchical team names and captures immediate manager infoprocess_employees()- Processes raw employee data with team hierarchiesupdate_user_details_table()- Updates the user_details table with immediate manager group informationcreate_webui_users_csv()- Generates a CSV report with user informationget_teams_for_users()- Looks up teams for specific user namesrestore_missing_logs.py- Standalone script to restore missing webui_logs from backup database
The script updates the user_details table in the monitoring database:
- Sets the
groupfield to the immediate manager's group name - Matches users by email address
- Preserves existing user information while updating only the group field
The script can be configured using environment variables. Copy .env.example to .env and fill in your values:
EMMA_API_TOKEN: API token for accessing the EMMA backendWEBUI_TOKEN: API token for accessing the WebUI APIWEBUI_DB_PATH: Path to the WebUI SQLite database (default: platform-specific path)WEBUI_MONITORING_DB_PATH: Path to the monitoring database with user_details table (default: /raid/tools/devops/logs/database/webui_monitoring.db)EMMA_API_URL: URL for the EMMA API endpoint (default: https://emma_backend.transchip.com/getAllEmps)WEBUI_API_URL: URL for the WebUI API (default: https://llm.transchip.com/api/v1/users/all)VERIFY_SSL: Whether to verify SSL certificates (default: true)
The script generates:
- Console output with synchronization statistics
- CSV reports on the desktop with user information
- Updates to the monitoring database user_details table
- Restored webui_logs data when using the restore script
- API tokens are stored in
.envfile (gitignored) - not hardcoded in the script - SSL verification is disabled for API calls (
verify=False) - should be addressed for production use - Database connections use direct file path access to network locations
If you encounter issues:
-
Database not found: Ensure network paths are properly mounted or set the
WEBUI_DB_PATHenvironment variable to point to your local database file. -
API connection failures: Check network connectivity and ensure the
EMMA_API_TOKENandWEBUI_TOKENin your.envfile are valid. -
SSL errors: The script currently disables SSL verification. For production use, proper SSL certificate handling should be implemented.