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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
//! # secret_store
//!
//! A unified, async secret-store interface for multiple cloud providers,
//! inspired by [`object_store`](https://docs.rs/object_store).
//!
//! All providers implement the same [`SecretStore`] trait, so you can swap
//! backends without changing application code.
//!
//! ## Providers
//!
//! | Feature | Provider | Builder |
//! |-----------|-------------------------------------------|----------------------------------------|
//! | *(none)* | [`memory::InMemory`] — for tests | `InMemory::new()` / `InMemory::with_secrets()` |
//! | `azure` | Azure Key Vault | [`azure::KeyVaultBuilder`] |
//! | `aws` | AWS Secrets Manager | [`aws::AwsSecretsManagerBuilder`] |
//! | `gcp` | GCP Secret Manager | [`gcp::GcpSecretManagerBuilder`] |
//! | `http` | Generic HTTP / HashiCorp Vault KV | [`http::HttpSecretStoreBuilder`] |
//!
//! ## Quick Start — In-Memory (no cloud credentials needed)
//!
//! ```
//! use std::sync::Arc;
//! use secret_store::{SecretStore, memory::InMemory};
//!
//! #[tokio::main]
//! async fn main() -> secret_store::Result<()> {
//! let store: Arc<dyn SecretStore> = Arc::new(InMemory::new());
//!
//! store.set_secret("db-password", "hunter2").await?;
//! let val = store.get_secret("db-password").await?;
//! println!("{}", val.expose_secret()); // hunter2
//!
//! // List secrets (optionally filtered by prefix)
//! let names = store.list_secrets(Some("db-")).await?;
//! assert_eq!(names[0].name, "db-password");
//!
//! store.delete_secret("db-password").await?;
//! Ok(())
//! }
//! ```
//!
//! ## Quick Start — Azure Key Vault (`azure` feature)
//!
//! ```no_run
//! use secret_store::azure::KeyVaultBuilder;
//! use secret_store::SecretStore;
//!
//! #[tokio::main]
//! async fn main() -> secret_store::Result<()> {
//! // Reads AZURE_KEYVAULT_URL + AZURE_TENANT_ID / AZURE_CLIENT_ID /
//! // AZURE_CLIENT_SECRET from env, or falls back to the Azure CLI.
//! let store = KeyVaultBuilder::from_env().build().await?;
//! println!("{store}"); // AzureKeyVault: https://my-vault.vault.azure.net/
//! println!("{store:?}"); // vault_url=..., provider=AzureKeyVault
//! store.set_secret("api-key", "s3cr3t").await?;
//! Ok(())
//! }
//! ```
//!
//! ## Quick Start — AWS Secrets Manager (`aws` feature)
//!
//! ```no_run
//! use secret_store::aws::AwsSecretsManagerBuilder;
//! use secret_store::SecretStore;
//!
//! #[tokio::main]
//! async fn main() -> secret_store::Result<()> {
//! // Reads AWS_DEFAULT_REGION / AWS_REGION from env; credentials come
//! // from the standard AWS credential chain (env, ~/.aws, IMDSv2, …).
//! let store = AwsSecretsManagerBuilder::from_env().build().await?;
//! store.set_secret("db-password", "hunter2").await?;
//! Ok(())
//! }
//! ```
//!
//! ## Quick Start — GCP Secret Manager (`gcp` feature)
//!
//! ```no_run
//! use secret_store::gcp::GcpSecretManagerBuilder;
//! use secret_store::SecretStore;
//!
//! #[tokio::main]
//! async fn main() -> secret_store::Result<()> {
//! // Reads GCP_PROJECT_ID from env; authenticates via Application Default
//! // Credentials (GOOGLE_APPLICATION_CREDENTIALS, gcloud CLI, Workload Identity).
//! let store = GcpSecretManagerBuilder::from_env().build().await?;
//! store.set_secret("api-key", "s3cr3t").await?;
//! Ok(())
//! }
//! ```
//!
//! ## Quick Start — Generic HTTP / HashiCorp Vault (`http` feature)
//!
//! ```no_run
//! use secret_store::http::HttpSecretStoreBuilder;
//! use secret_store::SecretStore;
//!
//! #[tokio::main]
//! async fn main() -> secret_store::Result<()> {
//! // Reads SECRET_STORE_HTTP_URL and SECRET_STORE_HTTP_TOKEN from env.
//! let store = HttpSecretStoreBuilder::from_env().build()?;
//! store.set_secret("db-password", "hunter2").await?;
//! Ok(())
//! }
//! ```
//!
//! ## Display and Debug
//!
//! Every store implements [`fmt::Display`] (minimal, log-friendly) and
//! [`fmt::Debug`] (verbose, useful while debugging):
//!
//! ```
//! use secret_store::memory::InMemory;
//!
//! let store = InMemory::new();
//! println!("{store}"); // InMemory(0 secrets)
//! println!("{store:?}"); // same — InMemory has no extra internal state
//! ```
//!
//! Cloud stores show their identifying info:
//! - **Azure** — `Display`: vault URL; `Debug`: vault URL + provider tag
//! - **AWS** — `Display`: region; `Debug`: region + provider tag
//! - **GCP** — `Display`: project ID; `Debug`: project ID + API endpoint + provider tag
//! - **HTTP** — `Display`: base URL; `Debug`: base URL + namespace + provider tag
//!
//! ## KMS Envelope Encryption
//!
//! Enable the `kms` feature to access [`kms::SecretsManager`], a
//! zero-storage encryption layer that wraps data keys with a cloud KMS and
//! encrypts your data locally with AES-256-GCM before storing ciphertext in
//! any [`SecretStore`] backend.
pub use ;
use async_trait;
use fmt;
use Arc;
// ─────────────────────────────────────────────────────────────────────────────
// Core trait
// ─────────────────────────────────────────────────────────────────────────────
/// A unified, async interface for reading and writing named secrets.
///
/// Implementors must also implement [`fmt::Display`] (used for log output
/// and diagnostics), [`fmt::Debug`], [`Send`], [`Sync`], and have a
/// `'static` lifetime so they can be freely stored in `Arc<dyn SecretStore>`.
///
/// # Implementing a custom backend
///
/// ```
/// use async_trait::async_trait;
/// use secret_store::{SecretStore, SecretValue, SecretMeta, Result};
///
/// #[derive(Debug)]
/// struct MyStore;
///
/// impl std::fmt::Display for MyStore {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// write!(f, "MyStore")
/// }
/// }
///
/// #[async_trait]
/// impl SecretStore for MyStore {
/// async fn get_secret(&self, name: &str) -> Result<SecretValue> {
/// Ok(SecretValue::new("placeholder"))
/// }
/// async fn set_secret(&self, _name: &str, _value: &str) -> Result<()> { Ok(()) }
/// async fn delete_secret(&self, _name: &str) -> Result<()> { Ok(()) }
/// async fn list_secrets(&self, _prefix: Option<&str>) -> Result<Vec<SecretMeta>> { Ok(vec![]) }
/// }
/// ```
/// Type alias for a dynamically-dispatched [`SecretStore`].
///
/// ```
/// use secret_store::{DynSecretStore, memory::InMemory};
/// use std::sync::Arc;
///
/// let store: Arc<DynSecretStore> = Arc::new(InMemory::new());
/// ```
pub type DynSecretStore = dyn SecretStore;
// ─────────────────────────────────────────────────────────────────────────────
// Blanket Arc / Box delegation
// ─────────────────────────────────────────────────────────────────────────────
/// Implements [`SecretStore`] for `Arc<T>` where `T: SecretStore`.
///
/// This lets you pass an `Arc<dyn SecretStore>` wherever a `&dyn SecretStore`
/// is expected, and compose stores freely.
/// Implements [`SecretStore`] for `Box<T>` where `T: SecretStore`.