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

Function apply_operation

crates/openshell-policy/src/merge.rs:312–379  ·  view source on GitHub ↗
(
    policy: &mut SandboxPolicy,
    operation: &PolicyMergeOp,
    warnings: &mut Vec<PolicyMergeWarning>,
)

Source from the content-addressed store, hash-verified

310}
311
312fn apply_operation(
313 policy: &mut SandboxPolicy,
314 operation: &PolicyMergeOp,
315 warnings: &mut Vec<PolicyMergeWarning>,
316) -> Result<(), PolicyMergeError> {
317 match operation {
318 PolicyMergeOp::AddRule { rule_name, rule } => {
319 add_rule(policy, rule_name, rule, warnings)?;
320 }
321 PolicyMergeOp::RemoveEndpoint {
322 rule_name,
323 host,
324 port,
325 } => {
326 remove_endpoint(policy, rule_name.as_deref(), host, *port);
327 }
328 PolicyMergeOp::RemoveRule { rule_name } => {
329 policy.network_policies.remove(rule_name);
330 }
331 PolicyMergeOp::AddDenyRules {
332 host,
333 port,
334 deny_rules,
335 } => {
336 let endpoint = find_endpoint_mut(policy, host, *port).ok_or_else(|| {
337 PolicyMergeError::EndpointNotFound {
338 host: host.clone(),
339 port: *port,
340 }
341 })?;
342 ensure_method_path_endpoint(endpoint, host, *port)?;
343 if endpoint.access.is_empty() && endpoint.rules.is_empty() {
344 return Err(PolicyMergeError::EndpointHasNoAllowBase {
345 host: host.clone(),
346 port: *port,
347 });
348 }
349 append_unique_deny_rules(&mut endpoint.deny_rules, deny_rules);
350 }
351 PolicyMergeOp::AddAllowRules { host, port, rules } => {
352 let endpoint = find_endpoint_mut(policy, host, *port).ok_or_else(|| {
353 PolicyMergeError::EndpointNotFound {
354 host: host.clone(),
355 port: *port,
356 }
357 })?;
358 ensure_method_path_endpoint(endpoint, host, *port)?;
359 expand_existing_access(endpoint, host, *port, warnings)?;
360 append_unique_l7_rules(&mut endpoint.rules, rules);
361 }
362 PolicyMergeOp::RemoveBinary {
363 rule_name,
364 binary_path,
365 } => {
366 let should_remove = if let Some(rule) = policy.network_policies.get_mut(rule_name) {
367 let original_len = rule.binaries.len();
368 rule.binaries.retain(|binary| binary.path != *binary_path);
369 original_len != rule.binaries.len() && rule.binaries.is_empty()

Callers 1

merge_policyFunction · 0.85

Calls 10

add_ruleFunction · 0.85
remove_endpointFunction · 0.85
find_endpoint_mutFunction · 0.85
append_unique_deny_rulesFunction · 0.85
expand_existing_accessFunction · 0.85
append_unique_l7_rulesFunction · 0.85
lenMethod · 0.80
removeMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected