Upgraded modules #8
No files matched your search
+27
-27
@@ -1,34 +1,34 @@
|
|||||||
--extra-index-url https://git.gansejunge.com/api/packages/notifier/pypi/simple/
|
--extra-index-url https://git.gansejunge.com/api/packages/notifier/pypi/simple/
|
||||||
aio-pika==9.5.7
|
aio-pika==10.1.1
|
||||||
aiormq==6.9.0
|
aiormq==7.2.2
|
||||||
annotated-types==0.7.0
|
annotated-doc==0.0.5
|
||||||
anyio==4.11.0
|
annotated-types==0.8.0
|
||||||
|
anyio==4.15.1
|
||||||
argon2-cffi==25.1.0
|
argon2-cffi==25.1.0
|
||||||
argon2-cffi-bindings==25.1.0
|
argon2-cffi-bindings==26.1.0
|
||||||
certifi==2026.7.22
|
certifi==2026.7.22
|
||||||
cffi==2.0.0
|
cffi==2.1.1
|
||||||
click==8.3.0
|
click==8.5.0
|
||||||
fastapi==0.119.0
|
fastapi==0.143.3
|
||||||
h11==0.16.0
|
h11==0.16.0
|
||||||
httpcore==1.0.9
|
httpcore==1.0.9
|
||||||
httpx==0.28.1
|
httpx==0.28.1
|
||||||
idna==3.11
|
idna==3.20
|
||||||
lib-db-module==0.2.0
|
lib-db-module==0.3.0
|
||||||
lib-secret-manager==0.2.0
|
lib-secret-manager==0.3.1
|
||||||
lib-uvicorn-config==0.2.0
|
multidict==7.1.0
|
||||||
multidict==6.7.0
|
|
||||||
mysql-connector-python==9.4.0
|
mysql-connector-python==9.4.0
|
||||||
pamqp==3.3.0
|
opentelemetry-api==1.45.1
|
||||||
prometheus_client==0.23.1
|
pamqp==4.0.1
|
||||||
propcache==0.4.1
|
prometheus_client==0.26.0
|
||||||
pycparser==2.23
|
propcache==0.5.4
|
||||||
pydantic==2.12.0
|
pycparser==3.11
|
||||||
pydantic_core==2.41.1
|
pydantic==2.14.1
|
||||||
python-json-logger==4.0.0
|
pydantic_core==2.50.1
|
||||||
simple-logger-handler==0.1.0
|
python-json-logger==4.2.0
|
||||||
sniffio==1.3.1
|
simple-logger-handler==0.2.1
|
||||||
starlette==0.48.0
|
starlette==1.8.0
|
||||||
typing-inspection==0.4.2
|
typing-inspection==0.4.4
|
||||||
typing_extensions==4.15.0
|
typing_extensions==4.16.0
|
||||||
uvicorn==0.37.0
|
uvicorn==0.54.0
|
||||||
yarl==1.22.0
|
yarl==1.25.1
|
||||||
+17
-18
@@ -16,14 +16,13 @@ from metrics_server import REQUEST_COUNTER
|
|||||||
from rabbitmq_handler import RabbitMQProducer
|
from rabbitmq_handler import RabbitMQProducer
|
||||||
from secret_manager import cleanup_secret_files
|
from secret_manager import cleanup_secret_files
|
||||||
from simple_logger_handler import LOG_LEVEL, setup_logger
|
from simple_logger_handler import LOG_LEVEL, setup_logger
|
||||||
from uvicorn_logger_config import LOGGING_CONFIG
|
|
||||||
from validator import verify_api_key
|
from validator import verify_api_key
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
api_key_header_internal = APIKeyHeader(name="X-API-Key-Internal")
|
api_key_header_internal = APIKeyHeader(name="X-API-Key-Internal")
|
||||||
|
|
||||||
class Notification(BaseModel):
|
class Notification(BaseModel):
|
||||||
user_id : int = Field(gt=0) #ToDo fix among all services
|
user_id : int = Field(gt=0)
|
||||||
message : Dict
|
message : Dict
|
||||||
|
|
||||||
class PullResponse(BaseModel):
|
class PullResponse(BaseModel):
|
||||||
@@ -36,12 +35,12 @@ class PullRequest(BaseModel):
|
|||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
logger.info("Starting application...")
|
logger.info("[FastAPI] Starting application...")
|
||||||
|
|
||||||
logger.info("Creating MySQL connection pool...")
|
logger.info("[FastAPI] Creating MySQL connection pool...")
|
||||||
create_connection_pool("ApiInternalPool")
|
create_connection_pool("ApiInternalPool")
|
||||||
start_healthcheck_thread()
|
start_healthcheck_thread()
|
||||||
logger.info("MySQL healthcheck thread started.")
|
logger.info("[FastAPI] MySQL healthcheck thread started.")
|
||||||
|
|
||||||
producer = RabbitMQProducer()
|
producer = RabbitMQProducer()
|
||||||
PULL_SERVICE_URL = os.getenv(
|
PULL_SERVICE_URL = os.getenv(
|
||||||
@@ -50,7 +49,7 @@ async def lifespan(app: FastAPI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info("Starting RabbitMQ producer...")
|
logger.info("[FastAPI] Starting RabbitMQ producer...")
|
||||||
await producer.connect()
|
await producer.connect()
|
||||||
app.state.rmq_producer = producer
|
app.state.rmq_producer = producer
|
||||||
logger.info("[FastAPI] RabbitMQ producer initialized.")
|
logger.info("[FastAPI] RabbitMQ producer initialized.")
|
||||||
@@ -71,10 +70,10 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
logger.info("Closing RabbitMQ producer...")
|
logger.info("[FastAPI] Closing RabbitMQ producer...")
|
||||||
await producer.close()
|
await producer.close()
|
||||||
|
|
||||||
logger.info("Closing MySQL connection pool...")
|
logger.info("[FastAPI] Closing MySQL connection pool...")
|
||||||
close_connection_pool()
|
close_connection_pool()
|
||||||
|
|
||||||
await app.state.http_client.aclose()
|
await app.state.http_client.aclose()
|
||||||
@@ -96,11 +95,11 @@ async def prometheus_middleware(request: Request, call_next):
|
|||||||
status = response.status_code
|
status = response.status_code
|
||||||
logger.debug(f"Request processed with status: {status}")
|
logger.debug(f"Request processed with status: {status}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Exception during request processing: {e}")
|
logger.exception(f"[FastAPI] Exception during request processing: {e}")
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
REQUEST_COUNTER.labels(request.method, request.url.path, status).inc()
|
REQUEST_COUNTER.labels(request.method, request.url.path, status).inc()
|
||||||
logger.debug(f"Prometheus counter incremented: {request.method} {request.url.path} {status}")
|
logger.debug(f"[FastAPI] Prometheus counter incremented: {request.method} {request.url.path} {status}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def verify_api_key_dependency_internal(db=Depends(get_db), api_key: str = Depends(api_key_header_internal)) -> str:
|
def verify_api_key_dependency_internal(db=Depends(get_db), api_key: str = Depends(api_key_header_internal)) -> str:
|
||||||
@@ -109,9 +108,9 @@ def verify_api_key_dependency_internal(db=Depends(get_db), api_key: str = Depend
|
|||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
for program_name, hashed_key in rows:
|
for program_name, hashed_key in rows:
|
||||||
if verify_api_key(api_key=api_key, hashed=hashed_key):
|
if verify_api_key(api_key=api_key, hashed=hashed_key):
|
||||||
logger.debug(f"API key verified for program: {program_name}")
|
logger.debug(f"[FastAPI] API key verified for program: {program_name}")
|
||||||
return program_name
|
return program_name
|
||||||
logger.warning("Internal API key verification failed")
|
logger.warning("[FastAPI] Internal API key verification failed")
|
||||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||||
|
|
||||||
@api.exception_handler(StarletteHTTPException)
|
@api.exception_handler(StarletteHTTPException)
|
||||||
@@ -135,8 +134,8 @@ async def receive_notifications(
|
|||||||
program_name: str = Depends(verify_api_key_dependency_internal)
|
program_name: str = Depends(verify_api_key_dependency_internal)
|
||||||
):
|
):
|
||||||
|
|
||||||
logger.info(f"Received notifcation data from {program_name} for RMQ")
|
logger.info(f"[FastAPI] Received notifcation data from {program_name} for RMQ")
|
||||||
logger.debug(f"Notification data: {notification_data}")
|
logger.debug(f"[FastAPI] Notification data: {notification_data}")
|
||||||
await request.app.state.rmq_producer.publish(
|
await request.app.state.rmq_producer.publish(
|
||||||
notification_data.user_id,
|
notification_data.user_id,
|
||||||
notification_data.message
|
notification_data.message
|
||||||
@@ -168,15 +167,15 @@ async def pull_notifications(
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
async def start_servers():
|
async def start_servers():
|
||||||
logger.debug("Starting FastAPI and metrics servers")
|
logger.info("[Server] Starting main API (port 8101) and metrics server (port 9000)...")
|
||||||
config_main = uvicorn.Config("main:api", host="0.0.0.0", port=8101, log_level=LOG_LEVEL.lower(), log_config=LOGGING_CONFIG)
|
config_main = uvicorn.Config("main:api", host="0.0.0.0", port=8101, log_level=LOG_LEVEL.lower(), log_config=None)
|
||||||
config_metrics = uvicorn.Config("metrics_server:metrics_api", host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(), log_config=LOGGING_CONFIG)
|
config_metrics = uvicorn.Config("metrics_server:metrics_api", host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(), log_config=None)
|
||||||
|
|
||||||
server_main = uvicorn.Server(config_main)
|
server_main = uvicorn.Server(config_main)
|
||||||
server_metrics = uvicorn.Server(config_metrics)
|
server_metrics = uvicorn.Server(config_metrics)
|
||||||
|
|
||||||
await asyncio.gather(server_main.serve(), server_metrics.serve())
|
await asyncio.gather(server_main.serve(), server_metrics.serve())
|
||||||
logger.debug("Servers started")
|
logger.info("[Server] Both servers have stopped.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(start_servers())
|
asyncio.run(start_servers())
|
||||||
@@ -8,7 +8,7 @@ from urllib.parse import quote
|
|||||||
import aio_pika
|
import aio_pika
|
||||||
from aio_pika.exceptions import AMQPException, DeliveryError
|
from aio_pika.exceptions import AMQPException, DeliveryError
|
||||||
|
|
||||||
from secret_manager import return_credentials
|
from secret_manager import get_secret
|
||||||
from simple_logger_handler import setup_logger
|
from simple_logger_handler import setup_logger
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
@@ -50,8 +50,8 @@ class RabbitMQProducer:
|
|||||||
self._ready = asyncio.Event()
|
self._ready = asyncio.Event()
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
username = return_credentials("/etc/secrets/rmq_username")
|
username = get_secret(os.getenv("RMQ_USERNAME",""),"/etc/secrets/rmq_username")
|
||||||
password = return_credentials("/etc/secrets/rmq_password")
|
password = get_secret(os.getenv("RMQ_PASSWORD",""),"/etc/secrets/rmq_password")
|
||||||
url = (
|
url = (
|
||||||
f"amqp://{quote(username, safe='')}:{quote(password, safe='')}"
|
f"amqp://{quote(username, safe='')}:{quote(password, safe='')}"
|
||||||
f"@{self.rmq_host}/{quote(self.rmq_vhost, safe='')}"
|
f"@{self.rmq_host}/{quote(self.rmq_vhost, safe='')}"
|
||||||
|
|||||||
Reference in new issue
Block a user