forked from kenzuya/unshackle
refactor(vaults): pick kv vault behaviour from class flags and keep the api batch size
This commit is contained in:
@@ -91,10 +91,20 @@ class Refused(Exception):
|
||||
|
||||
|
||||
class Vault(metaclass=ABCMeta):
|
||||
"""A key vault of KID:KEY pairs.
|
||||
|
||||
Its class flags tell kv what it can do: bulk_writes (add_keys takes a whole service in one call),
|
||||
batch_insert (add_keys takes more than one content key; HTTP clears it when the server refuses
|
||||
batches) and has_tables (one table per service, with resolve_table and create_table).
|
||||
"""
|
||||
|
||||
# a vault on this machine; Vaults.get_key tries these first, before the network ones
|
||||
local: bool = False
|
||||
report_now: bool = False
|
||||
stores_flags: bool = False
|
||||
bulk_writes: bool = False
|
||||
batch_insert: bool = True
|
||||
has_tables: bool = False
|
||||
|
||||
def __init__(self, name: str, no_push: bool = False) -> None:
|
||||
self.name = name
|
||||
@@ -152,5 +162,13 @@ class Vault(metaclass=ABCMeta):
|
||||
def unflag_bad_key(self, kid: UUID | str, key: str) -> None:
|
||||
"""Forget a flagged KID:KEY, for example when a CDM licence confirmed it."""
|
||||
|
||||
def resolve_table(self, name: str) -> str | None:
|
||||
"""The stored name of the table of a service, or None. Only a vault with has_tables has tables."""
|
||||
return None
|
||||
|
||||
def create_table(self, name: str) -> None:
|
||||
"""Make the table of a service. Only a vault with has_tables has tables."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
__all__ = ("Refused", "Vault", "brief", "json_body")
|
||||
|
||||
@@ -246,7 +246,7 @@ class Vaults:
|
||||
try:
|
||||
vault.unflag_bad_key(kid, key)
|
||||
except Exception as e:
|
||||
log.debug(f"Could not unflag {key} in Vault '{vault.name}': {e!r}")
|
||||
log.debug(f"Could not unflag {key} in Vault '{vault.name}': {brief(e)}")
|
||||
|
||||
def add_key(self, kid: UUID | str, key: str, excluding: KeySource | None = None) -> int:
|
||||
"""Add a KID:KEY to all Vaults, optionally with an exclusion.
|
||||
|
||||
Reference in New Issue
Block a user