pub mod engine;
pub mod types;
mod existing;
pub use existing::{
MockPolicyEngine, Policy, PolicyDecision as ExistingPolicyDecision, PolicyEngine,
};
pub use types::{
AccessContext, AccessDecision, AccessType, AllocationDecision, AllocationResult,
EnforcementStatistics, ResourceAccessRequest, ResourceAllocationRequest, ResourceType,
SourceInfo,
};
pub use crate::types::PolicyError;
pub use engine::{DefaultPolicyEnforcementPoint, MockPolicyEnforcementPoint};
use crate::types::*;
use async_trait::async_trait;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ResourceAccessConfig {
pub default_deny: bool,
pub enable_caching: bool,
pub cache_ttl_secs: u64,
pub policy_path: Option<String>,
pub enable_audit: bool,
}
impl Default for ResourceAccessConfig {
fn default() -> Self {
Self {
default_deny: true,
enable_caching: true,
cache_ttl_secs: 300, policy_path: None,
enable_audit: true,
}
}
}
#[async_trait]
pub trait PolicyEnforcementPoint: Send + Sync {
async fn check_resource_access(
&self,
agent_id: AgentId,
resource: &ResourceAccessRequest,
) -> Result<AccessDecision, PolicyError>;
async fn validate_resource_allocation(
&self,
agent_id: AgentId,
allocation: &ResourceAllocationRequest,
) -> Result<AllocationDecision, PolicyError>;
async fn load_policies(&self, config: &ResourceAccessConfig) -> Result<(), PolicyError>;
async fn reload_policies(&self) -> Result<(), PolicyError>;
async fn get_enforcement_stats(&self) -> Result<EnforcementStatistics, PolicyError>;
}
pub struct PolicyEnforcementFactory;
impl PolicyEnforcementFactory {
pub async fn create_enforcement_point(
config: ResourceAccessConfig,
) -> Result<Arc<dyn PolicyEnforcementPoint>, PolicyError> {
let enforcement_point = DefaultPolicyEnforcementPoint::new(config).await?;
Ok(Arc::new(enforcement_point))
}
pub fn create_mock_enforcement_point() -> Arc<dyn PolicyEnforcementPoint> {
Arc::new(MockPolicyEnforcementPoint::new())
}
}