# ============================================================================== # Formeleon - Multi-tenant Form Generator # Author: Björn Runden # 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 }