pub struct ReloadableAuth { /* private fields */ }Expand description
A wrapper that allows hot-swapping the underlying auth backend.
This is useful for reloading configuration without restarting the server.
Uses parking_lot::RwLock which doesn’t poison on panic.
§Example
use trojan_auth::{ReloadableAuth, MemoryAuth};
let auth = ReloadableAuth::new(MemoryAuth::from_passwords(["initial"]));
// Later, reload with new passwords
auth.reload(MemoryAuth::from_passwords(["new_password"]));Implementations§
Source§impl ReloadableAuth
impl ReloadableAuth
Sourcepub fn new<A: AuthBackend + 'static>(auth: A) -> Self
pub fn new<A: AuthBackend + 'static>(auth: A) -> Self
Create a new reloadable auth with the given initial backend.
Sourcepub fn reload<A: AuthBackend + 'static>(&self, auth: A)
pub fn reload<A: AuthBackend + 'static>(&self, auth: A)
Replace the auth backend with a new one.
This is an atomic operation - in-flight requests will complete with the old backend, new requests will use the new backend.
Sourcepub fn reload_arc(&self, auth: Arc<dyn AuthBackend>)
pub fn reload_arc(&self, auth: Arc<dyn AuthBackend>)
Replace the auth backend with a pre-wrapped Arc.
Sourcepub fn get(&self) -> Arc<dyn AuthBackend>
pub fn get(&self) -> Arc<dyn AuthBackend>
Get a clone of the current backend Arc.
This is useful for passing the backend to other components without holding the lock.
Trait Implementations§
Source§impl AuthBackend for ReloadableAuth
impl AuthBackend for ReloadableAuth
Source§fn verify<'life0, 'life1, 'async_trait>(
&'life0 self,
hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<AuthResult, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn verify<'life0, 'life1, 'async_trait>(
&'life0 self,
hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<AuthResult, AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Verify a password hash. Read more
Source§fn record_traffic<'life0, 'life1, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
bytes: u64,
) -> Pin<Box<dyn Future<Output = Result<(), AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn record_traffic<'life0, 'life1, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
bytes: u64,
) -> Pin<Box<dyn Future<Output = Result<(), AuthError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Optional: Record traffic usage for a user. Read more
Auto Trait Implementations§
impl !Freeze for ReloadableAuth
impl !RefUnwindSafe for ReloadableAuth
impl Send for ReloadableAuth
impl Sync for ReloadableAuth
impl Unpin for ReloadableAuth
impl !UnwindSafe for ReloadableAuth
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