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

Method update_entity

autokuma/src/sync.rs:134–182  ·  view source on GitHub ↗
(
        &self,
        kuma: &Client,
        id: &String,
        current: &Entity,
        new: &Entity,
    )

Source from the content-addressed store, hash-verified

132 }
133
134 async fn update_entity(
135 &self,
136 kuma: &Client,
137 id: &String,
138 current: &Entity,
139 new: &Entity,
140 ) -> Result<()> {
141 let merge = merge_entities(&current, &new, None);
142
143 if current != &merge {
144 debug!(
145 "\n======= OLD =======\n{}\n===================\n\n======= NEW =======\n{}\n===================",
146 serde_json::to_string_pretty(&current).unwrap(),
147 serde_json::to_string_pretty(&merge).unwrap()
148 );
149
150 if current.entity_type() != new.entity_type() {
151 info!(
152 "Recreating entity because type changed: {} ({:?} -> {:?})",
153 id,
154 current.entity_type(),
155 new.entity_type()
156 );
157 self.delete_entity(kuma, id, &current).await?;
158 self.create_entity(kuma, id, &new).await?;
159 return Ok(());
160 }
161
162 info!("Updating {}: {}", new.entity_type(), id);
163
164 match (merge, current) {
165 (Entity::Monitor(merge), Entity::Monitor(_)) => {
166 kuma.edit_monitor(merge).await?;
167 }
168 (Entity::DockerHost(merge), Entity::DockerHost(_)) => {
169 kuma.edit_docker_host(merge).await?;
170 }
171 (Entity::Notification(merge), Entity::Notification(_)) => {
172 kuma.edit_notification(merge).await?;
173 }
174 (Entity::Tag(merge), Entity::Tag(_)) => {
175 kuma.edit_tag(merge).await?;
176 }
177 _ => {}
178 }
179 }
180
181 Ok(())
182 }
183
184 fn create_entity_selector(name: String, entity: &Entity) -> Result<Option<EntitySelector>> {
185 Ok(match entity {

Callers 1

do_syncMethod · 0.80

Calls 8

merge_entitiesFunction · 0.85
entity_typeMethod · 0.80
delete_entityMethod · 0.80
create_entityMethod · 0.80
edit_monitorMethod · 0.80
edit_docker_hostMethod · 0.80
edit_notificationMethod · 0.80
edit_tagMethod · 0.80

Tested by

no test coverage detected