mod agent;
mod approval;
mod http;
mod shell;
mod workflow;
pub use agent::AgentStepConfig;
pub use approval::ApprovalConfig;
pub use http::HttpConfig;
pub use shell::ShellConfig;
pub use workflow::WorkflowStepConfig;
use ironflow_store::entities::StepKind;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum StepConfig {
Shell(ShellConfig),
Http(HttpConfig),
Agent(AgentStepConfig),
Workflow(WorkflowStepConfig),
Approval(ApprovalConfig),
}
impl StepConfig {
pub fn kind(&self) -> StepKind {
match self {
StepConfig::Shell(_) => StepKind::Shell,
StepConfig::Http(_) => StepKind::Http,
StepConfig::Agent(_) => StepKind::Agent,
StepConfig::Workflow(_) => StepKind::Workflow,
StepConfig::Approval(_) => StepKind::Approval,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serde_roundtrip() {
let configs = vec![
StepConfig::Shell(ShellConfig::new("echo test")),
StepConfig::Http(HttpConfig::get("http://example.com")),
StepConfig::Agent(AgentStepConfig::new("summarize")),
StepConfig::Workflow(WorkflowStepConfig::new("build", serde_json::json!({}))),
StepConfig::Approval(ApprovalConfig::new("Deploy to production?")),
];
for config in configs {
let json = serde_json::to_string(&config).expect("serialize");
let back: StepConfig = serde_json::from_str(&json).expect("deserialize");
let json2 = serde_json::to_string(&back).expect("serialize2");
assert_eq!(json, json2);
}
}
}