Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shuttle_secrets source #538

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add shuttle secret store source example to docs
  • Loading branch information
cbinzer committed Feb 25, 2024
commit bf2f4cf907243370a40a3b4f20da0ad4be52766c
34 changes: 34 additions & 0 deletions src/shuttle_secret_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@ use crate::{ConfigError, Environment, Map, Source, Value};
/// A source for the [SecretStore](https://docs.rs/shuttle-secrets/0.39.0/shuttle_secrets/struct.SecretStore.html)
/// of [shuttle.rs](https://www.shuttle.rs/). It is based on the [Environment] source and offers all
/// the features that Environment provides.
/// # Example
/// ```ignore
/// #[derive(Deserialize, Debug, PartialEq)]
/// pub struct MyAppConfiguration {
/// pub authentication: AuthenticationSettings,
/// }
///
/// #[derive(Deserialize, Debug, PartialEq)]
/// pub struct AuthenticationSettings {
/// pub token_secret: String,
/// }
///
/// #[shuttle_runtime::main]
/// async fn main(
/// #[shuttle_secrets::Secrets] secret_store: SecretStore, // includes MY_APP_AUTHENTICATION__TOKEN_SECRET=my_secret
/// ) -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
/// let service_config = move |cfg: &mut ServiceConfig| {
/// let my_config = Config::builder()
/// .add_source(
/// ShuttleSecretStore::new(&secret_store)
/// .prefix("MY_APP")
/// .prefix_separator("_")
/// .separator("__"),
/// )
/// .build()
/// .unwrap()
/// .try_deserialize::<MyAppConfiguration>()
/// .unwrap();
/// cfg.app_data(Data::new(my_config));
/// };
///
/// Ok(service_config.into())
/// }
/// ```
#[derive(Clone, Debug, Default)]
pub struct ShuttleSecretStore {
environment: Environment,
Expand Down