stats: use persistent UUID identifier

This commit is contained in:
RhodeCode Admin 2025-11-28 11:32:42 +01:00
parent f172aa4144
commit b452f0598e

View file

@ -900,9 +900,27 @@ def generate_platform_uuid():
Generates platform UUID based on it's name
"""
import platform
import uuid
def generate_stable_v5_uuid():
"""Generates a stable, repeatable Version 5 UUID based on the MAC address."""
# Use a fixed, arbitrary UUID as the namespace for the machine IDs.
# This ensures that all generated IDs are distinct from standard UUID namespaces.
machine_namespace = uuid.UUID("10000000-0000-0000-0000-000000000001")
# Get the 48-bit MAC address as an integer
mac_int = uuid.getnode()
# Convert MAC address integer to a string name
mac_str = str(mac_int)
# Create the Version 5 UUID (SHA-1 hash of Namespace + MAC string)
stable_uuid = uuid.uuid5(machine_namespace, mac_str)
return str(stable_uuid)
try:
uuid_list = [platform.platform()]
uuid_list = [platform.platform(), generate_stable_v5_uuid()]
return sha256_safe(":".join(uuid_list))
except Exception as e:
log.error("Failed to generate host uuid: %s", e)