Skip to content

API Reference parrot.vault_targets

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.vault_targets

View source

Vault protected targets for ai-parrot DocumentDB collections (FEAT-099).

Registered under the navigator_session.vault_targets entry-point group so navigator-vault rotation and v1 → v2 migration cover parrot credentials:

=================== ========================== ========================== Collection Identity Encrypted field =================== ========================== ========================== user_credentials (user_id, name) credential user_llm_keys (user_id, provider) api_key =================== ========================== ==========================

Values are stored base64-encoded; rows expose the decoded bytes so the vault kernel can read envelope headers, and writes re-encode them unchanged.

Quarantine moves the document to <collection>_quarantine (with quarantined_at, reason, run_id) and removes it from the source collection; restore_raw puts the original document back and drops the quarantine copy.

Alias CREDENTIAL_FIELD

Re-exported from parrot.security.credentials_utils.CREDENTIAL_FIELD.

Alias CREDENTIAL_PURPOSE

Re-exported from parrot.security.credentials_utils.CREDENTIAL_PURPOSE.

Class DocumentDbTarget

Base for DocumentDB collections holding one sealed field per document.

Parameter Type Default Description
docdb_factory Callable[[], Any] Callable returning a DocumentDb async context manager.

Attributes:

Attribute Type Description
name str
collection str
purpose str
identity_fields tuple[str, ...]
encrypted_field str
encrypted_fields tuple[str, ...]

Method DocumentDbTarget.context_for

Context binding field of row (see credentials_utils).

context_for(row: Any, field: str)

Parameter Type Default Description
row Any
field str

Method DocumentDbTarget.ref_for

ref_for(identity: Mapping[str, Any]) -> str

Parameter Type Default Description
identity Mapping[str, Any]

Returns: str

Method DocumentDbTarget.iter_batches

Iterate documents in deterministic batches (whole collection read once).

Credential collections are small (a few documents per user), so the documents are read once, sorted by their identity, and handed out in batches; DocumentDB drops _id on read, so rows are addressed by their natural key.

iter_batches(batch_size: int) -> AsyncIterator[list[VaultRow]]

Parameter Type Default Description
batch_size int

Returns: AsyncIterator[list[VaultRow]]

Method DocumentDbTarget.transaction

No-op: DocumentDB writes here are per-document.

transaction() -> AsyncIterator[None]

Returns: AsyncIterator[None]

Method DocumentDbTarget.write

Replace the sealed field of row and record key_version.

write(row: Any, blobs: Mapping[str, Optional[bytes]], key_version: int) -> None

Parameter Type Default Description
row Any
blobs Mapping[str, Optional[bytes]]
key_version int

Raises:

  • ValueError — If blobs names unknown fields or is empty.
  • LookupError — If the document no longer exists.

Method DocumentDbTarget.quarantine

Move the document to <collection>_quarantine (keeping its value).

quarantine(row: Any, reason: str, run_id: str) -> None

Parameter Type Default Description
row Any
reason str
run_id str

Method DocumentDbTarget.export_raw

Export every document as stored (value base64, identity, metadata).

export_raw(sink: BackupSink) -> int

Parameter Type Default Description
sink BackupSink

Returns: int

Method DocumentDbTarget.restore_raw

Restore documents (including quarantined ones) from a backup.

The stored document is replaced, not merged, so fields added by the migration (e.g. updated_at) do not survive a rollback.

restore_raw(source: BackupSource) -> int

Parameter Type Default Description
source BackupSource

Returns: int

Method DocumentDbTarget.to_backup_record

JSON-safe snapshot of a document (sealed value stays sealed).

to_backup_record(row: VaultRow) -> dict

Parameter Type Default Description
row VaultRow

Returns: dict

Alias LLM_KEY_FIELD

Re-exported from parrot.security.credentials_utils.LLM_KEY_FIELD.

Alias LLM_KEY_PURPOSE

Re-exported from parrot.security.credentials_utils.LLM_KEY_PURPOSE.

Attribute QUARANTINE_SUFFIX

Class RedisDocumentTarget

DocumentDbTarget whose I/O goes through RedisDocumentStore (FEAT-878). Same refs, records and contexts.

Parameter Type Default Description
documents Any
quarantine Any

Method RedisDocumentTarget.iter_batches

Iterate Redis documents in deterministic identity order.

iter_batches(batch_size: int) -> AsyncIterator[list[VaultRow]]

Parameter Type Default Description
batch_size int

Returns: AsyncIterator[list[VaultRow]]

Method RedisDocumentTarget.write

Replace the sealed field and record key_version.

write(row: Any, blobs: Mapping[str, Optional[bytes]], key_version: int) -> None

Parameter Type Default Description
row Any
blobs Mapping[str, Optional[bytes]]
key_version int

Raises:

  • ValueError — If blobs names unknown fields or is empty.
  • LookupError — If the document no longer exists.

Method RedisDocumentTarget.quarantine

Move a Redis document to its quarantine collection.

The quarantine copy is written before the source is removed, so an interruption leaves the document in both collections (safe, and idempotent on re-run) and never in neither.

quarantine(row: Any, reason: str, run_id: str) -> None

Parameter Type Default Description
row Any
reason str
run_id str

Method RedisDocumentTarget.restore_raw

Restore backed-up Redis documents and remove their quarantine copies.

restore_raw(source: BackupSource) -> int

Parameter Type Default Description
source BackupSource

Returns: int

Class RedisUserCredentialsTarget

Redis target for sealed user credentials.

Class RedisUserLlmKeysTarget

Redis target for sealed user LLM keys.

Class UserCredentialsTarget

user_credentials documents written by the credentials handler/vault utils.

Class UserLlmKeysTarget

user_llm_keys documents written by the BYOK (Studio keys) handler.

Alias credential_context

Re-exported from parrot.security.credentials_utils.credential_context.

Alias llm_key_context

Re-exported from parrot.security.credentials_utils.llm_key_context.

Function redis_user_credentials_factory

Entry-point factory for user_credentials in Redis (VAULT_STORE=redis).

redis_user_credentials_factory(resources: Mapping[str, Any]) -> Optional[RedisUserCredentialsTarget]

Parameter Type Default Description
resources Mapping[str, Any]

Returns: Optional[RedisUserCredentialsTarget]

Function redis_user_llm_keys_factory

Entry-point factory for user_llm_keys in Redis (BYOK_STORE=redis).

redis_user_llm_keys_factory(resources: Mapping[str, Any]) -> Optional[RedisUserLlmKeysTarget]

Parameter Type Default Description
resources Mapping[str, Any]

Returns: Optional[RedisUserLlmKeysTarget]

Function user_credentials_factory

Entry-point factory for user_credentials (needs DocumentDB).

user_credentials_factory(resources: Mapping[str, Any]) -> Optional[UserCredentialsTarget]

Parameter Type Default Description
resources Mapping[str, Any]

Returns: Optional[UserCredentialsTarget]

Function user_llm_keys_factory

Entry-point factory for user_llm_keys (needs DocumentDB).

user_llm_keys_factory(resources: Mapping[str, Any]) -> Optional[UserLlmKeysTarget]

Parameter Type Default Description
resources Mapping[str, Any]

Returns: Optional[UserLlmKeysTarget]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally