Validate that object metadata is present and contains required fields. This ensures that all resources have valid metadata with non-empty ID and name, preventing issues where missing metadata could lead to security vulnerabilities (e.g., empty string IDs/names matching unintended resources). Returns `INVALID_ARGUMENT` if metadata is missing or invalid.
(
metadata: Option<&openshell_core::proto::datamodel::v1::ObjectMeta>,
resource_type: &str,
)
| 584 | /// |
| 585 | /// Returns `INVALID_ARGUMENT` if metadata is missing or invalid. |
| 586 | pub(super) fn validate_object_metadata( |
| 587 | metadata: Option<&openshell_core::proto::datamodel::v1::ObjectMeta>, |
| 588 | resource_type: &str, |
| 589 | ) -> Result<(), Status> { |
| 590 | let metadata = metadata |
| 591 | .ok_or_else(|| Status::invalid_argument(format!("{resource_type} metadata is required")))?; |
| 592 | |
| 593 | if metadata.id.is_empty() { |
| 594 | return Err(Status::invalid_argument(format!( |
| 595 | "{resource_type} metadata.id cannot be empty" |
| 596 | ))); |
| 597 | } |
| 598 | |
| 599 | if metadata.name.is_empty() { |
| 600 | return Err(Status::invalid_argument(format!( |
| 601 | "{resource_type} metadata.name cannot be empty" |
| 602 | ))); |
| 603 | } |
| 604 | |
| 605 | // Validate all labels in metadata |
| 606 | for (key, value) in &metadata.labels { |
| 607 | validate_label_key(key)?; |
| 608 | validate_label_value(value)?; |
| 609 | } |
| 610 | |
| 611 | Ok(()) |
| 612 | } |
| 613 | |
| 614 | // --------------------------------------------------------------------------- |
| 615 | // Policy validation |
nothing calls this directly
no test coverage detected