"""Stable pseudonymous workspace identifier for telemetry payloads.The ADR requires every :class:`~core.telemetry.TelemetryEventPayload` tocarry a ``workspace_hash`` rather than the operator's profile id or NIF. Thismodule derives that hash deterministically from the local storage root path-- a value that already exists per-deployment, is never the taxpayer'sidentity, and is stable across repeated runs of the same installation withoutneeding any new persisted state.See Also: :func:`~core.telemetry.workspace_hash` Public facade export of this pseudonymous deployment-id helper. :class:`~core.telemetry.TelemetryEventPayload` Payload shape that carries the derived workspace hash. :class:`~core.config.Settings` Source of the local storage root used as the stable hash input."""from__future__importannotationsfrompathlibimportPathfrom..hashingimportsha256_hex__all__=["workspace_hash"]
[docs]defworkspace_hash(storage_root:Path)->str:"""Derive a stable, non-identifying pseudonym for this local deployment. Args: storage_root: The deployment's local storage root (``settings.aeat_local_storage_root``). Only its resolved path string is hashed; no file contents, profile data, or identity fields are read. Returns: A 64-character lowercase hex SHA-256 digest of the resolved storage root path. Two processes pointed at the same storage root produce the same hash; the hash cannot be reversed to recover the path or any taxpayer identity. """returnsha256_hex(str(Path(storage_root).resolve()).encode("utf-8"))