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

Function apply_add_endpoint_options

crates/openshell-cli/src/policy_update.rs:354–408  ·  view source on GitHub ↗
(
    spec: &str,
    endpoint: &mut NetworkEndpoint,
    options: &str,
)

Source from the content-addressed store, hash-verified

352}
353
354fn apply_add_endpoint_options(
355 spec: &str,
356 endpoint: &mut NetworkEndpoint,
357 options: &str,
358) -> Result<()> {
359 if options.is_empty() {
360 return Ok(());
361 }
362
363 for option in options.split(',') {
364 let option = option.trim();
365 if option.is_empty() {
366 return Err(miette!(
367 "--add-endpoint options segment must not contain empty options in '{spec}'"
368 ));
369 }
370 match option {
371 "websocket-credential-rewrite" => {
372 ensure_websocket_credential_rewrite_protocol(spec, endpoint)?;
373 endpoint.websocket_credential_rewrite = true;
374 }
375 "request-body-credential-rewrite" => {
376 ensure_request_body_credential_rewrite_protocol(spec, endpoint)?;
377 endpoint.request_body_credential_rewrite = true;
378 }
379 _ => {
380 let Some(allowed_ip) = option.strip_prefix("allowed-ip=") else {
381 return Err(miette!(
382 "--add-endpoint options segment supports only 'websocket-credential-rewrite', 'request-body-credential-rewrite', and 'allowed-ip=<CIDR-or-IP>'; got '{option}' in '{spec}'"
383 ));
384 };
385 let allowed_ip = allowed_ip.trim();
386 if allowed_ip.is_empty() {
387 return Err(miette!(
388 "--add-endpoint allowed-ip option must include a CIDR or IP value in '{spec}'"
389 ));
390 }
391 if allowed_ip.contains(char::is_whitespace) {
392 return Err(miette!(
393 "--add-endpoint allowed-ip option must not contain whitespace in '{spec}'"
394 ));
395 }
396 if !endpoint
397 .allowed_ips
398 .iter()
399 .any(|existing| existing == allowed_ip)
400 {
401 endpoint.allowed_ips.push(allowed_ip.to_string());
402 }
403 }
404 }
405 }
406
407 Ok(())
408}
409
410fn parse_host(flag: &str, spec: &str, host: &str) -> Result<String> {
411 let host = host.trim();

Callers 1

parse_add_endpoint_specFunction · 0.85

Tested by

no test coverage detected