(
&self,
kuma: &Client,
id: &String,
current: &Entity,
new: &Entity,
)
| 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(¤t, &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(¤t).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, ¤t).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 { |
no test coverage detected