use std::collections::HashMap;
use std::path::{Path, PathBuf};
use crate::types::{AuthCategory, Confidence, Finding, PolicyEngine};
pub struct PolicyFile {
pub label: String,
pub output_path: PathBuf,
pub content: String,
pub finding_count: usize,
}
#[derive(Debug)]
pub struct ValidationResult {
pub valid: bool,
pub error: Option<String>,
}
pub trait PolicyGenerator {
fn engine(&self) -> PolicyEngine;
fn validate(&self, policy: &str) -> ValidationResult;
fn render_template(&self, template: &str, vars: &HashMap<String, String>) -> String;
fn default_stub(&self, category: AuthCategory, snippet: &str) -> String;
fn wrap_by_confidence(&self, body: &str, confidence: Confidence) -> String;
fn group_and_generate(
&self,
findings: &[Finding],
policy_prefix: &str,
output_dir: &Path,
) -> Vec<PolicyFile>;
}
pub fn generator_for(engine: PolicyEngine) -> &'static dyn PolicyGenerator {
static REGO: crate::rego::RegoGenerator = crate::rego::RegoGenerator;
static CEDAR: crate::cedar::CedarGenerator = crate::cedar::CedarGenerator;
match engine {
PolicyEngine::Rego => ®O,
PolicyEngine::Cedar => &CEDAR,
}
}