Repository navigation
Expand file tree
/
Copy pathsfapi.py
More file actions
70 lines (62 loc) · 2.77 KB
/
Copy pathsfapi.py
File metadata and controls
70 lines (62 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""
SpiderFoot REST API (modular entrypoint)
Delegates to the modular FastAPI app in spiderfoot/api/main.py
"""
from __future__ import annotations
import argparse
import uvicorn
from spiderfoot.api.main import app
# Re-export legacy API symbols for test and compatibility
from spiderfoot.api.dependencies import get_app_config, optional_auth
from spiderfoot.api.models import ScanRequest, WorkspaceRequest, ScanResponse, WorkspaceResponse
from spiderfoot.api.search_base import search_base
from spiderfoot.api.dependencies import app_config
from spiderfoot.db import SpiderFootDb
from spiderfoot.sflib.core import SpiderFoot
from spiderfoot.helpers import SpiderFootHelpers
from spiderfoot.api.utils import clean_user_input, build_excel
from spiderfoot.api.routers.websocket import WebSocketManager
import openpyxl
import logging
# For test patching and legacy compatibility
security = optional_auth
logger = logging.getLogger("sfapi")
Config = get_app_config().__class__ if get_app_config() else None
def main():
"""Main function to run the FastAPI application (modular)"""
parser = argparse.ArgumentParser(description='SpiderFoot REST API Server')
parser.add_argument('-H', '--host', default='127.0.0.1', help='Host to bind to')
parser.add_argument('-p', '--port', type=int, default=8001, help='Port to bind to')
parser.add_argument('-c', '--config', help='Configuration file path')
parser.add_argument('--reload', action='store_true', help='Enable auto-reload for development')
args = parser.parse_args()
# ── Startup dependency checks (microservice mode) ──
import os
service_role = os.environ.get("SF_SERVICE_ROLE", "api")
if os.environ.get("SF_DEPLOYMENT_MODE") in ("microservice", "microservices"):
try:
from spiderfoot.ops.startup_sequencer import StartupSequencer
sequencer = StartupSequencer(role=service_role)
result = sequencer.wait_for_ready_sync(timeout=60)
if not result.all_ready:
logger.error("Startup dependency check failed:\n%s", result.summary())
except Exception as exc:
logger.warning("Startup sequencer unavailable: %s", exc)
# ── Register shutdown handlers ──
try:
from spiderfoot.ops.graceful_shutdown import get_shutdown_coordinator
coordinator = get_shutdown_coordinator()
coordinator.install_signal_handlers()
logger.info("Graceful shutdown coordinator active (role=%s)", service_role)
except Exception as exc:
logger.warning("Shutdown coordinator unavailable: %s", exc)
uvicorn.run(
"spiderfoot.api.main:app",
host=args.host,
port=args.port,
reload=args.reload,
log_level="info"
)
if __name__ == "__main__":
main()