Skip to main content

agent_orchestrator/
config_ext.rs

1//! Extension trait adding CRD-projected accessors to `OrchestratorConfig`.
2//!
3//! These methods depend on `CrdProjectable` which stays in core because its
4//! implementations reference resource converters.
5
6use crate::config::OrchestratorConfig;
7use crate::crd::projection::RuntimePolicyProjection;
8use crate::crd::store::ResourceStoreExt;
9
10/// Extension methods for `OrchestratorConfig` that require CRD projection.
11pub trait OrchestratorConfigExt {
12    /// Returns the `RuntimePolicyProjection` from the resource store, or defaults.
13    fn runtime_policy(&self) -> RuntimePolicyProjection;
14
15    /// Returns the `RuntimePolicyProjection` scoped to a specific project.
16    ///
17    /// Falls back to the `_system` project, then to defaults. This prevents
18    /// RuntimePolicy resources from other projects from contaminating the
19    /// runner configuration.
20    fn runtime_policy_for_project(&self, project: &str) -> RuntimePolicyProjection;
21}
22
23impl OrchestratorConfigExt for OrchestratorConfig {
24    fn runtime_policy(&self) -> RuntimePolicyProjection {
25        self.resource_store
26            .project_singleton::<RuntimePolicyProjection>()
27            .unwrap_or_default()
28    }
29
30    fn runtime_policy_for_project(&self, project: &str) -> RuntimePolicyProjection {
31        // Try project-specific RuntimePolicy first
32        if let Some(rp) = self
33            .resource_store
34            .project_singleton_for_project::<RuntimePolicyProjection>(project)
35        {
36            return rp;
37        }
38        // Fall back to _system project
39        if let Some(rp) = self
40            .resource_store
41            .project_singleton_for_project::<RuntimePolicyProjection>(
42                orchestrator_config::resource_store::SYSTEM_PROJECT,
43            )
44        {
45            return rp;
46        }
47        // Final fallback: defaults
48        RuntimePolicyProjection::default()
49    }
50}