pub struct ApiKeyStore { /* private fields */ }Expand description
In-memory API key store. Persists to JSON.
Implementations§
Source§impl ApiKeyStore
impl ApiKeyStore
pub fn new() -> Self
Sourcepub fn load_from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self>
Load from a JSON file. Missing file → empty store.
Sourcepub fn reload_from_file(&self, path: impl AsRef<Path>) -> Result<()>
pub fn reload_from_file(&self, path: impl AsRef<Path>) -> Result<()>
Atomically replace the in-memory key set from a complete persisted snapshot. A parse or I/O failure leaves the currently active set untouched, so a partial secret projection cannot erase valid keys.
Sourcepub fn create(
&self,
prefix: impl Into<String>,
scopes: Vec<String>,
ttl: Option<Duration>,
) -> Result<(ApiKey, String)>
pub fn create( &self, prefix: impl Into<String>, scopes: Vec<String>, ttl: Option<Duration>, ) -> Result<(ApiKey, String)>
Create a new key. Returns the key record and the raw secret string (the caller must surface it to the user once; we never store the raw).
§Errors
Returns AuthError::Other if Argon2 fails (extremely rare; only
happens on out-of-memory).
§Examples
use agentguard_auth::ApiKeyStore;
use std::time::Duration;
let store = ApiKeyStore::new();
let (key, raw) = store.create("ag_live", vec!["read".into()], Some(Duration::from_secs(3600))).unwrap();
assert_eq!(key.prefix, "ag_live");
// Surface `raw` to the user once. It looks like: ag_live_<uuid>_<base64>Sourcepub fn create_bound(
&self,
prefix: impl Into<String>,
scopes: Vec<String>,
ttl: Option<Duration>,
identity: ApiKeyIdentity,
) -> Result<(ApiKey, String)>
pub fn create_bound( &self, prefix: impl Into<String>, scopes: Vec<String>, ttl: Option<Duration>, identity: ApiKeyIdentity, ) -> Result<(ApiKey, String)>
Create a key bound to one Cedar subject and optional tenant.
Decision routes accept only identity-bound keys and require the
authorize scope (or *).
Trait Implementations§
Source§impl Debug for ApiKeyStore
impl Debug for ApiKeyStore
Source§impl Default for ApiKeyStore
impl Default for ApiKeyStore
Source§fn default() -> ApiKeyStore
fn default() -> ApiKeyStore
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for ApiKeyStore
impl !RefUnwindSafe for ApiKeyStore
impl Send for ApiKeyStore
impl Sync for ApiKeyStore
impl Unpin for ApiKeyStore
impl UnwindSafe for ApiKeyStore
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more