greentic_secrets_api/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[cfg(not(feature = "std"))]
4extern crate alloc;
5
6#[cfg(not(feature = "std"))]
7use alloc::{borrow::Cow, string::String, vec::Vec};
8#[cfg(feature = "std")]
9use std::{borrow::Cow, string::String, vec::Vec};
10
11use async_trait::async_trait;
12use thiserror::Error;
13
14#[cfg(feature = "std")]
15use anyhow::Error as AnyhowError;
16
17/// Error conditions that can occur while interacting with a secrets provider.
18#[derive(Debug, Error)]
19pub enum SecretError {
20    #[error("not found: {0}")]
21    NotFound(String),
22
23    #[error("permission denied: {0}")]
24    Permission(String),
25
26    #[error("backend error: {0}")]
27    Backend(Cow<'static, str>),
28
29    #[cfg(feature = "std")]
30    #[error(transparent)]
31    Other(#[from] AnyhowError),
32}
33
34/// Result type returned by [`SecretsManager`].
35pub type Result<T> = core::result::Result<T, SecretError>;
36
37/// Minimal secrets manager interface shared between hosts and providers.
38#[async_trait]
39pub trait SecretsManager: Send + Sync {
40    /// Read the secret data stored at `path`.
41    async fn read(&self, path: &str) -> Result<Vec<u8>>;
42
43    /// Overwrite the secret data stored at `path`.
44    async fn write(&self, path: &str, bytes: &[u8]) -> Result<()>;
45
46    /// Delete the secret stored at `path`.
47    async fn delete(&self, path: &str) -> Result<()>;
48}