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] def generate_comment_hash(content: str) -> str: return hashlib.sha256(content.strip().encode()).hexdigest()
[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)
[docs] class CommentService:
[docs] @classmethod def is_duplicate(cls, comment: str) -> bool: return cache.get(generate_comment_hash(comment)) is not None
[docs] @classmethod def is_internal(cls, comment: str) -> bool: return comment.startswith("[INTERNAL]")