Merge pull request #45 from bellingcat/dev

Merge pull request #44 from bellingcat/main v0.7.1
This commit is contained in:
Miguel Sozinho Ramalho
2024-10-28 15:20:28 +00:00
committed by GitHub
9 changed files with 12 additions and 12 deletions

3
.gitignore vendored
View File

@@ -22,4 +22,5 @@ htmlcov
local_archive
local_archive_test
*db-wal
*db-shm
*db-shm
copy-files.sh

View File

@@ -47,7 +47,7 @@ services:
- web
- redis
healthcheck:
test: ["CMD", "pipenv", "run", "celery", "-A", "worker.celery", "status"]
test: ["CMD", "pipenv", "run", "celery", "-A", "worker.main.celery", "status"]
interval: 30s
timeout: 10s
retries: 3

View File

@@ -1,4 +1,4 @@
VERSION = "0.7.0"
VERSION = "0.7.1"
API_DESCRIPTION = """
#### API for the Auto-Archiver project, a tool to archive web pages and Google Sheets.

View File

@@ -5,15 +5,14 @@ from fastapi import Request
# logging configurations
logger.add("logs/api_logs.log", retention="30 days", rotation="3 days")
error_logger = logger.add("logs/error_logs.log", retention="30 days")
logger.add("logs/error_logs.log", retention="30 days", level="ERROR")
def log_error(e: Exception, traceback_str: str = None, extra:str = ""):
# EXCEPTION_COUNTER.labels(type(e).__name__).inc()
if not traceback_str: traceback_str = traceback.format_exc()
if extra: extra = f"{extra}\n"
logger.error(f"{extra}{e.__class__.__name__}: {e}")
error_logger.error(f"{extra}{e.__class__.__name__}: {e}\n{traceback_str}")
logger.error(f"{extra}{e.__class__.__name__}: {e}\n{traceback_str}")
async def logging_middleware(request: Request, call_next):
try:

View File

@@ -1,9 +1,11 @@
from functools import lru_cache
from sqlalchemy import Engine, create_engine, event
from sqlalchemy.orm import sessionmaker
from shared.settings import get_settings
from contextlib import contextmanager
@lru_cache
def make_engine(database_url: str):
engine = create_engine(database_url, connect_args={"check_same_thread": False})

View File

@@ -26,7 +26,8 @@ def mock_settings():
def test_db(get_settings: Settings):
from db.database import make_engine
from db import models
make_engine.cache_clear()
engine = make_engine(get_settings.DATABASE_PATH)
fs = get_settings.DATABASE_PATH.replace("sqlite:///", "")

View File

@@ -1,5 +1,3 @@
import json
from unittest.mock import patch

View File

@@ -51,7 +51,7 @@ def app_factory(settings = get_settings()):
app.include_router(interoperability_router)
# prometheus exposed in /metrics with authentication
Instrumentator(should_group_status_codes=False, excluded_handlers=["/metrics", "/health"]).instrument(app).expose(app, dependencies=[Depends(token_api_key_auth)])
Instrumentator(should_group_status_codes=False, excluded_handlers=["/metrics", "/health", "/openapi.json", "/favicon.ico"]).instrument(app).expose(app, dependencies=[Depends(token_api_key_auth)])
local_dir = settings.SERVE_LOCAL_ARCHIVE
if not os.path.isdir(local_dir) and os.path.isdir(local_dir.replace("/app", ".")):

View File

@@ -15,10 +15,9 @@ def secure_compare(token, api_key):
# Factory method to create an authentication dependency for a specific key
def api_key_auth(api_key):
assert len(api_key) >= 20, "Invalid API key, must be at least 20 chars"
async def auth(bearer: HTTPAuthorizationCredentials = Depends(bearer_security), auto_error=True):
assert len(api_key) >= 20, "Invalid API key, must be at least 20 chars"
is_correct = secure_compare(bearer.credentials, api_key)
if is_correct: return True