Skip to content

backend

backend

CamBackend: memory-backend/1.1 served by CAM over its HTTP API.

Licence boundary. CAM is a separate program under its own licence. Marianne reaches it only across a process boundary, by HTTP on the wire format CAM documents, using the standard library alone. Nothing of CAM is imported, copied, vendored or declared as a dependency, and a test keeps it that way.

Identity. The gateway has already authorised every call before it gets here. The CAM key is the conductor's own, so until CAM ships stamped principals (delegated principals are not built) every Marianne principal appears to CAM as the one key's principal. This client does not invent principal stamping. The scope is passed through as CAM's scope.

What CAM offers today: declare, recall, and a readiness probe. verify, bind, forget, fetch, stream_facts and migration_ingest have no CAM operation yet, and each raises E7 capability_unsupported naming the operation. Recall has no cursor in CAM, so a response is trimmed to the per-call byte cap at a fact boundary on this side: omitted facts are reported by a page cursor with an empty token (nothing to resume) and an omitted count, and a single fact larger than the cap is listed as oversized_unit.

The API key is named by an environment variable or a file, read for each request, and never appears in a log, an exception message or a repr.

Classes

CamBackendConfig dataclass

CamBackendConfig(base_url, api_key_env='', api_key_file='', timeout_seconds=DEFAULT_TIMEOUT_SECONDS, allow_remote=False)

One CAM attachment. Holds the NAME of the key source, never the key.

CamBackend

CamBackend(config)

memory-backend/1.1 over CAM's HTTP API (declare, recall, health).

Source code in src/marianne/memory/backends/cam/backend.py
def __init__(self, config: CamBackendConfig) -> None:
    self._cfg = config
    parts = urllib.parse.urlsplit(config.base_url)
    self._https = parts.scheme == "https"
    self._host = parts.hostname or ""
    self._port = parts.port
    self._prefix = parts.path.rstrip("/")

Functions:

cam_backend_factory

cam_backend_factory(settings)

Build a :class:CamBackend from an attachment's settings:. Does no I/O.

Keys: base_url (required), api_key_env | api_key_file (exactly one; the NAME of a variable or a path, never the key), timeout_seconds, allow_remote.

Source code in src/marianne/memory/backends/cam/backend.py
def cam_backend_factory(settings: Mapping[str, Any]) -> CamBackend:
    """Build a :class:`CamBackend` from an attachment's ``settings:``. Does no I/O.

    Keys: ``base_url`` (required), ``api_key_env`` | ``api_key_file`` (exactly
    one; the NAME of a variable or a path, never the key), ``timeout_seconds``,
    ``allow_remote``.
    """
    allowed = {"base_url", "api_key_env", "api_key_file", "timeout_seconds", "allow_remote"}
    unknown = sorted(set(settings) - allowed)
    if unknown:
        raise _config_error(f"unknown cam setting(s) {unknown}; legal: {sorted(allowed)}")
    if not isinstance(settings.get("base_url"), str):
        raise _config_error("cam settings need base_url")
    for name in ("api_key_env", "api_key_file"):
        if name in settings and not isinstance(settings[name], str):
            raise _config_error(f"{name} must be a string")
    if "allow_remote" in settings and not isinstance(settings["allow_remote"], bool):
        raise _config_error("allow_remote must be true or false")
    return CamBackend(CamBackendConfig(
        base_url=settings["base_url"],
        api_key_env=settings.get("api_key_env", ""),
        api_key_file=settings.get("api_key_file", ""),
        timeout_seconds=settings.get("timeout_seconds", DEFAULT_TIMEOUT_SECONDS),
        allow_remote=settings.get("allow_remote", False),
    ))