From afba827603d83ab4c4b4a8fe8fc8ef8a81829f08 Mon Sep 17 00:00:00 2001 From: Jocelyn Boullier Date: Mon, 23 Oct 2023 11:36:36 +0200 Subject: [PATCH] fix(secret-store): use Secret instead of String --- common/src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index ee4e8a2bdf..b34b93e181 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -156,22 +156,22 @@ impl DatabaseReadyInfo { /// Store that holds all the secrets available to a deployment #[derive(Deserialize, Serialize, Clone)] pub struct SecretStore { - pub(crate) secrets: BTreeMap, + pub(crate) secrets: BTreeMap>, } impl SecretStore { - pub fn new(secrets: BTreeMap) -> Self { + pub fn new(secrets: BTreeMap>) -> Self { Self { secrets } } pub fn get(&self, key: &str) -> Option { - self.secrets.get(key).map(ToOwned::to_owned) + self.secrets.get(key).map(|k| ToOwned::to_owned(k.expose())) } } impl IntoIterator for SecretStore { - type Item = (String, String); - type IntoIter = as IntoIterator>::IntoIter; + type Item = (String, Secret); + type IntoIter = > as IntoIterator>::IntoIter; fn into_iter(self) -> Self::IntoIter { self.secrets.into_iter() } @@ -248,14 +248,20 @@ mod tests { #[test] fn secretstore_intoiter() { let bt = BTreeMap::from([ - ("1".to_owned(), "2".to_owned()), - ("3".to_owned(), "4".to_owned()), + ("1".to_owned(), "2".to_owned().into()), + ("3".to_owned(), "4".to_owned().into()), ]); let ss = SecretStore::new(bt); let mut iter = ss.into_iter(); - assert_eq!(iter.next(), Some(("1".to_owned(), "2".to_owned()))); - assert_eq!(iter.next(), Some(("3".to_owned(), "4".to_owned()))); + assert_eq!( + iter.next(), + Some(("1".to_owned().into(), "2".to_owned().into())) + ); + assert_eq!( + iter.next(), + Some(("3".to_owned().into(), "4".to_owned().into())) + ); assert_eq!(iter.next(), None); }