use crate::{AttributesEntry, Identifier, TimestampInSeconds};
use async_trait::async_trait;
use ockam_core::compat::boxed::Box;
use ockam_core::Result;
#[cfg(feature = "std")]
use ockam_node::database::AutoRetry;
#[cfg(feature = "std")]
use ockam_node::retry;
#[async_trait]
pub trait IdentityAttributesRepository: Send + Sync + 'static {
async fn get_attributes(
&self,
subject: &Identifier,
attested_by: &Identifier,
) -> Result<Option<AttributesEntry>>;
async fn put_attributes(&self, subject: &Identifier, entry: AttributesEntry) -> Result<()>;
async fn delete_expired_attributes(&self, now: TimestampInSeconds) -> Result<()>;
}
#[cfg(feature = "std")]
#[async_trait]
impl<T: IdentityAttributesRepository> IdentityAttributesRepository for AutoRetry<T> {
async fn get_attributes(
&self,
subject: &Identifier,
attested_by: &Identifier,
) -> Result<Option<AttributesEntry>> {
retry!(self.wrapped.get_attributes(subject, attested_by))
}
async fn put_attributes(&self, subject: &Identifier, entry: AttributesEntry) -> Result<()> {
retry!(self.wrapped.put_attributes(subject, entry.clone()))
}
async fn delete_expired_attributes(&self, now: TimestampInSeconds) -> Result<()> {
retry!(self.wrapped.delete_expired_attributes(now))
}
}