use crate::RuntimeError;
pub async fn string(
client: &aws_sdk_secretsmanager::Client,
name: &str,
) -> Result<String, RuntimeError> {
let response = client
.get_secret_value()
.secret_id(name)
.send()
.await
.map_err(|error| RuntimeError::other(format!("reading secret {name}"), error))?;
response
.secret_string()
.map(str::to_owned)
.ok_or_else(|| RuntimeError::Configuration(format!("secret {name} has no string value")))
}
pub async fn json<T: serde::de::DeserializeOwned>(
client: &aws_sdk_secretsmanager::Client,
name: &str,
) -> Result<T, RuntimeError> {
let value = string(client, name).await?;
serde_json::from_str(&value).map_err(|error| {
RuntimeError::Configuration(format!(
"secret {name} is not the expected shape (at line {}, column {})",
error.line(),
error.column()
))
})
}