Skip to content

Commit

Permalink
feat: adding secret get_effective_at method host implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanti committed Dec 17, 2024
1 parent 69bef33 commit ec4441b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions crates/secret/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use reactor::gcore::fastedge::secret;

pub trait SecretStrategy {
fn get(&self, key: String) -> anyhow::Result<Option<Vec<u8>>>;
fn get_effective_at(&self, key: String, at: u64) -> anyhow::Result<Option<Vec<u8>>>;
}

#[derive(Clone)]
Expand All @@ -25,6 +26,21 @@ impl<T: SecretStrategy + Send> secret::Host for Secret<T> {
}
})
}

async fn get_effective_at(
&mut self,
key: String,
at: u32,
) -> wasmtime::Result<Result<Option<String>, secret::Error>> {
Ok(match self.strategy.get_effective_at(key, at as u64) {
Ok(None) => Ok(None),
Ok(Some(plaintext)) => Ok(Some(String::from_utf8(plaintext)?)),
Err(error) => {
tracing::error!(cause=?error, "decryption error");
Err(secret::Error::DecryptError)
}
})
}
}

impl<T: SecretStrategy> Secret<T> {
Expand Down
2 changes: 1 addition & 1 deletion sdk
4 changes: 4 additions & 0 deletions src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ impl SecretStrategy for SecretImpl {
fn get(&self, key: String) -> anyhow::Result<Option<Vec<u8>>> {
Ok(self.inner.get(&key).map(|v| v.as_bytes().to_vec()))
}

fn get_effective_at(&self, key: String, _at: u64) -> anyhow::Result<Option<Vec<u8>>> {
Ok(self.inner.get(&key).map(|v| v.as_bytes().to_vec()))
}
}

impl Deref for SecretImpl {
Expand Down

0 comments on commit ec4441b

Please sign in to comment.