Skip to content

Commit

Permalink
feat: Add support to parse a SecretStore to a struct using the config…
Browse files Browse the repository at this point in the history
… crate
  • Loading branch information
JasterV committed Mar 5, 2024
1 parent f41afde commit e9e8cc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions resources/secrets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ license = "Apache-2.0"
description = "Plugin to for managing secrets on shuttle"
keywords = ["shuttle-service", "secrets"]

[features]
config = ["config", "serde"]

[dependencies]
async-trait = "0.1.56"
serde_json = "1"
shuttle-service = { path = "../../service", version = "0.40.0" }
config = { version = "0.14.0", optional = true }
serde = { workspace = true, optional = true }
22 changes: 22 additions & 0 deletions resources/secrets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ impl ResourceInputBuilder for Secrets {
))
}
}

#[cfg(feature = "config")]
impl<'de> From<shuttle_secrets::SecretStore> for T
where
T: serde::Deserialize<'de>,
{
fn from(value: shuttle_secrets::SecretStore) -> Self {
let secrets = value.into_iter().collect::<HashMap<_, _>>();

config::Config::builder()
.add_source(
config::Environment::default()
.source(Some(secrets))
.try_parsing(true)
.separator("__"),
)
.build()
.expect("Failed to load app configuration")
.try_deserialize()
.expect("Cannot deserialize configuration")
}
}

0 comments on commit e9e8cc3

Please sign in to comment.