brokkr-agent::utils
Rust
Functions
Section titled “Functions”fn multidoc_deserialize
Section titled “fn multidoc_deserialize”pub
fn multidoc_deserialize( multi_doc_str: &str,) -> Result<Vec<serde_yaml::Value>, Box<dyn Error>>Deserializes a multi-document YAML string into a vector of YAML values.
Parameters:
| Name | Type | Description |
|---|---|---|
multi_doc_str |
&str |
String containing multiple YAML documents |
Returns:
Result<Vec<serde_yaml::Value>, Box<dyn Error>>- Vector of parsed YAML values or error
Source
pub fn multidoc_deserialize(multi_doc_str: &str) -> Result<Vec<serde_yaml::Value>, Box<dyn Error>> { let mut docs = vec![]; for d in serde_yaml::Deserializer::from_str(multi_doc_str) { docs.push(serde_yaml::Value::deserialize(d)?); } Ok(docs)}fn manifest_namespaces
Section titled “fn manifest_namespaces”pub
fn manifest_namespaces(multi_doc_str: &str) -> Vec<String>Extracts the unique Kubernetes namespaces referenced by a multi-document YAML manifest, in first-seen order. Documents without an explicit metadata.namespace contribute "default" (BROKKR-T-0190).
Parameters:
| Name | Type | Description |
|---|---|---|
multi_doc_str |
&str |
String containing multiple YAML documents |
Returns:
Vec<String>- Unique namespaces;["default"]when the manifest is empty or unparseable so callers always have somewhere to search
Source
pub fn manifest_namespaces(multi_doc_str: &str) -> Vec<String> { let mut namespaces: Vec<String> = Vec::new(); if let Ok(docs) = multidoc_deserialize(multi_doc_str) { for doc in docs { if doc.is_null() { continue; } let ns = doc .get("metadata") .and_then(|m| m.get("namespace")) .and_then(|n| n.as_str()) .unwrap_or("default") .to_string(); if !namespaces.contains(&ns) { namespaces.push(ns); } } } if namespaces.is_empty() { namespaces.push("default".to_string()); } namespaces}