utils.py 741 B

1234567891011121314151617181920212223242526
  1. import hashlib
  2. from typing import List, Optional
  3. from issues.models import EventType
  4. def default_hash_input(title: str, culprit: str, type: EventType) -> str:
  5. return title + culprit + str(type)
  6. def generate_hash(
  7. title: str, culprit: str, type: EventType, extra: Optional[List[str]] = None
  8. ) -> str:
  9. """Generate insecure hash used for grouping issues"""
  10. if extra:
  11. hash_input = "".join(
  12. [
  13. default_hash_input(title, culprit, type)
  14. if part == "{{ default }}"
  15. else part
  16. for part in extra
  17. ]
  18. )
  19. else:
  20. hash_input = default_hash_input(title, culprit, type)
  21. return hashlib.md5(hash_input.encode()).hexdigest()