#[cfg(feature = "diesel")]
pub mod diesel;
mod error;
pub use error::AgentStoreError;
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct Agent {
pub public_key: String,
pub org_id: String,
pub active: bool,
pub metadata: Vec<u8>,
pub roles: Vec<String>,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub service_id: Option<String>,
}
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct Role {
pub public_key: String,
pub role_name: String,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub service_id: Option<String>,
}
pub trait AgentStore: Send + Sync {
fn add_agent(&self, agent: Agent) -> Result<(), AgentStoreError>;
fn list_agents(&self, service_id: Option<&str>) -> Result<Vec<Agent>, AgentStoreError>;
fn fetch_agent(
&self,
pub_key: &str,
service_id: Option<&str>,
) -> Result<Option<Agent>, AgentStoreError>;
fn update_agent(&self, agent: Agent) -> Result<(), AgentStoreError>;
}
impl<AS> AgentStore for Box<AS>
where
AS: AgentStore + ?Sized,
{
fn add_agent(&self, agent: Agent) -> Result<(), AgentStoreError> {
(**self).add_agent(agent)
}
fn list_agents(&self, service_id: Option<&str>) -> Result<Vec<Agent>, AgentStoreError> {
(**self).list_agents(service_id)
}
fn fetch_agent(
&self,
pub_key: &str,
service_id: Option<&str>,
) -> Result<Option<Agent>, AgentStoreError> {
(**self).fetch_agent(pub_key, service_id)
}
fn update_agent(&self, agent: Agent) -> Result<(), AgentStoreError> {
(**self).update_agent(agent)
}
}