diff --git a/bin/monrun/resources/deployments.toml b/bin/monrun/resources/deployments.toml index 12b4bdd17..fd5841ae0 100644 --- a/bin/monrun/resources/deployments.toml +++ b/bin/monrun/resources/deployments.toml @@ -1,6 +1,6 @@ [[deployment]] name = "monitor-proxy" -description = "" +description = "An NGINX proxy for mogh.tech" tags = ["monitor"] [deployment.config] diff --git a/bin/monrun/src/maps.rs b/bin/monrun/src/maps.rs index 628ca9383..402959a36 100644 --- a/bin/monrun/src/maps.rs +++ b/bin/monrun/src/maps.rs @@ -7,7 +7,7 @@ use monitor_client::{ builder::BuilderListItem, deployment::DeploymentListItem, procedure::ProcedureListItem, repo::RepoListItem, server::ServerListItem, server_template::ServerTemplateListItem, - user::User, user_group::UserGroup, + tag::Tag, user::User, user_group::UserGroup, }, }; @@ -258,7 +258,7 @@ pub fn name_to_user_group() -> &'static HashMap { futures::executor::block_on( monitor_client().read(read::ListUserGroups::default()), ) - .expect("failed to get procedures from monitor") + .expect("failed to get user groups from monitor") .into_iter() .map(|user_group| (user_group.name.clone(), user_group)) .collect() @@ -272,9 +272,22 @@ pub fn id_to_user() -> &'static HashMap { futures::executor::block_on( monitor_client().read(read::ListUsers::default()), ) - .expect("failed to get procedures from monitor") + .expect("failed to get users from monitor") .into_iter() .map(|user| (user.id.clone(), user)) .collect() }) } + +pub fn id_to_tag() -> &'static HashMap { + static ID_TO_TAG: OnceLock> = OnceLock::new(); + ID_TO_TAG.get_or_init(|| { + futures::executor::block_on( + monitor_client().read(read::ListTags::default()), + ) + .expect("failed to get tags from monitor") + .into_iter() + .map(|tag| (tag.id.clone(), tag)) + .collect() + }) +} diff --git a/bin/monrun/src/sync/resources/mod.rs b/bin/monrun/src/sync/resources/mod.rs index 2f65f1917..8b094504b 100644 --- a/bin/monrun/src/sync/resources/mod.rs +++ b/bin/monrun/src/sync/resources/mod.rs @@ -11,7 +11,7 @@ use monitor_client::{ }; use partial_derive2::MaybeNone; -use crate::{cli_args, monitor_client}; +use crate::{cli_args, maps::id_to_tag, monitor_client}; pub mod alerter; pub mod build; @@ -84,11 +84,19 @@ pub trait ResourceSync { Self::minimize_update(original.config, resource.config) .await?; + let original_tags = original + .tags + .iter() + .filter_map(|id| { + id_to_tag().get(id).map(|t| t.name.clone()) + }) + .collect::>(); + // Only try to update if there are any fields to update, // or a change to tags / description if !resource.config.is_none() || resource.description != original.description - || resource.tags != original.tags + || resource.tags != original_tags { to_update.push((id, resource)); }