Cache parsed auth state per remote and validate it with on-disk file metadata so repeated authenticated API calls can skip redundant open/read/JSON parse work within one process. Centralize cache load, persist, and removal helpers in the cache module, reuse them from login, logout, and whoami, and update the refresh path to persist structured cache data directly. Add targeted cache tests for memory reuse, invalidation after external writes, persist updates, and cache removal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
/// Access and refresh token pair stored in the login cache file.
|
|
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
|
|
pub struct CacheToken {
|
|
pub access: String,
|
|
pub refresh: String,
|
|
}
|
|
|
|
/// Minimal user fields stored in the cache, matching Python's `User` dataclass.
|
|
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
|
|
pub struct CacheUser {
|
|
pub id: u32,
|
|
pub username: String,
|
|
pub laboratory_ids: Vec<u32>,
|
|
pub is_reviewer: bool,
|
|
}
|
|
|
|
/// All four laboratory fields needed for digest computation.
|
|
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
|
|
pub struct CacheLaboratory {
|
|
pub id: u32,
|
|
pub name: String,
|
|
#[serde(default)]
|
|
pub pi_name: String,
|
|
#[serde(default)]
|
|
pub full_name: String,
|
|
}
|
|
|
|
/// Wrapper matching Python's `Laboratories` serialization: `{"items": [...]}`.
|
|
#[derive(Deserialize, Serialize, Clone, Debug, Default, PartialEq, Eq)]
|
|
pub struct CacheLabsWrapper {
|
|
pub items: Vec<CacheLaboratory>,
|
|
}
|
|
|
|
/// Full login cache, corresponding to the `<remote>.json` file written by `login`.
|
|
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
|
|
pub struct Cache {
|
|
pub user: Option<CacheUser>,
|
|
pub token: CacheToken,
|
|
pub laboratories: CacheLabsWrapper,
|
|
#[serde(default)]
|
|
pub digest: String,
|
|
}
|