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

Function validate_name

crates/openshell-driver-podman/src/client.rs:57–85  ·  view source on GitHub ↗

Validate that a resource name is safe for URL path interpolation. Valid names start with an alphanumeric character and contain only alphanumerics, dots, underscores, and hyphens — matching Podman's own naming rules. Names longer than [`MAX_NAME_LEN`] are rejected.

(name: &str)

Source from the content-addressed store, hash-verified

55/// alphanumerics, dots, underscores, and hyphens — matching Podman's
56/// own naming rules. Names longer than [`MAX_NAME_LEN`] are rejected.
57pub fn validate_name(name: &str) -> Result<(), PodmanApiError> {
58 // Regex-equivalent: ^[a-zA-Z0-9][a-zA-Z0-9._-]*$
59 if name.is_empty() {
60 return Err(PodmanApiError::InvalidInput(
61 "name must not be empty".to_string(),
62 ));
63 }
64 if name.len() > MAX_NAME_LEN {
65 return Err(PodmanApiError::InvalidInput(format!(
66 "name exceeds maximum length of {MAX_NAME_LEN} characters (got {})",
67 name.len()
68 )));
69 }
70 let bytes = name.as_bytes();
71 if !bytes[0].is_ascii_alphanumeric() {
72 return Err(PodmanApiError::InvalidInput(format!(
73 "name must start with an alphanumeric character: {name:?}"
74 )));
75 }
76 if !bytes
77 .iter()
78 .all(|&b| b.is_ascii_alphanumeric() || b == b'.' || b == b'_' || b == b'-')
79 {
80 return Err(PodmanApiError::InvalidInput(format!(
81 "name contains invalid characters: {name:?}"
82 )));
83 }
84 Ok(())
85}
86
87/// A container state snapshot returned by inspect APIs.
88#[derive(Debug, Clone, serde::Deserialize)]

Callers 10

validated_container_nameFunction · 0.85
start_containerMethod · 0.85
stop_containerMethod · 0.85
remove_containerMethod · 0.85
inspect_containerMethod · 0.85
create_volumeMethod · 0.85
remove_volumeMethod · 0.85
inspect_volumeMethod · 0.85
ensure_networkMethod · 0.85
network_gateway_ipMethod · 0.85

Calls 2

lenMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected