vanta_core/traits.rs
1//! The trait seams the engine is wired through (see
2//! `docs/02-architecture.md` §dependency-injection-and-extension-seams).
3//!
4//! Concrete implementations live in their owning crates (`vanta-provider`,
5//! `vanta-net`, `vanta-store`, `vanta-security`, `vanta-platform`); test fakes
6//! live in `vanta-test`.
7
8use crate::error::VtaResult;
9use crate::platform::Platform;
10use crate::types::Artifact;
11use std::path::Path;
12
13/// Describes how to discover and resolve a tool's artifacts
14/// (`docs/07-providers.md`, `docs/22-provider-sdk.md`).
15pub trait Provider {
16 /// The provider id, e.g. `"official/node"`.
17 fn id(&self) -> &str;
18 /// The available version strings, newest-first ordering applied by the resolver.
19 fn list_versions(&self) -> VtaResult<Vec<String>>;
20 /// The artifact descriptor for a version on a platform.
21 fn resolve(&self, version: &str, platform: &Platform) -> VtaResult<Artifact>;
22}
23
24/// A fetch backend (curated, github-releases, direct-url, …).
25pub trait Backend {
26 fn name(&self) -> &str;
27 /// Fetch `url` into `dest` (a path in the download cache).
28 fn fetch(&self, url: &str, dest: &Path) -> VtaResult<()>;
29}
30
31/// A byte cache keyed by an opaque string (download/metadata caches).
32pub trait CacheStore {
33 fn get(&self, key: &str) -> VtaResult<Option<Vec<u8>>>;
34 fn put(&self, key: &str, bytes: &[u8]) -> VtaResult<()>;
35}
36
37/// Verifies an artifact signature against trusted keys (`docs/15-security.md`).
38pub trait SignatureVerifier {
39 /// The scheme handled, e.g. `"minisign"` or `"cosign"`.
40 fn scheme(&self) -> &str;
41 /// Whether `signature` is valid for `data`.
42 fn verify(&self, data: &[u8], signature: &str) -> VtaResult<bool>;
43}
44
45/// A way to materialize an environment view from the store
46/// (`docs/09-store.md` §link-strategies).
47pub trait LinkStrategy {
48 /// The strategy name, e.g. `"reflink"`, `"hardlink"`, `"symlink"`, `"copy"`.
49 fn name(&self) -> &str;
50 /// Whether this strategy is usable for the given target directory.
51 fn probe(&self, dir: &Path) -> bool;
52 /// Link `src` to `dst`.
53 fn link(&self, src: &Path, dst: &Path) -> VtaResult<()>;
54}