matchesPattern checks if a command matches an allowed pattern Supports exact matches and template patterns like "systemctl status {service}"
(command, pattern string)
| 54 | // matchesPattern checks if a command matches an allowed pattern |
| 55 | // Supports exact matches and template patterns like "systemctl status {service}" |
| 56 | func (v *Validator) matchesPattern(command, pattern string) bool { |
| 57 | // Exact match |
| 58 | if command == pattern { |
| 59 | return true |
| 60 | } |
| 61 | |
| 62 | // Template match |
| 63 | template := ParseTemplate(pattern) |
| 64 | if len(template.Parameters) == 0 { |
| 65 | // No parameters, must be exact match |
| 66 | return false |
| 67 | } |
| 68 | |
| 69 | // Check if command structure matches template |
| 70 | return v.matchesTemplateStructure(command, template) |
| 71 | } |
| 72 | |
| 73 | // matchesTemplateStructure checks if a command matches the structure of a template |
| 74 | func (v *Validator) matchesTemplateStructure(command string, template CommandTemplate) bool { |
no test coverage detected