pub struct FileStore { /* private fields */ }Expand description
The token file, and the three operations anything has on it.
Configurable rather than abstract. A path, an optional group and a mode cover the differences between boards that actually exist: a different filesystem layout, a robot with no group to share the token with, a stricter mode. What they do not cover is a credential that does not live in a file at all — a TPM, a keyring — and that is a reason to add a trait when somebody has one, not before.
Implementations§
Source§impl FileStore
impl FileStore
Sourcepub fn at(path: impl Into<PathBuf>) -> Self
pub fn at(path: impl Into<PathBuf>) -> Self
A credential at path, readable only by the user that writes it.
Sourcepub fn readable_by_group(self, group: impl Into<String>) -> Self
pub fn readable_by_group(self, group: impl Into<String>) -> Self
Let one more group read it, by name.
By name because systemd-sysusers and its equivalents allocate dynamically: a number
written down is right on one board and wrong on the next. This also relaxes the mode to
0640, since group ownership without the group-read bit gives nobody anything — call
Self::mode afterwards for the unusual case where that is what you meant.
A group that does not exist on this system is a warning and a token that stays private to its owner, not an error: a login that failed because a developer’s laptop has no such group would be a worse outcome than a token the other daemon cannot read yet.
Sourcepub fn load(&self) -> Option<Stored>
pub fn load(&self) -> Option<Stored>
What is stored, or None when the robot belongs to nobody.
A file that will not parse is None with a warning rather than an error: the recovery for
a corrupt credential is signing in again, and a daemon that refuses to start — or a status
call that fails — because of one would make that harder rather than safer.
Sourcepub fn save(&self, stored: &Stored) -> Result<(), Error>
pub fn save(&self, stored: &Stored) -> Result<(), Error>
Replace the credential, atomically, readable only by its owner and the named group.
The one window this cannot close. Hugging Face rotates the refresh token on every
refresh, so between “the server issued a new pair” and “the new pair is on disk” the old
refresh token is already dead. A power cut in that window leaves a robot holding a
credential Hugging Face will not renew, and no ordering here fixes it — the rotation
happened on their side. It surfaces as a refresh failure in crate::Status::last_error
and is fixed by signing in again, which is why crate::maintain starts trying a week
early rather than on the last day.
Trait Implementations§
impl Eq for FileStore
impl StructuralPartialEq for FileStore
Auto Trait Implementations§
impl Freeze for FileStore
impl RefUnwindSafe for FileStore
impl Send for FileStore
impl Sync for FileStore
impl Unpin for FileStore
impl UnsafeUnpin for FileStore
impl UnwindSafe for FileStore
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.