Source code for ferrosoft.apps.ticketing.api.service
# Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
import hashlib
import hmac
from django.core.cache import cache
[docs]
class WebhookSignatureValidator:
def __init__(self, secret_key: str):
self.secret_key = secret_key
[docs]
@classmethod
def from_django_settings(cls):
from django.conf import settings
return cls(getattr(settings, "TAIGA_CONFIG", {}).get("SECRET_KEY"))
[docs]
def is_valid(self, signature: str, body: bytes) -> bool:
computed_signature = hmac.new(
self.secret_key.encode(), body, hashlib.sha1
).hexdigest()
return hmac.compare_digest(computed_signature, signature)