MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / validate_object_metadata

Function validate_object_metadata

crates/openshell-server/src/grpc/validation.rs:586–612  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

584///
585/// Returns `INVALID_ARGUMENT` if metadata is missing or invalid.
586pub(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

Callers

nothing calls this directly

Calls 3

validate_label_keyFunction · 0.85
validate_label_valueFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected