Skip to main content

agent_orchestrator/resource/
mod.rs

1use crate::cli_types::ResourceKind;
2use crate::config::OrchestratorConfig;
3use anyhow::Result;
4
5pub(crate) const API_VERSION: &str = "orchestrator.dev/v2";
6
7// ── Submodules ────────────────────────────────────────────────────────────────
8
9pub(crate) mod agent;
10mod env_store;
11pub(crate) mod execution_profile;
12mod export;
13mod parse;
14mod project;
15pub(crate) mod runtime_policy;
16mod secret_store;
17mod step_template;
18mod trigger;
19pub(crate) mod workflow;
20pub(crate) mod workspace;
21
22mod apply;
23pub(crate) mod helpers;
24mod registry;
25#[cfg(test)]
26pub(crate) mod test_fixtures;
27mod tests;
28
29// ── Re-exports (resource types from existing submodules) ──────────────────────
30
31pub use agent::AgentResource;
32pub use env_store::EnvStoreResource;
33pub use execution_profile::ExecutionProfileResource;
34pub use export::{export_crd_documents, export_manifest_documents, export_manifest_resources};
35pub use parse::{
36    delete_resource_by_kind, kind_as_str, parse_manifests_from_yaml, parse_resources_from_yaml,
37};
38pub use project::ProjectResource;
39pub use runtime_policy::RuntimePolicyResource;
40pub use secret_store::SecretStoreResource;
41pub use step_template::StepTemplateResource;
42pub use trigger::TriggerResource;
43pub use workflow::WorkflowResource;
44pub use workspace::WorkspaceResource;
45
46// ── Re-exports (from new submodules) ──────────────────────────────────────────
47
48pub use helpers::metadata_from_store;
49pub(crate) use helpers::{
50    apply_to_store, delete_from_store, manifest_yaml, metadata_with_name, serializes_equal,
51    validate_resource_name,
52};
53pub use registry::*;
54// apply_to_map is used by individual resource apply methods via super::
55pub use apply::apply_to_project;
56
57// ── Re-exports (cli_types used by submodules via super::) ─────────────────────
58
59pub(crate) use crate::cli_types::ResourceMetadata;
60
61// ── Core types ────────────────────────────────────────────────────────────────
62
63pub use orchestrator_config::resource_store::ApplyResult;
64
65/// Common behavior implemented by builtin manifest resource adapters.
66pub trait Resource: Sized {
67    /// Returns the builtin resource kind.
68    fn kind(&self) -> ResourceKind;
69    /// Returns the resource name.
70    fn name(&self) -> &str;
71    /// Validates the resource contents before apply.
72    fn validate(&self) -> Result<()>;
73    /// Applies the resource into the provided config.
74    fn apply(&self, config: &mut OrchestratorConfig) -> Result<ApplyResult>;
75    /// Serializes the resource back into manifest YAML.
76    fn to_yaml(&self) -> Result<String>;
77
78    /// Project-scoped resource lookup. `project_id` of `None` defaults to the
79    /// default project (via `OrchestratorConfig::effective_project_id`).
80    fn get_from_project(
81        config: &OrchestratorConfig,
82        name: &str,
83        project_id: Option<&str>,
84    ) -> Option<Self>;
85
86    /// Project-scoped resource deletion. `project_id` of `None` defaults to
87    /// the default project.
88    fn delete_from_project(
89        config: &mut OrchestratorConfig,
90        name: &str,
91        project_id: Option<&str>,
92    ) -> bool;
93
94    /// Convenience: lookup in the default project.
95    fn get_from(config: &OrchestratorConfig, name: &str) -> Option<Self> {
96        Self::get_from_project(config, name, None)
97    }
98
99    /// Convenience: delete from the default project.
100    fn delete_from(config: &mut OrchestratorConfig, name: &str) -> bool {
101        Self::delete_from_project(config, name, None)
102    }
103}