Skip to content

consent

consent

Explicit user consent, read fresh at each collection/submission boundary.

Classes

ConsentState

Bases: str, Enum

Missing or unreadable records never imply permission.

ConsentRecord

ConsentRecord(path=None)

Atomic, private consent record independent of any score's contents.

Do not cache this object’s state: long-running daemons must observe revocation. A caller may override the path for isolated tests, never via score YAML.

Source code in src/marianne/telemetry/consent.py
def __init__(self, path: Path | None = None) -> None:
    self.path = path if path is not None else Path.home() / ".marianne/telemetry-consent.json"
Attributes
state property
state

Return current on-disk consent, failing closed on malformed data.

consent_id property
consent_id

Opaque identifier for this grant; absent after revocation.

Methods:
grant
grant()

Persist explicit permission, retaining the ID of an existing grant.

Source code in src/marianne/telemetry/consent.py
def grant(self) -> None:
    """Persist explicit permission, retaining the ID of an existing grant."""
    with self.collection_transaction():
        self._write(ConsentState.GRANTED, self.consent_id or str(uuid4()))
collection_transaction
collection_transaction()

Serialize grant/revoke with authorized appends across every spool.

Always acquire this before a spool lock. Revocation then waits for any already-authorized append and no append can finish after revoke returns.

Source code in src/marianne/telemetry/consent.py
@contextmanager
def collection_transaction(self) -> Iterator[None]:
    """Serialize grant/revoke with authorized appends across every spool.

    Always acquire this before a spool lock. Revocation then waits for any
    already-authorized append and no append can finish after revoke returns.
    """
    self.path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
    lock_path = self.path.with_name(self.path.name + ".lock")
    fd = os.open(lock_path, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600)
    try:
        fcntl.flock(fd, fcntl.LOCK_EX)
        yield
    finally:
        os.close(fd)
revoke
revoke(*, spool_path=None, purge=False)

Stop collection first, then optionally remove the supplied local spool.

Source code in src/marianne/telemetry/consent.py
def revoke(self, *, spool_path: Path | None = None, purge: bool = False) -> None:
    """Stop collection first, then optionally remove the supplied local spool."""
    with self.collection_transaction():
        self._write(ConsentState.REVOKED, None)
        if purge and spool_path is not None:
            self.purge_spool(spool_path)
purge_spool staticmethod
purge_spool(path)

Remove staged envelopes; a missing spool is already purged.

Source code in src/marianne/telemetry/consent.py
@staticmethod
def purge_spool(path: Path) -> None:
    """Remove staged envelopes; a missing spool is already purged."""
    from marianne.telemetry.spool import TelemetrySpool

    TelemetrySpool(path).purge()