Feature/windows notifications #9

Merged
florian merged 3 commits from feature/windows-notifications into main 2026-10-13 08:14:52 +00:00
5 changed files with 54 additions and 21 deletions
Showing only changes of commit 4e088547ff - Show all commits

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
[tool.ruff]
line-length = 120
target-version = "py312"
[tool.ruff.lint]
select = [
"E", "F", # pycodestyle errors, pyflakes (unused imports/variables, undefined names)
"I", # import sorting (replaces isort)
"B", # bugbear: likely bugs
"ASYNC", # async mistakes
"RUF006", # un-referenced asyncio.create_task (tasks can be garbage-collected)
]
ignore = ["E501"]
[tool.ruff.lint.isort]
known-first-party = ["db_module", "metrics_server", "rabbitmq_handler", "secret_manager",
"simple_logger_handler", "uvicorn_logger_config", "validator"]
[tool.ruff.format]
indent-style = "tab"
[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = [
"fastapi.Depends",
"fastapi.Query",
"fastapi.Header",
"fastapi.Body",
"fastapi.Security",
]
+1
View File
@@ -0,0 +1 @@
ruff==0.17.0
+21 -19
View File
@@ -1,23 +1,25 @@
from fastapi import FastAPI, Depends, HTTPException, Request
import asyncio
import os
import uuid
from contextlib import asynccontextmanager
from hashlib import sha256
from typing import List, Optional
import httpx
import uvicorn
from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.responses import JSONResponse
from fastapi.security.api_key import APIKeyHeader
from starlette.exceptions import HTTPException as StarletteHTTPException
from typing import Optional,List
from pydantic import BaseModel
from validator import is_valid_platform,is_valid_token,verify_api_key
from secret_manager.fernet_encryption import encrypt_token
from secret_manager import cleanup_secret_files, return_credentials
from db_module import get_db, create_connection_pool, close_connection_pool, start_healthcheck_thread
from simple_logger_handler import setup_logger, LOG_LEVEL
import uuid
from hashlib import sha256
import uvicorn
from contextlib import asynccontextmanager
from starlette.exceptions import HTTPException as StarletteHTTPException
from db_module import close_connection_pool, create_connection_pool, get_db, start_healthcheck_thread
from metrics_server import REQUEST_COUNTER
import asyncio
from secret_manager import cleanup_secret_files, return_credentials
from secret_manager.fernet_encryption import encrypt_token
from simple_logger_handler import LOG_LEVEL, setup_logger
from uvicorn_logger_config import LOGGING_CONFIG
import httpx
import os
from validator import is_valid_platform, is_valid_token, verify_api_key
logger = setup_logger(__name__)
api_key_header = APIKeyHeader(name="X-API-Key")
@@ -207,7 +209,7 @@ def register_token(
logger.info(f"[FastAPI] Success: Registering token for user_id={user_id}, platform={request_data.platform}")
except Exception as e:
logger.exception(f"[FastAPI] Failed to register token for user_id={user_id}: {e}")
raise HTTPException(status_code=500, detail=str(e))
raise HTTPException(status_code=500, detail=str(e)) from e
return {"status":"registered"}
@@ -230,7 +232,7 @@ def unregister_token(
""", ('expired', hashed_token))
except Exception as e:
logger.exception(f"[FastAPI] Failed to unregister token for user_id={user_id}: {e}")
raise HTTPException(status_code=500, detail=str(e))
raise HTTPException(status_code=500, detail=str(e)) from e
logger.info(f"[FastAPI] Success: Unregistering token for user_id={user_id}, platform={request_data.platform}")
return {"status":"unregistered"}
@@ -248,10 +250,10 @@ async def pull_notifications(
data = PullResponse.model_validate(resp.json())
except httpx.HTTPStatusError as e:
logger.error(f"[FastAPI] Upstream returned {e.response.status_code} for user_id={user_id}")
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable")
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable") from e
except ValueError as e:
logger.error(f"[FastAPI] Backend-API-Internal call failed with ValueError for user_id={user_id}: {e!r}")
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable")
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable") from e
logger.info(f"[FastAPI] Returning {len(data.messages)} message(s) for user_id={user_id}, has_more={data.has_more}")
return data
+1 -1
View File
@@ -1,5 +1,5 @@
from fastapi import FastAPI, Response
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, Counter
from prometheus_client import CONTENT_TYPE_LATEST, Counter, generate_latest
metrics_api = FastAPI(title="Metrics Server", description="Prometheus metrics endpoint")
+3 -1
View File
@@ -1,5 +1,7 @@
from argon2 import PasswordHasher
import re
from argon2 import PasswordHasher
from simple_logger_handler import setup_logger
logger = setup_logger(__name__)