use std::collections::HashSet;
use async_trait::async_trait;
use cosmian_kmip::{
kmip_0::kmip_types::State,
kmip_2_1::{kmip_attributes::Attributes, kmip_objects::Object},
};
use crate::{InterfaceResult, ObjectWithMetadata};
pub enum AtomicOperation {
Create((String, Object, Attributes, HashSet<String>)),
Upsert((String, Object, Attributes, Option<HashSet<String>>, State)),
UpdateObject((String, Object, Attributes, Option<HashSet<String>>)),
UpdateState((String, State)),
Delete(String),
}
impl AtomicOperation {
#[must_use]
pub fn get_object_uid(&self) -> &str {
match self {
Self::Create((uid, _, _, _))
| Self::Upsert((uid, _, _, _, _))
| Self::UpdateObject((uid, _, _, _))
| Self::UpdateState((uid, _))
| Self::Delete(uid) => uid,
}
}
}
#[async_trait(?Send)]
pub trait ObjectsStore {
async fn create(
&self,
uid: Option<String>,
owner: &str,
object: &Object,
attributes: &Attributes,
tags: &HashSet<String>,
) -> InterfaceResult<String>;
async fn retrieve(&self, uid: &str) -> InterfaceResult<Option<ObjectWithMetadata>>;
async fn retrieve_tags(&self, uid: &str) -> InterfaceResult<HashSet<String>>;
async fn update_object(
&self,
uid: &str,
object: &Object,
attributes: &Attributes,
tags: Option<&HashSet<String>>,
) -> InterfaceResult<()>;
async fn update_state(&self, uid: &str, state: State) -> InterfaceResult<()>;
async fn delete(&self, uid: &str) -> InterfaceResult<()>;
async fn atomic(
&self,
user: &str,
operations: &[AtomicOperation],
) -> InterfaceResult<Vec<String>>;
async fn is_object_owned_by(&self, uid: &str, owner: &str) -> InterfaceResult<bool>;
async fn list_uids_for_tags(&self, tags: &HashSet<String>) -> InterfaceResult<HashSet<String>>;
async fn find(
&self,
researched_attributes: Option<&Attributes>,
state: Option<State>,
user: &str,
user_must_be_owner: bool,
) -> InterfaceResult<Vec<(String, State, Attributes)>>;
}