pub struct AuthCache { /* private fields */ }Expand description
In-memory view of ~/.config/dsp-cli/auth.toml.
Load with AuthCache::load (or AuthCache::load_from in tests).
Mutate with AuthCache::set_token and AuthCache::remove.
Persist with AuthCache::save (or AuthCache::save_to in tests).
Internal layout is a BTreeMap (not HashMap) so the on-disk TOML has
deterministic key order. The toml crate serialises a BTreeMap<String, T>
at the root as a sequence of standalone [key] tables, which is the shape
ADR-0007 specifies — no wrapper struct or #[serde(flatten)] needed.
Implementations§
Source§impl AuthCache
impl AuthCache
Sourcepub fn default_path() -> Result<PathBuf, Diagnostic>
pub fn default_path() -> Result<PathBuf, Diagnostic>
The canonical cache path: ~/.config/dsp-cli/auth.toml.
Returns an error if the home directory cannot be resolved.
Sourcepub fn load() -> Result<Self, Diagnostic>
pub fn load() -> Result<Self, Diagnostic>
Load the cache from Self::default_path.
A missing file is not an error — it means no tokens are cached yet.
Sourcepub fn load_from(path: &Path) -> Result<Self, Diagnostic>
pub fn load_from(path: &Path) -> Result<Self, Diagnostic>
Load the cache from an explicit path.
A missing file is not an error — returns an empty cache. Files whose
reported size exceeds MAX_CACHE_FILE_BYTES are rejected before the
contents are read, so a symlink pointing at a huge file fails fast.
Sourcepub fn save(&self) -> Result<(), Diagnostic>
pub fn save(&self) -> Result<(), Diagnostic>
Save the cache to Self::default_path.
Creates the parent directory if it does not exist. On Unix, the file is
created with mode 0600.
Sourcepub fn save_to(&self, path: &Path) -> Result<(), Diagnostic>
pub fn save_to(&self, path: &Path) -> Result<(), Diagnostic>
Save the cache to an explicit path.
Creates the parent directory if it does not exist. On Unix, the file is
created with mode 0600.
Sourcepub fn acquired_at(&self, server: &str) -> Option<DateTime<Utc>>
pub fn acquired_at(&self, server: &str) -> Option<DateTime<Utc>>
Return the acquired_at timestamp for server, if any.
Sourcepub fn expires_at(&self, server: &str) -> Option<DateTime<Utc>>
pub fn expires_at(&self, server: &str) -> Option<DateTime<Utc>>
Return the expires_at timestamp for server, if any.
Sourcepub fn set_entry(&mut self, server: impl Into<String>, entry: ServerEntry)
pub fn set_entry(&mut self, server: impl Into<String>, entry: ServerEntry)
Insert or replace a fully-populated entry for server.
Prefer this over set_token when the full entry shape is available
(e.g. after a login that returns user + expiry). set_token remains
as a thin convenience for callers that only have a token.
Sourcepub fn set_token(&mut self, server: String, token: String)
pub fn set_token(&mut self, server: String, token: String)
Insert or replace the token for server.
Convenience wrapper that constructs a partial ServerEntry with only
the token set, leaving user, acquired_at, and expires_at as
None. Use set_entry when the full shape is available.