(flag: &str, spec: &str)
| 242 | } |
| 243 | |
| 244 | fn parse_l7_rule_spec(flag: &str, spec: &str) -> Result<ParsedL7RuleSpec> { |
| 245 | let parts = spec.split(':').collect::<Vec<_>>(); |
| 246 | if parts.len() != 4 { |
| 247 | return Err(miette!( |
| 248 | "{flag} expects host:port:METHOD:path_glob, got '{spec}'" |
| 249 | )); |
| 250 | } |
| 251 | |
| 252 | let host = parse_host(flag, spec, parts[0])?; |
| 253 | let port = parse_port(flag, spec, parts[1])?; |
| 254 | let method = parts[2].trim(); |
| 255 | if method.is_empty() { |
| 256 | return Err(miette!("{flag} has an empty METHOD segment in '{spec}'")); |
| 257 | } |
| 258 | if method.contains(char::is_whitespace) { |
| 259 | return Err(miette!( |
| 260 | "{flag} METHOD must not contain whitespace in '{spec}'" |
| 261 | )); |
| 262 | } |
| 263 | |
| 264 | let path = parts[3].trim(); |
| 265 | if path.is_empty() { |
| 266 | return Err(miette!("{flag} has an empty path segment in '{spec}'")); |
| 267 | } |
| 268 | if !path.starts_with('/') && path != "**" && !path.starts_with("**/") { |
| 269 | return Err(miette!( |
| 270 | "{flag} path must start with '/' or be '**', got '{path}' in '{spec}'" |
| 271 | )); |
| 272 | } |
| 273 | |
| 274 | Ok(ParsedL7RuleSpec { |
| 275 | host, |
| 276 | port, |
| 277 | method: method.to_ascii_uppercase(), |
| 278 | path: path.to_string(), |
| 279 | }) |
| 280 | } |
| 281 | |
| 282 | fn parse_remove_endpoint_spec(spec: &str) -> Result<(String, u32)> { |
| 283 | let parts = spec.split(':').collect::<Vec<_>>(); |
no test coverage detected