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

Function remove_endpoint

crates/openshell-policy/src/merge.rs:869–913  ·  view source on GitHub ↗
(policy: &mut SandboxPolicy, rule_name: Option<&str>, host: &str, port: u32)

Source from the content-addressed store, hash-verified

867}
868
869fn remove_endpoint(policy: &mut SandboxPolicy, rule_name: Option<&str>, host: &str, port: u32) {
870 let target_keys: Vec<String> = if let Some(rule_name) = rule_name {
871 if policy.network_policies.contains_key(rule_name) {
872 vec![rule_name.to_string()]
873 } else {
874 vec![]
875 }
876 } else {
877 let mut keys: Vec<_> = policy.network_policies.keys().cloned().collect();
878 keys.sort();
879 keys
880 };
881
882 let mut empty_rules = Vec::new();
883 for key in target_keys {
884 if let Some(rule) = policy.network_policies.get_mut(&key) {
885 rule.endpoints.retain_mut(|endpoint| {
886 if !endpoint_matches_host_port(endpoint, host, port) {
887 return true;
888 }
889
890 let mut remaining_ports = canonical_ports(endpoint);
891 remaining_ports.retain(|existing_port| *existing_port != port);
892 remaining_ports.sort_unstable();
893 remaining_ports.dedup();
894
895 if remaining_ports.is_empty() {
896 return false;
897 }
898
899 endpoint.port = remaining_ports[0];
900 endpoint.ports = remaining_ports;
901 true
902 });
903
904 if rule.endpoints.is_empty() {
905 empty_rules.push(key);
906 }
907 }
908 }
909
910 for key in empty_rules {
911 policy.network_policies.remove(&key);
912 }
913}
914
915#[cfg(test)]
916mod tests {

Callers 1

apply_operationFunction · 0.85

Calls 6

canonical_portsFunction · 0.85
contains_keyMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected