-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhashmap_snapshot.rs
35 lines (27 loc) · 1.02 KB
/
hashmap_snapshot.rs
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
use secret_vault::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let subscriber = tracing_subscriber::fmt()
.with_env_filter("secret_vault=debug")
.finish();
tracing::subscriber::set_global_default(subscriber)?;
// Secret coming from an environment variable
let secret_ref = SecretVaultRef::new("user".into())
.with_required(false)
.with_allow_in_snapshots(true);
// Building the vault with test env source
let vault = SecretVaultBuilder::with_source(InsecureEnvSource::new())
.without_encryption()
.with_secret_refs(vec![&secret_ref])
.build()?;
// Load secrets from the source
vault.refresh().await?;
// Creating a snapshot
let snapshot = vault
.snapshot(SecretVaultHashMapSnapshotBuilder::new())
.await?;
// Reading the secret value
let secret_value: Secret = snapshot.require_secret_by_ref(&secret_ref)?;
println!("Received secret: {:?}", secret_value);
Ok(())
}