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

Function validate_string_map

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

Validate a `map ` field: entry count, key length, value length.

(
    map: &std::collections::HashMap<String, String>,
    max_entries: usize,
    max_key_len: usize,
    max_value_len: usize,
    field_name: &str,
)

Source from the content-addressed store, hash-verified

220
221/// Validate a `map<string, string>` field: entry count, key length, value length.
222pub(super) fn validate_string_map(
223 map: &std::collections::HashMap<String, String>,
224 max_entries: usize,
225 max_key_len: usize,
226 max_value_len: usize,
227 field_name: &str,
228) -> Result<(), Status> {
229 if map.len() > max_entries {
230 return Err(Status::invalid_argument(format!(
231 "{field_name} exceeds maximum entries ({} > {max_entries})",
232 map.len()
233 )));
234 }
235 for (key, value) in map {
236 if key.len() > max_key_len {
237 return Err(Status::invalid_argument(format!(
238 "{field_name} key exceeds maximum length ({} > {max_key_len})",
239 key.len()
240 )));
241 }
242 if value.len() > max_value_len {
243 return Err(Status::invalid_argument(format!(
244 "{field_name} value exceeds maximum length ({} > {max_value_len})",
245 value.len()
246 )));
247 }
248 }
249 Ok(())
250}
251
252/// OPENSHELL_* keys that are allowed in exec environment. The Python SDK's
253/// `exec_python()` sends a serialized callable via this key.

Callers 3

validate_sandbox_specFunction · 0.85

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected