use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PolicyOutcome {
Promote,
Reject,
Escalate,
}
impl PolicyOutcome {
#[must_use]
pub fn is_allowed(&self) -> bool {
matches!(self, Self::Promote)
}
#[must_use]
pub fn is_terminal(&self) -> bool {
matches!(self, Self::Promote | Self::Reject)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyDecision {
pub outcome: PolicyOutcome,
pub mode: DecisionMode,
pub reason: Option<String>,
pub principal_id: String,
pub action: String,
pub resource_id: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DecisionMode {
Policy,
Delegation,
}
impl PolicyDecision {
#[must_use]
pub fn policy(
outcome: PolicyOutcome,
reason: Option<String>,
principal_id: String,
action: String,
resource_id: String,
) -> Self {
Self {
outcome,
mode: DecisionMode::Policy,
reason,
principal_id,
action,
resource_id,
}
}
#[must_use]
pub fn delegation(
outcome: PolicyOutcome,
reason: Option<String>,
principal_id: String,
action: String,
resource_id: String,
) -> Self {
Self {
outcome,
mode: DecisionMode::Delegation,
reason,
principal_id,
action,
resource_id,
}
}
}