feat: webhook event-model und shared-secret auth
This commit is contained in:
12
app/webhook/auth.py
Normal file
12
app/webhook/auth.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import hmac
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
|
||||
def verify_secret(provided: str | None, expected: str) -> None:
|
||||
"""Constant-time comparison of the shared secret.
|
||||
|
||||
Raises HTTPException(401) on mismatch or missing header.
|
||||
"""
|
||||
if provided is None or not hmac.compare_digest(provided, expected):
|
||||
raise HTTPException(status_code=401, detail="invalid or missing secret")
|
||||
14
app/webhook/models.py
Normal file
14
app/webhook/models.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from enum import Enum
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class EventType(str, Enum):
|
||||
CREATED = "created"
|
||||
UPDATED = "updated"
|
||||
DELETED = "deleted"
|
||||
|
||||
|
||||
class NextcloudEvent(BaseModel):
|
||||
event_type: EventType
|
||||
file_path: str
|
||||
file_name: str
|
||||
Reference in New Issue
Block a user