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

Method create_entity

autokuma/src/sync.rs:35–109  ·  view source on GitHub ↗
(&self, kuma: &Client, id: &String, entity: &Entity)

Source from the content-addressed store, hash-verified

33 }
34
35 async fn create_entity(&self, kuma: &Client, id: &String, entity: &Entity) -> Result<()> {
36 info!("Creating new {}: {}", entity.entity_type(), id);
37 match entity.clone() {
38 Entity::Monitor(monitor) => {
39 match kuma.add_monitor(monitor).await {
40 Ok(monitor) => {
41 let db_id = monitor.common().id().ok_or_else(|| {
42 KumaError::CommunicationError(
43 "Did not receive an id from Uptime Kuma".to_owned(),
44 )
45 })?;
46
47 self.app_state
48 .db
49 .store_id(Name::Monitor(id.clone()), db_id)?;
50
51 Ok(())
52 }
53 Err(err) => Err(err),
54 }?;
55 }
56 Entity::DockerHost(docker_host) => {
57 let db_id = kuma.add_docker_host(docker_host).await?.id.ok_or_else(|| {
58 KumaError::CommunicationError(
59 "Did not receive an id from Uptime Kuma".to_owned(),
60 )
61 })?;
62
63 self.app_state
64 .db
65 .store_id(Name::DockerHost(id.clone()), db_id)?;
66 }
67 Entity::Notification(notification) => {
68 let db_id = kuma
69 .add_notification(notification)
70 .await?
71 .id
72 .ok_or_else(|| {
73 KumaError::CommunicationError(
74 "Did not receive an id from Uptime Kuma".to_owned(),
75 )
76 })?;
77
78 self.app_state
79 .db
80 .store_id(Name::Notification(id.clone()), db_id)?;
81 }
82 Entity::StatusPage(status_page) => {
83 let db_id = kuma
84 .add_status_page(status_page)
85 .await?
86 .slug
87 .ok_or_else(|| {
88 KumaError::CommunicationError(
89 "Did not receive an id from Uptime Kuma".to_owned(),
90 )
91 })?;
92

Callers 2

update_entityMethod · 0.80
do_syncMethod · 0.80

Calls 12

MonitorEnum · 0.85
DockerHostClass · 0.85
NotificationClass · 0.85
StatusPageClass · 0.85
TagClass · 0.85
add_monitorMethod · 0.80
store_idMethod · 0.80
add_docker_hostMethod · 0.80
add_notificationMethod · 0.80
add_status_pageMethod · 0.80
add_tagMethod · 0.80
commonMethod · 0.45

Tested by

no test coverage detected