Files
formeleon/utils/helpers.py
T

35 lines
1.0 KiB
Python

# ==============================================================================
# Formeleon - Multi-tenant Form Generator
# Author: Björn Runden <br@runden.net>
# Module: utils/helpers.py
# Description: Helper and utility functions for the application.
# ==============================================================================
import hashlib
from typing import Optional
from flask import request
def hash_ip(ip: str) -> str:
"""
Create a hash of an IP address for privacy-preserving storage.
:param ip: IP address string
:return: SHA256 hash of the IP
"""
if not ip:
return ''
return hashlib.sha256(ip.encode()).hexdigest()
def get_request_context() -> dict:
"""
Get standardized request context for audit logging.
:return: Dictionary with request context information
"""
return {
'ip_address': request.remote_addr,
'user_agent': request.user_agent.string if request.user_agent else None,
'path': request.path,
'method': request.method
}