MCPcopy Create free account
hub / github.com/BigBoot/AutoKuma / verify_monitor

Method verify_monitor

kuma-client/src/client.rs:704–765  ·  view source on GitHub ↗
(self: &Arc<Self>, monitor: &Monitor)

Source from the content-addressed store, hash-verified

702 }
703
704 async fn verify_monitor(self: &Arc<Self>, monitor: &Monitor) -> Result<()> {
705 if let Some(referenced_parent) = monitor.common().parent() {
706 if !self
707 .monitors
708 .lock()
709 .await
710 .values()
711 .any(|m| m.common().id().is_some_and(|id| &id == referenced_parent))
712 {
713 return Err(Error::InvalidReference(
714 InvalidReferenceError::InvalidParent(referenced_parent.to_string()),
715 ));
716 }
717 }
718
719 if let Some(referenced_notifications) = monitor.common().notification_id_list() {
720 let available_notifications = self
721 .notifications
722 .lock()
723 .await
724 .iter()
725 .filter_map(|n| n.id)
726 .collect::<HashSet<_>>();
727
728 for (notification_id, _) in referenced_notifications {
729 if let Some(id) = notification_id.parse::<i32>().ok() {
730 if !available_notifications.contains(&id) {
731 return Err(Error::InvalidReference(
732 InvalidReferenceError::InvalidNotification(notification_id.to_owned()),
733 ));
734 }
735 } else {
736 return Err(Error::InvalidReference(
737 InvalidReferenceError::InvalidNotification(notification_id.to_owned()),
738 ));
739 }
740 }
741 }
742
743 if let Monitor::Docker {
744 value: docker_monitor,
745 } = monitor
746 {
747 if let Some(referenced_docker_host) = &docker_monitor.docker_host {
748 if !self
749 .docker_hosts
750 .lock()
751 .await
752 .iter()
753 .any(|dh| dh.id.is_some_and(|id| &id == referenced_docker_host))
754 {
755 return Err(Error::InvalidReference(
756 InvalidReferenceError::InvalidDockerHost(
757 referenced_docker_host.to_string(),
758 ),
759 ));
760 }
761 }

Callers 2

add_monitorMethod · 0.80
edit_monitorMethod · 0.80

Calls 2

iterMethod · 0.80
commonMethod · 0.45

Tested by

no test coverage detected