splitTemplate splits a template string into static parts e.g., "systemctl status {service}" -> ["systemctl status ", ""]
(template string)
| 99 | // splitTemplate splits a template string into static parts |
| 100 | // e.g., "systemctl status {service}" -> ["systemctl status ", ""] |
| 101 | func (v *Validator) splitTemplate(template string) []string { |
| 102 | var parts []string |
| 103 | var current strings.Builder |
| 104 | inParam := false |
| 105 | |
| 106 | for _, ch := range template { |
| 107 | if ch == '{' { |
| 108 | if current.Len() > 0 { |
| 109 | parts = append(parts, current.String()) |
| 110 | current.Reset() |
| 111 | } |
| 112 | inParam = true |
| 113 | } else if ch == '}' { |
| 114 | inParam = false |
| 115 | } else if !inParam { |
| 116 | current.WriteRune(ch) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if current.Len() > 0 { |
| 121 | parts = append(parts, current.String()) |
| 122 | } |
| 123 | |
| 124 | return parts |
| 125 | } |
| 126 | |
| 127 | // GetAllowedCommands returns the list of allowed commands for a target type |
| 128 | func (v *Validator) GetAllowedCommands(targetType TargetType) []string { |
no test coverage detected