FactsDB/factsdb/main.py
Jarian Cottingham f4b84cc412 fix: security hardening, code fixes, and infrastructure improvements
- Replace eval() with json.loads() in database.py (RCE fix)
- Use json.dumps() for safe storage of list fields
- Add API key authentication middleware
- Remove hardcoded credentials, require env vars
- Disable Flask debug mode
- Restrict FTP homedir to /app/data with read-only perms
- Fix threading: Lock -> RLock, add WAL mode
- Fix API calls to use correct DatabaseManager methods
- Fix main.py FTP method names
- Fix click.click.echo typo
- Implement scheduler _run_all_jobs
- Add __main__.py for module execution
- Pin dependency versions
- Use .env vars in docker-compose, read-only DB for FTP
- Implement AI text chunking with overlap windows
- Add schema validation for AI responses
- Skip unsupported file types instead of fallback
2026-07-05 13:05:08 +00:00

76 lines
2.4 KiB
Python

"""
Main entry point for FactsDB service
"""
import sys
import os
from .config import Config
from .database import DatabaseManager
from .scheduler import get_scheduler
from .ftp_server import FTPServerManager
def main():
"""Main entry point"""
if len(sys.argv) < 2:
print("Usage: python -m factsdb.main [command]")
print("Commands:")
print(" cli - Start CLI interface")
print(" api - Start REST API server")
print(" ftp - Start FTP server")
print(" scheduler - Start scheduler")
print(" onboard - Onboard a directory (use with --directory and --table-name)")
return
command = sys.argv[1]
config = Config()
if command == "cli":
# Import and run CLI
from .cli import cli
cli()
elif command == "api":
# Start API server
from .api import app
print("Starting FactsDB REST API server...")
app.run(debug=False, host='0.0.0.0', port=5000)
elif command == "ftp":
# Start FTP server
ftp_manager = FTPServerManager(config)
# Add current directory as allowed directory
current_dir = os.path.abspath('.')
ftp_manager.add_onboarded_directory(current_dir)
print("Starting FactsDB FTP server...")
try:
ftp_manager.start()
print("FTP Server running. Press Ctrl+C to stop.")
try:
import time
while True:
time.sleep(1)
except KeyboardInterrupt:
ftp_manager.stop()
print("FTP Server stopped.")
except Exception as e:
print(f"Error starting FTP server: {e}")
elif command == "scheduler":
# Start scheduler
scheduler = get_scheduler(config)
scheduler.start()
print("FactsDB Scheduler started.")
print("Press Ctrl+C to stop.")
try:
import time
while True:
time.sleep(1)
except KeyboardInterrupt:
scheduler.stop()
print("Scheduler stopped.")
elif command == "onboard":
# This would be handled by CLI
print("Use 'python -m factsdb.cli onboard' for onboarding")
else:
print(f"Unknown command: {command}")
print("Use 'python -m factsdb.main cli' for CLI interface")
if __name__ == "__main__":
main()