pub struct SecretManager<B, E, const V: usize = 256, const S: usize = 32>{ /* private fields */ }Expand description
Convenience facade that runs a SecretSyncer and a KeyRotator together.
SecretManager is the right choice when a single service instance should both rotate
keys and consume them. Internally it:
- Calls
SecretSyncer::initial_loadsynchronously so the ring is hydrated beforestartreturns (any failure is propagated as theErrvariant). - Spawns the syncer and rotator as independent
tokiotasks that run until theCancellationTokenis cancelled.
The SecretGroup trait is forwarded to the inner InMemorySecretGroup so you can
call current and resolve directly on the
manager.
For split deployments — a dedicated rotation service plus many reader nodes — use
KeyRotator and SecretSyncer independently instead.
§Type parameters
B— backend that implements bothSecretBackendandSecretRotationBackendE— encryptor that implementsKeyEncryptorV— ring buffer size (default 256, must be ≤ 256)S— key size in bytes (default 32)
Implementations§
Source§impl<B, E, const V: usize, const S: usize> SecretManager<B, E, V, S>
impl<B, E, const V: usize, const S: usize> SecretManager<B, E, V, S>
Sourcepub fn new(
group_id: impl Into<String>,
group: Arc<InMemorySecretGroup<V, S>>,
backend: B,
encryptor: E,
rotation_interval: Duration,
propagation_delay: Duration,
poll_interval: Option<Duration>,
generate_key: Option<fn() -> [u8; S]>,
) -> Self
pub fn new( group_id: impl Into<String>, group: Arc<InMemorySecretGroup<V, S>>, backend: B, encryptor: E, rotation_interval: Duration, propagation_delay: Duration, poll_interval: Option<Duration>, generate_key: Option<fn() -> [u8; S]>, ) -> Self
Create a new SecretManager.
§Arguments
group_id— identifies the logical key group in storagegroup— the ring buffer that will be kept hydrated; typically wrapped inArcso application code can read it concurrentlybackend— implements bothSecretBackend(read) andSecretRotationBackend(write)encryptor— encrypts keys on write, decrypts on readrotation_interval— how long a key lives before a new one is generatedpropagation_delay— head-start given to syncers before a new key becomescurrent; set to at least your maximum expected poll latencypoll_interval— how often the syncer polls for new keys;Noneuses 5 secondsgenerate_key— custom key-material generator;Noneuses a CSPRNG fill
Sourcepub async fn start(
self,
token: CancellationToken,
) -> Result<SecretManagerHandle, <B as SecretBackend>::Error>
pub async fn start( self, token: CancellationToken, ) -> Result<SecretManagerHandle, <B as SecretBackend>::Error>
Hydrate the ring buffer and spawn background tasks.
Performs the initial load synchronously — if it fails the error is returned and no
tasks are spawned. On success, the syncer and rotator are launched and a
SecretManagerHandle is returned.
§Graceful shutdown
let token = CancellationToken::new();
let handle = SecretManager::new("payments-signing", group, backend, encryptor,
Duration::from_secs(3600), Duration::from_secs(30), None, None)
.start(token.clone()).await?;
// … serve traffic …
token.cancel(); // signal tasks to stop
handle.wait().await; // block until both tasks have exitedTrait Implementations§
Source§impl<B, E, const V: usize, const S: usize> SecretGroup<V, S> for SecretManager<B, E, V, S>
impl<B, E, const V: usize, const S: usize> SecretGroup<V, S> for SecretManager<B, E, V, S>
Auto Trait Implementations§
impl<B, E, const V: usize, const S: usize> Freeze for SecretManager<B, E, V, S>
impl<B, E, const V: usize = 256, const S: usize = 32> !RefUnwindSafe for SecretManager<B, E, V, S>
impl<B, E, const V: usize, const S: usize> Send for SecretManager<B, E, V, S>
impl<B, E, const V: usize, const S: usize> Sync for SecretManager<B, E, V, S>
impl<B, E, const V: usize, const S: usize> Unpin for SecretManager<B, E, V, S>
impl<B, E, const V: usize, const S: usize> UnsafeUnpin for SecretManager<B, E, V, S>where
B: UnsafeUnpin,
E: UnsafeUnpin,
impl<B, E, const V: usize = 256, const S: usize = 32> !UnwindSafe for SecretManager<B, E, V, S>
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Add an aggregate function filter Read more
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Add an aggregate function order Read more
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreCreates a shared type from an unshared type.
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self to an expression for Diesel’s query builder. Read moreSource§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
Source§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
Executes the given command, returning the number of rows affected. Read more
Source§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Source§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Executes the given query, returning a [
Stream] with the returned rows. Read moreSource§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
Runs the command, and returns the affected row. Read more
Source§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Runs the command, returning an
Vec with the affected rows. Read moreSource§impl<T> WindowExpressionMethods for T
impl<T> WindowExpressionMethods for T
Source§fn over(self) -> Self::Outputwhere
Self: OverDsl,
fn over(self) -> Self::Outputwhere
Self: OverDsl,
Turn a function call into a window function call Read more
Source§fn window_filter<P>(self, f: P) -> Self::Output
fn window_filter<P>(self, f: P) -> Self::Output
Add a filter to the current window function Read more
Source§fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
Add a partition clause to the current window function Read more
Source§fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
Add a order clause to the current window function Read more