use std::collections::HashMap;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct AppRoleAuthReply {
pub auth: AuthToken,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct AuthToken {
pub client_token: String,
pub lease_duration: u64,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct GetSecretReply {
pub lease_duration: u64,
pub data: SecretData,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SecretData {
pub data: HashMap<String, String>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct UserPassAuthReply {
pub auth: AuthToken,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Error {
Unauthorized,
}
#[async_trait]
pub trait SecretStore: Clone + Send + Sync {
async fn approle_auth(&self, role_id: &str, secret_id: &str)
-> Result<AppRoleAuthReply, Error>;
async fn create_secret(&self, secret_path: &str, secret_data: SecretData) -> Result<(), Error>;
async fn get_secret(&self, secret_path: &str) -> Result<Option<GetSecretReply>, Error>;
async fn token_auth(&self, token: &str) -> Result<(), Error>;
async fn userpass_auth(
&self,
username: &str,
password: &str,
) -> Result<UserPassAuthReply, Error>;
async fn userpass_create_update_user(
&self,
current_username: &str,
username: &str,
password: &str,
) -> Result<(), Error>;
}