Skip to main content

ReloadableAuth

Struct ReloadableAuth 

Source
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

Source

pub fn new<A: AuthBackend + 'static>(auth: A) -> Self

Create a new reloadable auth with the given initial backend.

Source

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.

Source

pub fn reload_arc(&self, auth: Arc<dyn AuthBackend>)

Replace the auth backend with a pre-wrapped Arc.

Source

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

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,

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,

Optional: Record traffic usage for a user. Read more
Source§

impl Debug for ReloadableAuth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.