pub struct GlobalIndex { /* private fields */ }Expand description
In-memory representation of the global index.
Backed by a BTreeMap so iteration order is deterministic
(paths sort lexicographically), which keeps secrets list output
stable across runs.
Implementations§
Source§impl GlobalIndex
impl GlobalIndex
Sourcepub fn new() -> Self
pub fn new() -> Self
Build an empty index. Useful for tests and as the default when the on-disk file is absent.
Sourcepub fn default_path() -> Result<PathBuf, IndexError>
pub fn default_path() -> Result<PathBuf, IndexError>
Resolve the canonical on-disk path
(<config-dir>/devboy-tools/secrets/index.toml).
Errors only if dirs::config_dir() returns None.
Sourcepub fn load() -> Result<Self, IndexError>
pub fn load() -> Result<Self, IndexError>
Load the index from the canonical default path.
Returns an empty index if the file does not exist (the global index is opt-in).
Sourcepub fn load_from(path: &Path) -> Result<Self, IndexError>
pub fn load_from(path: &Path) -> Result<Self, IndexError>
Load the index from a specific path. Returns an empty index if the file does not exist.
Sourcepub fn from_toml_str(body: &str) -> Result<Self, IndexError>
pub fn from_toml_str(body: &str) -> Result<Self, IndexError>
Parse the index from a TOML string with no associated path (used in tests and when the caller already has the bytes in memory).
Sourcepub fn save_to(&self, path: &Path) -> Result<(), IndexError>
pub fn save_to(&self, path: &Path) -> Result<(), IndexError>
Persist this index to path, creating parent directories
as needed. Used by the liveness flow (P9.2 / P9.3) to
write upstream-reported expires_at back into the global
metadata.
Sourcepub fn save(&self) -> Result<PathBuf, IndexError>
pub fn save(&self) -> Result<PathBuf, IndexError>
Persist to the default path. Returns the path written for the caller’s logging convenience.
Sourcepub fn record_expiry(&mut self, path: &SecretPath, expires_at: &str) -> bool
pub fn record_expiry(&mut self, path: &SecretPath, expires_at: &str) -> bool
Update entry.expires_at for path. Returns Ok(true)
when an entry existed and the field changed; Ok(false)
when no entry exists at that path. The caller persists
via save / save_to.
Used by the liveness flow (P9.2): a probe that returns
LivenessResult::expires_at hands the value here, and
the next doctor run sees the freshened expiry.
Sourcepub fn record_rotation(
&mut self,
path: &SecretPath,
last_rotated_at: &str,
) -> bool
pub fn record_rotation( &mut self, path: &SecretPath, last_rotated_at: &str, ) -> bool
Update entry.last_rotated_at for path. Same shape as
record_expiry; used by the rotation
flow (P13.1) after a successful rotation.
Sourcepub fn to_toml_string(&self) -> Result<String, Error>
pub fn to_toml_string(&self) -> Result<String, Error>
Serialize back to TOML. Round-trips bit-for-bit with what
from_toml_str would parse (modulo whitespace and key order —
the latter is stable thanks to BTreeMap).
Sourcepub fn get(&self, path: &SecretPath) -> Option<&IndexEntry>
pub fn get(&self, path: &SecretPath) -> Option<&IndexEntry>
Look up a single entry by path.
Sourcepub fn insert(
&mut self,
path: SecretPath,
entry: IndexEntry,
) -> Option<IndexEntry>
pub fn insert( &mut self, path: SecretPath, entry: IndexEntry, ) -> Option<IndexEntry>
Insert or replace an entry. Returns the previous entry if any.
Sourcepub fn remove(&mut self, path: &SecretPath) -> Option<IndexEntry>
pub fn remove(&mut self, path: &SecretPath) -> Option<IndexEntry>
Remove an entry. Returns the removed entry if present.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&SecretPath, &IndexEntry)>
pub fn iter(&self) -> impl Iterator<Item = (&SecretPath, &IndexEntry)>
Iterate over (path, entry) pairs in sorted order.
Trait Implementations§
Source§impl Clone for GlobalIndex
impl Clone for GlobalIndex
Source§fn clone(&self) -> GlobalIndex
fn clone(&self) -> GlobalIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more