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

Function check_glob_syntax

crates/openshell-supervisor-network/src/l7/mod.rs:406–442  ·  view source on GitHub ↗

Check a glob pattern for obvious syntax issues. Returns `Some(warning_message)` if the pattern looks malformed. OPA's `glob.match` is forgiving, so these are warnings (not errors) to surface likely typos without blocking policy loading.

(pattern: &str)

Source from the content-addressed store, hash-verified

404/// OPA's `glob.match` is forgiving, so these are warnings (not errors)
405/// to surface likely typos without blocking policy loading.
406fn check_glob_syntax(pattern: &str) -> Option<String> {
407 let mut bracket_depth: i32 = 0;
408 for c in pattern.chars() {
409 match c {
410 '[' => bracket_depth += 1,
411 ']' => {
412 if bracket_depth == 0 {
413 return Some(format!("glob pattern '{pattern}' has unmatched ']'"));
414 }
415 bracket_depth -= 1;
416 }
417 _ => {}
418 }
419 }
420 if bracket_depth > 0 {
421 return Some(format!("glob pattern '{pattern}' has unclosed '['"));
422 }
423
424 let mut brace_depth: i32 = 0;
425 for c in pattern.chars() {
426 match c {
427 '{' => brace_depth += 1,
428 '}' => {
429 if brace_depth == 0 {
430 return Some(format!("glob pattern '{pattern}' has unmatched '}}'"));
431 }
432 brace_depth -= 1;
433 }
434 _ => {}
435 }
436 }
437 if brace_depth > 0 {
438 return Some(format!("glob pattern '{pattern}' has unclosed '{{'"));
439 }
440
441 None
442}
443
444fn validate_host_wildcard(errors: &mut Vec<String>, loc: &str, host: &str) {
445 if !host.contains('*') {

Callers 5

validate_graphql_fieldsFunction · 0.85
validate_graphql_ruleFunction · 0.85
validate_matcher_valueFunction · 0.85
validate_l7_policiesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected