Files
dd0c/products/06-runbook-automation/agent/src/parser.rs

53 lines
1.3 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
/// Parsed runbook step.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RunbookStep {
pub index: usize,
pub description: String,
pub command: String,
pub timeout_seconds: u64,
pub on_failure: FailureAction,
pub condition: Option<String>, // Optional: only run if previous step output matches
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FailureAction {
Abort,
Continue,
Retry { max_attempts: u32 },
}
/// Parsed runbook.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Runbook {
pub name: String,
pub description: String,
pub version: String,
pub steps: Vec<RunbookStep>,
}
/// Parse a YAML runbook into structured steps.
pub fn parse_yaml(content: &str) -> anyhow::Result<Runbook> {
// TODO: Full YAML parsing with serde_yaml
// For now, return a placeholder
Ok(Runbook {
name: "placeholder".into(),
description: "TODO: implement YAML parser".into(),
version: "0.1.0".into(),
steps: vec![],
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_empty_returns_placeholder() {
let result = parse_yaml("").unwrap();
assert_eq!(result.name, "placeholder");
assert!(result.steps.is_empty());
}
}