pub struct ModelRegistry { /* private fields */ }Expand description
Adopted models, persisted as JSON when opened on a path.
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn with_trust(self, trust: ModelTrust) -> Self
pub fn with_trust(self, trust: ModelTrust) -> Self
Set what resolve verifies against.
Sourcepub fn set_trust(&self, trust: ModelTrust)
pub fn set_trust(&self, trust: ModelTrust)
Replace the trust (a key was pinned or removed, a revocation list was swapped). Takes effect on the next resolve.
Sourcepub fn open(path: impl Into<PathBuf>) -> Result<Self, ModelError>
pub fn open(path: impl Into<PathBuf>) -> Result<Self, ModelError>
Open (or start) the registry file at path.
Sourcepub fn adopt(
&self,
scanned: ScannedModel,
key: &SigningKey,
key_id: &str,
anchors: &TrustAnchors,
replace: bool,
) -> Result<AdoptedModel, ModelError>
pub fn adopt( &self, scanned: ScannedModel, key: &SigningKey, key_id: &str, anchors: &TrustAnchors, replace: bool, ) -> Result<AdoptedModel, ModelError>
Attest a scanned model with the operator key and register it. The
key must be pinned in anchors, otherwise the attestation does not
verify and nothing is registered. A different manifest under an
existing name is refused unless replace is set.
Sourcepub fn attach(
&self,
envelope: &ManifestEnvelope,
root: &Path,
anchors: &TrustAnchors,
replace: bool,
) -> Result<AdoptedModel, ModelError>
pub fn attach( &self, envelope: &ManifestEnvelope, root: &Path, anchors: &TrustAnchors, replace: bool, ) -> Result<AdoptedModel, ModelError>
Register an already-attested manifest (for example one fetched from
another node) whose files lie under root. Its signature is checked
against anchors; file hashes are checked lazily on first use.
Sourcepub fn remove(&self, id_or_name: &str) -> Result<(), ModelError>
pub fn remove(&self, id_or_name: &str) -> Result<(), ModelError>
Forget a model (files are untouched).
Sourcepub fn entries(&self) -> Vec<(String, ModelEntry)>
pub fn entries(&self) -> Vec<(String, ModelEntry)>
Snapshot of every entry, keyed by package id.
Sourcepub fn get(&self, id_or_name: &str) -> Result<(String, ModelEntry), ModelError>
pub fn get(&self, id_or_name: &str) -> Result<(String, ModelEntry), ModelError>
One entry by package id or name.
Sourcepub fn check(
&self,
id_or_name: &str,
mode: CheckMode,
) -> Result<ModelCheck, ModelError>
pub fn check( &self, id_or_name: &str, mode: CheckMode, ) -> Result<ModelCheck, ModelError>
Check a model’s files.
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn set_advertised(
&self,
id_or_name: &str,
advertised: bool,
) -> Result<(), ModelError>
pub fn set_advertised( &self, id_or_name: &str, advertised: bool, ) -> Result<(), ModelError>
Hide or advertise a model in node facts (local, unsigned opt-out: shard hashes fingerprint which models this node holds).
Sourcepub fn resolve(&self, id_or_name: &str) -> Result<ResolvedModel, ModelError>
pub fn resolve(&self, id_or_name: &str) -> Result<ResolvedModel, ModelError>
The model for an adapter to load, verified against the registry’s
trust (see with_trust); refused with
ModelError::NotReady when none is set.
What a caller may rely on when this returns Ok:
- the attestation verifies against the pinned anchors now, and the package, its signers and its shard hashes are not revoked;
- the registry’s file list equals the attested body;
- every file resolves inside the model root (or its HF
blobs/), and the returned paths are those resolved locations; - the first resolve of a model in this process hashed every byte (a full check, which on a 45 GB model takes minutes); later resolves re-hash only files whose size or mtime changed.
The lazy window: after the first resolve, a file replaced with the
same size and the same mtime is not noticed until the next process
start or an explicit CheckMode::Full check. Adapters that must
close that window call check(.., CheckMode::Full) before loading.
Paths are returned, not handles: a file can still change between
this call and the adapter opening it.
Sourcepub fn resolve_with(
&self,
id_or_name: &str,
trust: &ModelTrust,
) -> Result<ResolvedModel, ModelError>
pub fn resolve_with( &self, id_or_name: &str, trust: &ModelTrust, ) -> Result<ResolvedModel, ModelError>
resolve against an explicit trust (the sharing
gate passes the anchors the caller holds right now).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ModelRegistry
impl RefUnwindSafe for ModelRegistry
impl Send for ModelRegistry
impl Sync for ModelRegistry
impl Unpin for ModelRegistry
impl UnsafeUnpin for ModelRegistry
impl UnwindSafe for ModelRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more