mod asset_service;
mod audit_service;
mod collection_service;
pub mod relation_service;
mod search_service;
pub use asset_service::AssetService;
pub use audit_service::AuditService;
pub use collection_service::CollectionService;
pub use relation_service::RelationService;
pub use search_service::SearchService;
use std::sync::Arc;
use crate::repository::{
AssetRepository, AuditRepository, CollectionRepository, RelationRepository,
};
#[derive(Clone)]
pub struct Services {
assets: Arc<dyn AssetRepository>,
relations: Arc<dyn RelationRepository>,
collections: Arc<dyn CollectionRepository>,
audit: Arc<dyn AuditRepository>,
authorizer: Option<std::sync::Arc<pep::cedar::CedarAuthorizer>>,
}
impl Services {
pub fn from_repositories(
assets: impl AssetRepository + 'static,
relations: impl RelationRepository + 'static,
collections: impl CollectionRepository + 'static,
audit: impl AuditRepository + 'static,
) -> Self {
Services {
assets: Arc::new(assets),
relations: Arc::new(relations),
collections: Arc::new(collections),
audit: Arc::new(audit),
authorizer: None,
}
}
pub fn with_cedar_repos(
assets: impl AssetRepository + 'static,
relations: impl RelationRepository + 'static,
collections: impl CollectionRepository + 'static,
audit: impl AuditRepository + 'static,
authorizer: pep::cedar::CedarAuthorizer,
) -> Self {
Services {
assets: Arc::new(assets),
relations: Arc::new(relations),
collections: Arc::new(collections),
audit: Arc::new(audit),
authorizer: Some(std::sync::Arc::new(authorizer)),
}
}
pub fn assets(&self) -> &dyn AssetRepository {
self.assets.as_ref()
}
pub fn relations(&self) -> &dyn RelationRepository {
self.relations.as_ref()
}
pub fn collections(&self) -> &dyn CollectionRepository {
self.collections.as_ref()
}
pub fn audit(&self) -> &dyn AuditRepository {
self.audit.as_ref()
}
pub fn authorizer(&self) -> Option<&pep::cedar::CedarAuthorizer> {
self.authorizer.as_deref()
}
pub fn cedar_enabled(&self) -> bool {
self.authorizer.is_some()
}
}