- Fix missing await on FocusGroup.get_messages() (N-L1) - Replace time.sleep with asyncio.sleep in key_theme_service and focus_group_service (N-P10) - Replace flask import with quart in focus_groups.py (N-S3) - Add logger.error before all 500 returns in focus_groups.py (N-P6) - Add logging to silent except blocks across routes (N-M10, N-M11) - Add @rate_limit to 6 remaining AI endpoints (N-H4) - Add --confirm flag to populate scripts before delete_many (S-H2) - Remove hardcoded Azure ID fallbacks from msal_service.py and msalConfig.ts (A-M2, F-H4) - Centralize make_serializable() in utils.py, remove duplicates from 3 route files (N-P7) - Replace all datetime.utcnow() with datetime.now(timezone.utc) across entire backend (M-L2) - AuthContext.tsx: only mark token validated on 200 success, not on non-401 errors (F-H2) - Rename authType → auth_type in auth.py (N-S4) - Add security_report.md and security_report.pdf with full 92-finding status Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
78 lines
2.5 KiB
Bash
Executable file
78 lines
2.5 KiB
Bash
Executable file
#!/bin/bash
|
|
# DEV-ONLY: MongoDB setup script for local development environments.
|
|
# DO NOT run in production.
|
|
|
|
# Define colors for readable output
|
|
GREEN="\033[0;32m"
|
|
RED="\033[0;31m"
|
|
YELLOW="\033[0;33m"
|
|
BLUE="\033[0;34m"
|
|
NC="\033[0m" # No Color
|
|
|
|
# S-C2: Block production environments
|
|
MONGO_HOST="${MONGO_HOST:-localhost}"
|
|
APP_ENV="${APP_ENV:-development}"
|
|
|
|
echo -e "${BLUE}===== MongoDB Setup Script (DEV ONLY) =====${NC}"
|
|
echo -e "This script sets up MongoDB for LOCAL DEVELOPMENT only."
|
|
echo ""
|
|
|
|
if [ "$APP_ENV" = "production" ]; then
|
|
echo -e "${RED}ERROR: This script must not be run in production (APP_ENV=production).${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$MONGO_HOST" != "localhost" ] && [ "$MONGO_HOST" != "127.0.0.1" ]; then
|
|
echo -e "${RED}ERROR: MONGO_HOST is set to '$MONGO_HOST'. This script only runs against localhost.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${YELLOW}WARNING: This script configures MongoDB for development (no authentication).${NC}"
|
|
echo -e "This is INSECURE and should NEVER be done on a production server."
|
|
echo ""
|
|
read -r -p "Continue? [y/N] " confirm
|
|
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
|
|
echo "Aborted."
|
|
exit 0
|
|
fi
|
|
|
|
# Check if MongoDB is running
|
|
if ! pgrep -x "mongod" > /dev/null; then
|
|
echo -e "${YELLOW}MongoDB is not running. Attempting to start MongoDB...${NC}"
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# macOS
|
|
brew services start mongodb-community || mongod --config /usr/local/etc/mongod.conf --fork
|
|
else
|
|
# Linux
|
|
sudo systemctl start mongod || sudo service mongod start
|
|
fi
|
|
|
|
# Wait for MongoDB to start
|
|
sleep 3
|
|
|
|
# Check again
|
|
if ! pgrep -x "mongod" > /dev/null; then
|
|
echo -e "${RED}Failed to start MongoDB. Please start it manually before running this script.${NC}"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}MongoDB started successfully.${NC}"
|
|
fi
|
|
else
|
|
echo -e "${GREEN}MongoDB is already running.${NC}"
|
|
fi
|
|
|
|
echo -e "${YELLOW}Creating semblance_db database and collections...${NC}"
|
|
|
|
# S-M3: Use mongosh instead of deprecated mongo CLI
|
|
mongosh --eval '
|
|
db = db.getSiblingDB("semblance_db");
|
|
db.createCollection("users");
|
|
db.createCollection("personas");
|
|
db.createCollection("focus_groups");
|
|
print("Collections created.");
|
|
'
|
|
|
|
echo -e "${GREEN}MongoDB setup completed. The database is now ready for development.${NC}"
|
|
echo -e "${YELLOW}Note: You may need to restart MongoDB for all changes to take effect:${NC}"
|
|
echo -e " - On macOS: brew services restart mongodb-community"
|
|
echo -e " - On Linux: sudo systemctl restart mongod"
|