1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::;
/// The credentials a connection authenticates with, as handed to the
/// [`HELLO`](https://redis.io/commands/hello/) handshake.
/// A source of credentials consulted at **every** handshake: the initial
/// connection and each reconnection.
///
/// [`Config::password`](crate::client::Config::password) is fixed once and for
/// all, which is enough only while the password itself never changes. Managed
/// Redis offerings authenticate with short-lived tokens instead — AWS
/// ElastiCache IAM (15 minutes), GCP Memorystore IAM, Azure Entra ID, Vault
/// dynamic secrets — and a client replaying the token it was built with fails
/// authentication for good once that token expires. A provider is asked again
/// on each reconnection, so the client picks up the current token.
///
/// The trait is implemented for any `Fn() -> Future<Output = Result<Credentials>>`,
/// so a closure is usually all that is needed:
///
/// ```
/// use rustis::client::{Config, Credentials, IntoConfig};
/// use std::sync::Arc;
///
/// # fn main() -> rustis::Result<()> {
/// let mut config = "redis://127.0.0.1".into_config()?;
/// config.credentials_provider = Some(Arc::new(|| async {
/// // regenerate the token here (IAM, Vault, ...)
/// Ok(Credentials {
/// username: Some("iam-user".to_owned()),
/// password: generate_auth_token().await,
/// })
/// }));
/// # Ok(())
/// # }
/// # async fn generate_auth_token() -> String { String::from("token") }
/// ```
///
/// An error returned by the provider fails the handshake like any other
/// connection error: the [reconnection policy](crate::client::ReconnectionConfig)
/// retries it with its own backoff.