agent_orchestrator/config_load/validate/
agent_env.rs1use crate::config::{AgentConfig, EnvStoreConfig, OrchestratorConfig, SecretStoreConfig};
2use anyhow::Result;
3use std::collections::HashMap;
4
5fn validate_env_store_refs_for_agents(
7 agents: &HashMap<String, AgentConfig>,
8 env_stores: &HashMap<String, EnvStoreConfig>,
9 secret_stores: &HashMap<String, SecretStoreConfig>,
10 project_id: &str,
11) -> Result<()> {
12 for (agent_name, agent_cfg) in agents {
13 if let Some(ref entries) = agent_cfg.env {
14 for entry in entries {
15 if let Some(ref store_name) = entry.from_ref {
16 if !env_stores.contains_key(store_name.as_str())
17 && !secret_stores.contains_key(store_name.as_str())
18 {
19 anyhow::bail!(
20 "agent '{}'(project '{}') env fromRef '{}' references unknown store",
21 agent_name,
22 project_id,
23 store_name
24 );
25 }
26 }
27 if let Some(ref rv) = entry.ref_value {
28 if !env_stores.contains_key(&rv.name) && !secret_stores.contains_key(&rv.name) {
29 anyhow::bail!(
30 "agent '{}'(project '{}') env refValue.name '{}' references unknown store",
31 agent_name,
32 project_id,
33 rv.name
34 );
35 }
36 }
37 }
38 }
39 }
40 Ok(())
41}
42
43pub fn validate_agent_env_store_refs(config: &OrchestratorConfig) -> Result<()> {
46 for (project_id, project) in &config.projects {
47 validate_env_store_refs_for_agents(
48 &project.agents,
49 &project.env_stores,
50 &project.secret_stores,
51 project_id,
52 )?;
53 }
54 Ok(())
55}
56
57pub fn validate_agent_env_store_refs_for_project(
59 config: &OrchestratorConfig,
60 project_id: &str,
61) -> Result<()> {
62 if let Some(project) = config.projects.get(project_id) {
63 validate_env_store_refs_for_agents(
64 &project.agents,
65 &project.env_stores,
66 &project.secret_stores,
67 project_id,
68 )?;
69 }
70 Ok(())
71}
72
73pub fn validate_agent_command_rules(config: &OrchestratorConfig) -> Result<()> {
75 for project in config.projects.values() {
76 for (agent_id, agent_cfg) in &project.agents {
77 crate::prehook::validate_agent_command_rules(agent_id, &agent_cfg.command_rules)?;
78 }
79 }
80 Ok(())
81}
82
83pub fn validate_agent_command_rules_for_project(
85 config: &OrchestratorConfig,
86 project_id: &str,
87) -> Result<()> {
88 if let Some(project) = config.projects.get(project_id) {
89 for (agent_id, agent_cfg) in &project.agents {
90 crate::prehook::validate_agent_command_rules(agent_id, &agent_cfg.command_rules)?;
91 }
92 }
93 Ok(())
94}