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)
| 404 | /// OPA's `glob.match` is forgiving, so these are warnings (not errors) |
| 405 | /// to surface likely typos without blocking policy loading. |
| 406 | fn 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 | |
| 444 | fn validate_host_wildcard(errors: &mut Vec<String>, loc: &str, host: &str) { |
| 445 | if !host.contains('*') { |
no outgoing calls
no test coverage detected