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

Function parse_l7_rule_spec

crates/openshell-cli/src/policy_update.rs:244–280  ·  view source on GitHub ↗
(flag: &str, spec: &str)

Source from the content-addressed store, hash-verified

242}
243
244fn 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
282fn parse_remove_endpoint_spec(spec: &str) -> Result<(String, u32)> {
283 let parts = spec.split(':').collect::<Vec<_>>();

Callers 2

group_allow_rulesFunction · 0.85
group_deny_rulesFunction · 0.85

Calls 4

parse_portFunction · 0.85
lenMethod · 0.80
parse_hostFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected