48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
|
|
import uvicorn
|
|
from option_mcp_common.auth import load_token_store_from_files
|
|
|
|
from option_mcp_common.logging import configure_root_logging
|
|
|
|
from mcp_sentiment.server import create_app
|
|
|
|
|
|
def _load_cryptopanic_key() -> str:
|
|
"""CER-002: preferisci file secret, fallback a env CRYPTOPANIC_API_KEY."""
|
|
creds_file = os.environ.get("SENTIMENT_CREDENTIALS_FILE")
|
|
if creds_file and os.path.exists(creds_file):
|
|
try:
|
|
with open(creds_file) as f:
|
|
creds = json.load(f)
|
|
key = (creds.get("cryptopanic_key") or "").strip()
|
|
if key and key.lower() not in ("placeholder", "changeme", "none"):
|
|
return key
|
|
except (OSError, json.JSONDecodeError):
|
|
pass
|
|
return (os.environ.get("CRYPTOPANIC_API_KEY") or "").strip()
|
|
|
|
|
|
configure_root_logging() # CER-P5-009
|
|
|
|
def main():
|
|
key = _load_cryptopanic_key()
|
|
token_store = load_token_store_from_files(
|
|
core_token_file=os.environ.get("CORE_TOKEN_FILE"),
|
|
observer_token_file=os.environ.get("OBSERVER_TOKEN_FILE"),
|
|
)
|
|
app = create_app(cryptopanic_key=key, token_store=token_store)
|
|
uvicorn.run(
|
|
app,
|
|
log_config=None, # CER-P5-009: delega al root JSON logger
|
|
host=os.environ.get("HOST", "0.0.0.0"),
|
|
port=int(os.environ.get("PORT", "9014")),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|