mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 19:59:46 -05:00
monrun / api better diffs
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -2626,18 +2626,18 @@ checksum = "ffa94c2e5674923c67d7f3dfce1279507b191e10eb064881b46ed3e1256e5ca6"
|
||||
|
||||
[[package]]
|
||||
name = "partial_derive2"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31b6b7e709fe09cf13aad8a2b1bb238155c11d3c11ef7c57b4b3ede3fd56edc2"
|
||||
checksum = "57fd88f09814d56f73ea68256ebdd2cdd75a4a3b48d41c63bbc27c46c6733588"
|
||||
dependencies = [
|
||||
"partial_derive2_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "partial_derive2_derive"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c763d2a4d3cd8cced727c4d969e968558b15e2e4da837127806f3341462ed0e8"
|
||||
checksum = "bdc7cb36e2cd4e6e7a53e3d35fd3321e1bd83382e0207901bff7ffb779cf7619"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
@@ -23,7 +23,7 @@ derive_empty_traits = "0.1.0"
|
||||
merge_config_files = "0.1.5"
|
||||
termination_signal = "0.1.3"
|
||||
async_timing_util = "0.1.14"
|
||||
partial_derive2 = "0.4.0"
|
||||
partial_derive2 = "0.4.1"
|
||||
derive_variants = "0.1.3"
|
||||
mongo_indexed = "0.2.2"
|
||||
resolver_api = "0.1.9"
|
||||
|
||||
@@ -259,7 +259,7 @@ impl Resolve<ExportResourcesToToml, User> for State {
|
||||
.await
|
||||
.context("failed to add user groups")?;
|
||||
|
||||
let toml = toml::to_string_pretty(&res)
|
||||
let toml = toml::to_string(&res)
|
||||
.context("failed to serialize resources to toml")?;
|
||||
|
||||
Ok(ExportResourcesToTomlResponse { toml })
|
||||
|
||||
@@ -58,8 +58,11 @@ pub trait MonitorResource {
|
||||
+ DeserializeOwned
|
||||
+ PartialDiff<Self::PartialConfig, Self::ConfigDiff>
|
||||
+ 'static;
|
||||
type PartialConfig: Into<Self::Config> + Serialize + MaybeNone;
|
||||
type ConfigDiff: Into<Self::PartialConfig> + Serialize + Diff;
|
||||
type PartialConfig: Into<Self::Config> + Serialize;
|
||||
type ConfigDiff: Into<Self::PartialConfig>
|
||||
+ Serialize
|
||||
+ Diff
|
||||
+ MaybeNone;
|
||||
type Info: Send
|
||||
+ Sync
|
||||
+ Unpin
|
||||
@@ -271,18 +274,23 @@ pub async fn create<T: MonitorResource>(
|
||||
mut config: T::PartialConfig,
|
||||
user: &User,
|
||||
) -> anyhow::Result<Resource<T::Config, T::Info>> {
|
||||
let name = to_monitor_name(name);
|
||||
if !T::user_can_create(user) {
|
||||
return Err(anyhow!(
|
||||
"User does not have permissions to create {}",
|
||||
T::resource_type()
|
||||
));
|
||||
}
|
||||
|
||||
let name = to_monitor_name(name);
|
||||
|
||||
if ObjectId::from_str(&name).is_ok() {
|
||||
return Err(anyhow!("valid ObjectIds cannot be used as names"));
|
||||
}
|
||||
|
||||
let start_ts = monitor_timestamp();
|
||||
|
||||
T::validate_create_config(&mut config, user).await?;
|
||||
|
||||
let resource = Resource::<T::Config, T::Info> {
|
||||
id: Default::default(),
|
||||
name,
|
||||
@@ -292,6 +300,7 @@ pub async fn create<T: MonitorResource>(
|
||||
config: config.into(),
|
||||
info: T::default_info().await?,
|
||||
};
|
||||
|
||||
let resource_id = T::coll()
|
||||
.await
|
||||
.insert_one(&resource, None)
|
||||
@@ -303,10 +312,13 @@ pub async fn create<T: MonitorResource>(
|
||||
.as_object_id()
|
||||
.context("inserted_id is not ObjectId")?
|
||||
.to_string();
|
||||
|
||||
let resource = get::<T>(&resource_id).await?;
|
||||
let target = resource_target::<T>(resource_id);
|
||||
|
||||
create_permission(user, target.clone(), PermissionLevel::Write)
|
||||
.await;
|
||||
|
||||
let mut update = make_update(target, T::create_operation(), user);
|
||||
update.start_ts = start_ts;
|
||||
update.push_simple_log(
|
||||
@@ -323,7 +335,9 @@ pub async fn create<T: MonitorResource>(
|
||||
serde_json::to_string_pretty(&resource.config)
|
||||
.context("failed to serialize resource config to JSON")?,
|
||||
);
|
||||
|
||||
T::post_create(&resource, &mut update).await?;
|
||||
|
||||
update.finalize();
|
||||
add_update(update).await?;
|
||||
|
||||
@@ -355,6 +369,10 @@ pub async fn update<T: MonitorResource>(
|
||||
// Gets a diff object.
|
||||
let diff = resource.config.partial_diff(config);
|
||||
|
||||
if diff.is_none() {
|
||||
return Err(anyhow!("update has no changes"));
|
||||
}
|
||||
|
||||
let mut diff_log = String::from("diff");
|
||||
|
||||
for FieldDiff { field, from, to } in diff.iter_field_diffs() {
|
||||
@@ -366,12 +384,6 @@ pub async fn update<T: MonitorResource>(
|
||||
// This minimizes the update against the existing config
|
||||
let config: T::PartialConfig = diff.into();
|
||||
|
||||
if config.is_none() {
|
||||
return Err(anyhow!(
|
||||
"Partial update has no changes to database state"
|
||||
));
|
||||
}
|
||||
|
||||
let id = resource.id.clone();
|
||||
|
||||
let config_doc = T::update_document(resource, config)
|
||||
|
||||
@@ -3,17 +3,11 @@
|
||||
name = "monitor-proxy"
|
||||
description = "An NGINX proxy for mogh.tech"
|
||||
tags = ["monitor"]
|
||||
|
||||
[deployment.config]
|
||||
server_id = "monitor-01"
|
||||
network = "host"
|
||||
restart = "on-failure"
|
||||
|
||||
[deployment.config.image]
|
||||
type = "Image"
|
||||
|
||||
[deployment.config.image.params]
|
||||
image = "jc21/nginx-proxy-manager"
|
||||
deployment.config.server_id = "monitor-01"
|
||||
deployment.config.network = "host"
|
||||
deployment.config.restart = "on-failure"
|
||||
deployment.config.image.type = "Image"
|
||||
deployment.config.image.params.image = "jc21/nginx-proxy-manager"
|
||||
|
||||
[[deployment.config.volumes]]
|
||||
local = "/data/nginx/data"
|
||||
|
||||
@@ -7,8 +7,7 @@ use monitor_client::{
|
||||
},
|
||||
entities::{
|
||||
alerter::{
|
||||
Alerter, AlerterConfig, AlerterInfo, AlerterListItemInfo,
|
||||
PartialAlerterConfig,
|
||||
Alerter, AlerterConfig, AlerterConfigDiff, AlerterInfo, AlerterListItemInfo, PartialAlerterConfig
|
||||
},
|
||||
resource::{Resource, ResourceListItem},
|
||||
toml::ResourceToml,
|
||||
@@ -22,9 +21,10 @@ use crate::{maps::name_to_alerter, monitor_client};
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for Alerter {
|
||||
type Config = AlerterConfig;
|
||||
type Info = AlerterInfo;
|
||||
type PartialConfig = PartialAlerterConfig;
|
||||
type FullConfig = AlerterConfig;
|
||||
type FullInfo = AlerterInfo;
|
||||
type ConfigDiff = AlerterConfigDiff;
|
||||
type ListItemInfo = AlerterListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -68,14 +68,14 @@ impl ResourceSync for Alerter {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client().read(GetAlerter { alerter: id }).await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
Ok(original.partial_diff(update).into())
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ use monitor_client::{
|
||||
},
|
||||
entities::{
|
||||
build::{
|
||||
Build, BuildConfig, BuildInfo, BuildListItemInfo,
|
||||
PartialBuildConfig,
|
||||
Build, BuildConfig, BuildConfigDiff, BuildInfo,
|
||||
BuildListItemInfo, PartialBuildConfig,
|
||||
},
|
||||
resource::{Resource, ResourceListItem},
|
||||
toml::ResourceToml,
|
||||
@@ -25,9 +25,10 @@ use crate::{
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for Build {
|
||||
type Config = BuildConfig;
|
||||
type Info = BuildInfo;
|
||||
type PartialConfig = PartialBuildConfig;
|
||||
type FullConfig = BuildConfig;
|
||||
type FullInfo = BuildInfo;
|
||||
type ConfigDiff = BuildConfigDiff;
|
||||
type ListItemInfo = BuildListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -71,20 +72,20 @@ impl ResourceSync for Build {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client().read(GetBuild { build: id }).await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
mut original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
mut original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
// need to replace the builder id with name
|
||||
original.builder_id = id_to_builder()
|
||||
.get(&original.builder_id)
|
||||
.map(|b| b.name.clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(original.partial_diff(update).into())
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use monitor_client::{
|
||||
},
|
||||
entities::{
|
||||
builder::{
|
||||
Builder, BuilderConfig, BuilderListItemInfo,
|
||||
Builder, BuilderConfig, BuilderConfigDiff, BuilderListItemInfo,
|
||||
PartialBuilderConfig,
|
||||
},
|
||||
resource::{Resource, ResourceListItem},
|
||||
@@ -25,9 +25,10 @@ use crate::{
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for Builder {
|
||||
type Config = BuilderConfig;
|
||||
type Info = ();
|
||||
type PartialConfig = PartialBuilderConfig;
|
||||
type FullConfig = BuilderConfig;
|
||||
type FullInfo = ();
|
||||
type ConfigDiff = BuilderConfigDiff;
|
||||
type ListItemInfo = BuilderListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -71,14 +72,14 @@ impl ResourceSync for Builder {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client().read(GetBuilder { builder: id }).await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
mut original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
mut original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
// need to replace server builder id with name
|
||||
if let BuilderConfig::Server(config) = &mut original {
|
||||
config.server_id = id_to_server()
|
||||
@@ -87,6 +88,6 @@ impl ResourceSync for Builder {
|
||||
.unwrap_or_default();
|
||||
}
|
||||
|
||||
Ok(original.partial_diff(update).into())
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ use monitor_client::{
|
||||
api::{read::GetDeployment, write},
|
||||
entities::{
|
||||
deployment::{
|
||||
Deployment, DeploymentConfig, DeploymentImage,
|
||||
DeploymentListItemInfo, PartialDeploymentConfig,
|
||||
Deployment, DeploymentConfig, DeploymentConfigDiff,
|
||||
DeploymentImage, DeploymentListItemInfo,
|
||||
PartialDeploymentConfig,
|
||||
},
|
||||
resource::{Resource, ResourceListItem},
|
||||
toml::ResourceToml,
|
||||
@@ -22,9 +23,10 @@ use crate::{
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for Deployment {
|
||||
type Config = DeploymentConfig;
|
||||
type Info = ();
|
||||
type PartialConfig = PartialDeploymentConfig;
|
||||
type FullConfig = DeploymentConfig;
|
||||
type FullInfo = ();
|
||||
type ConfigDiff = DeploymentConfigDiff;
|
||||
type ListItemInfo = DeploymentListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -68,16 +70,16 @@ impl ResourceSync for Deployment {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client()
|
||||
.read(GetDeployment { deployment: id })
|
||||
.await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
mut original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
mut original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
// need to replace the server id with name
|
||||
original.server_id = id_to_server()
|
||||
.get(&original.server_id)
|
||||
@@ -97,6 +99,6 @@ impl ResourceSync for Deployment {
|
||||
};
|
||||
}
|
||||
|
||||
Ok(original.partial_diff(update).into())
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use monitor_client::{
|
||||
update::ResourceTarget,
|
||||
},
|
||||
};
|
||||
use partial_derive2::MaybeNone;
|
||||
use partial_derive2::{Diff, FieldDiff, MaybeNone, PartialDiff};
|
||||
|
||||
use crate::{cli_args, maps::id_to_tag, monitor_client};
|
||||
|
||||
@@ -34,13 +34,17 @@ pub struct ToUpdateItem<T> {
|
||||
}
|
||||
|
||||
pub trait ResourceSync {
|
||||
type Config: Clone
|
||||
+ Send
|
||||
+ PartialDiff<Self::PartialConfig, Self::ConfigDiff>
|
||||
+ 'static;
|
||||
type Info: Default;
|
||||
type PartialConfig: std::fmt::Debug
|
||||
+ Clone
|
||||
+ Send
|
||||
+ MaybeNone
|
||||
+ From<Self::ConfigDiff>
|
||||
+ 'static;
|
||||
type FullConfig: Clone + Send + 'static;
|
||||
type FullInfo: Default;
|
||||
type ConfigDiff: Diff + MaybeNone;
|
||||
type ListItemInfo: 'static;
|
||||
|
||||
fn display() -> &'static str;
|
||||
@@ -63,14 +67,14 @@ pub trait ResourceSync {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>>;
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>>;
|
||||
|
||||
/// Diffs the declared toml (partial) against the full existing config.
|
||||
/// Removes all fields from toml (partial) that haven't changed.
|
||||
async fn minimize_update(
|
||||
original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig>;
|
||||
) -> anyhow::Result<Self::ConfigDiff>;
|
||||
|
||||
async fn get_updates(
|
||||
resources: Vec<ResourceToml<Self::PartialConfig>>,
|
||||
@@ -80,16 +84,16 @@ pub trait ResourceSync {
|
||||
let mut to_create = ToCreate::<Self::PartialConfig>::new();
|
||||
let mut to_update = ToUpdate::<Self::PartialConfig>::new();
|
||||
|
||||
let quiet = cli_args().quiet;
|
||||
|
||||
for mut resource in resources {
|
||||
match map.get(&resource.name).map(|s| s.id.clone()) {
|
||||
Some(id) => {
|
||||
// Get the full original config for the resource.
|
||||
let original = Self::get(id.clone()).await?;
|
||||
|
||||
// Minimizes updates through diffing.
|
||||
resource.config =
|
||||
Self::minimize_update(original.config, resource.config)
|
||||
.await?;
|
||||
let diff =
|
||||
Self::get_diff(original.config, resource.config).await?;
|
||||
|
||||
let original_tags = original
|
||||
.tags
|
||||
@@ -99,6 +103,38 @@ pub trait ResourceSync {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Only proceed if there are any fields to update,
|
||||
// or a change to tags / description
|
||||
if diff.is_none()
|
||||
&& resource.description == original.description
|
||||
&& resource.tags == original_tags
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if !quiet {
|
||||
println!(
|
||||
"{}: {}: {}\n{}",
|
||||
"UPDATE".blue(),
|
||||
Self::display(),
|
||||
resource.name,
|
||||
diff
|
||||
.iter_field_diffs()
|
||||
.map(|FieldDiff { field, from, to }| format!(
|
||||
"{}: {field}\n{}: {}\n{}: {to}",
|
||||
"field".dimmed(),
|
||||
"from".dimmed(),
|
||||
from.dimmed(),
|
||||
"to".dimmed(),
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
// Minimizes updates through diffing.
|
||||
resource.config = diff.into();
|
||||
|
||||
let update = ToUpdateItem {
|
||||
id,
|
||||
update_description: resource.description
|
||||
@@ -107,74 +143,41 @@ pub trait ResourceSync {
|
||||
resource,
|
||||
};
|
||||
|
||||
// Only try to update if there are any fields to update,
|
||||
// or a change to tags / description
|
||||
if !update.resource.config.is_none()
|
||||
|| update.update_description
|
||||
|| update.update_tags
|
||||
{
|
||||
to_update.push(update);
|
||||
}
|
||||
to_update.push(update);
|
||||
}
|
||||
None => {
|
||||
if !quiet {
|
||||
println!(
|
||||
"{}: {}: {}: {resource:#?}",
|
||||
"CREATE".green(),
|
||||
Self::display(),
|
||||
resource.name.bold().green(),
|
||||
)
|
||||
}
|
||||
to_create.push(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let quiet = cli_args().quiet;
|
||||
|
||||
if !to_create.is_empty() {
|
||||
if quiet {
|
||||
println!(
|
||||
"\n{}s {}: {:#?}",
|
||||
Self::display(),
|
||||
"TO CREATE".green(),
|
||||
to_create.iter().map(|item| item.name.as_str())
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"\n{}",
|
||||
to_create
|
||||
.iter()
|
||||
.map(|r| format!(
|
||||
"{}: {}: {}: {r:#?}",
|
||||
"CREATE".green(),
|
||||
Self::display(),
|
||||
r.name.bold().green(),
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n\n")
|
||||
);
|
||||
}
|
||||
if quiet && !to_create.is_empty() {
|
||||
println!(
|
||||
"\n{}s {}: {:#?}",
|
||||
Self::display(),
|
||||
"TO CREATE".green(),
|
||||
to_create.iter().map(|item| item.name.as_str())
|
||||
);
|
||||
}
|
||||
|
||||
if !to_update.is_empty() {
|
||||
if quiet {
|
||||
println!(
|
||||
"\n{}s {}: {:#?}",
|
||||
Self::display(),
|
||||
"TO UPDATE".blue(),
|
||||
to_update
|
||||
.iter()
|
||||
.map(|update| update.resource.name.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"\n{}",
|
||||
to_update
|
||||
.iter()
|
||||
.map(|ToUpdateItem { resource, .. }| format!(
|
||||
"{}: {}: {}: {resource:#?}",
|
||||
"UPDATE".blue(),
|
||||
Self::display(),
|
||||
resource.name.bold().green(),
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n\n")
|
||||
);
|
||||
}
|
||||
if quiet && !to_update.is_empty() {
|
||||
println!(
|
||||
"\n{}s {}: {:#?}",
|
||||
Self::display(),
|
||||
"TO UPDATE".blue(),
|
||||
to_update
|
||||
.iter()
|
||||
.map(|update| update.resource.name.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
Ok((to_create, to_update))
|
||||
@@ -226,15 +229,13 @@ pub trait ResourceSync {
|
||||
Self::update_tags(id.clone(), &name, tags).await;
|
||||
}
|
||||
|
||||
if !resource.config.is_none() {
|
||||
if let Err(e) = Self::update(id, resource).await {
|
||||
warn!(
|
||||
"failed to update config on {} {name} | {e:#}",
|
||||
Self::display()
|
||||
);
|
||||
} else {
|
||||
info!("updated {} {name} config", Self::display());
|
||||
}
|
||||
if let Err(e) = Self::update(id, resource).await {
|
||||
warn!(
|
||||
"failed to update config on {} {name} | {e:#}",
|
||||
Self::display()
|
||||
);
|
||||
} else {
|
||||
info!("updated {} {name} config", Self::display());
|
||||
}
|
||||
|
||||
info!("{} {name} updated", Self::display());
|
||||
|
||||
@@ -8,8 +8,7 @@ use monitor_client::{
|
||||
},
|
||||
entities::{
|
||||
procedure::{
|
||||
PartialProcedureConfig, Procedure, ProcedureConfig,
|
||||
ProcedureListItemInfo,
|
||||
PartialProcedureConfig, Procedure, ProcedureConfig, ProcedureConfigDiff, ProcedureListItemInfo
|
||||
},
|
||||
resource::{Resource, ResourceListItem},
|
||||
toml::ResourceToml,
|
||||
@@ -30,9 +29,10 @@ use crate::{
|
||||
use super::{ResourceSync, ToCreate, ToUpdate};
|
||||
|
||||
impl ResourceSync for Procedure {
|
||||
type Config = ProcedureConfig;
|
||||
type Info = ();
|
||||
type PartialConfig = PartialProcedureConfig;
|
||||
type FullConfig = ProcedureConfig;
|
||||
type FullInfo = ();
|
||||
type ConfigDiff = ProcedureConfigDiff;
|
||||
type ListItemInfo = ProcedureListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -159,14 +159,14 @@ impl ResourceSync for Procedure {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client().read(GetProcedure { procedure: id }).await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
mut original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
mut original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
for execution in &mut original.executions {
|
||||
match &mut execution.execution {
|
||||
Execution::None(_) => {}
|
||||
@@ -245,6 +245,6 @@ impl ResourceSync for Procedure {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(original.partial_diff(update).into())
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ use monitor_client::{
|
||||
},
|
||||
entities::{
|
||||
repo::{
|
||||
PartialRepoConfig, Repo, RepoConfig, RepoInfo, RepoListItemInfo,
|
||||
PartialRepoConfig, Repo, RepoConfig, RepoConfigDiff, RepoInfo,
|
||||
RepoListItemInfo,
|
||||
},
|
||||
resource::{Resource, ResourceListItem},
|
||||
toml::ResourceToml,
|
||||
@@ -24,9 +25,10 @@ use crate::{
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for Repo {
|
||||
type Config = RepoConfig;
|
||||
type Info = RepoInfo;
|
||||
type PartialConfig = PartialRepoConfig;
|
||||
type FullConfig = RepoConfig;
|
||||
type FullInfo = RepoInfo;
|
||||
type ConfigDiff = RepoConfigDiff;
|
||||
type ListItemInfo = RepoListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -70,20 +72,20 @@ impl ResourceSync for Repo {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client().read(GetRepo { repo: id }).await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
mut original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
mut original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
// Need to replace server id with name
|
||||
original.server_id = id_to_server()
|
||||
.get(&original.server_id)
|
||||
.map(|s| s.name.clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(original.partial_diff(update).into())
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ use monitor_client::{
|
||||
entities::{
|
||||
resource::{Resource, ResourceListItem},
|
||||
server::{
|
||||
PartialServerConfig, Server, ServerConfig, ServerListItemInfo,
|
||||
PartialServerConfig, Server, ServerConfig, ServerConfigDiff,
|
||||
ServerListItemInfo,
|
||||
},
|
||||
toml::ResourceToml,
|
||||
update::ResourceTarget,
|
||||
@@ -21,10 +22,11 @@ use crate::{maps::name_to_server, monitor_client};
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for Server {
|
||||
type ListItemInfo = ServerListItemInfo;
|
||||
type FullConfig = ServerConfig;
|
||||
type FullInfo = ();
|
||||
type Config = ServerConfig;
|
||||
type Info = ();
|
||||
type PartialConfig = PartialServerConfig;
|
||||
type ConfigDiff = ServerConfigDiff;
|
||||
type ListItemInfo = ServerListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
"server"
|
||||
@@ -67,14 +69,14 @@ impl ResourceSync for Server {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client().read(GetServer { server: id }).await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
Ok(original.partial_diff(update).into())
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ use monitor_client::{
|
||||
entities::{
|
||||
resource::{Resource, ResourceListItem},
|
||||
server_template::{
|
||||
PartialServerTemplateConfig, ServerTemplate,
|
||||
ServerTemplateConfig, ServerTemplateListItemInfo,
|
||||
PartialServerTemplateConfig, ServerTemplate, ServerTemplateConfig, ServerTemplateConfigDiff, ServerTemplateListItemInfo
|
||||
},
|
||||
toml::ResourceToml,
|
||||
update::ResourceTarget,
|
||||
@@ -22,9 +21,10 @@ use crate::{maps::name_to_server_template, monitor_client};
|
||||
use super::ResourceSync;
|
||||
|
||||
impl ResourceSync for ServerTemplate {
|
||||
type Config = ServerTemplateConfig;
|
||||
type Info = ();
|
||||
type PartialConfig = PartialServerTemplateConfig;
|
||||
type FullConfig = ServerTemplateConfig;
|
||||
type FullInfo = ();
|
||||
type ConfigDiff = ServerTemplateConfigDiff;
|
||||
type ListItemInfo = ServerTemplateListItemInfo;
|
||||
|
||||
fn display() -> &'static str {
|
||||
@@ -68,7 +68,7 @@ impl ResourceSync for ServerTemplate {
|
||||
|
||||
async fn get(
|
||||
id: String,
|
||||
) -> anyhow::Result<Resource<Self::FullConfig, Self::FullInfo>> {
|
||||
) -> anyhow::Result<Resource<Self::Config, Self::Info>> {
|
||||
monitor_client()
|
||||
.read(GetServerTemplate {
|
||||
server_template: id,
|
||||
@@ -76,10 +76,10 @@ impl ResourceSync for ServerTemplate {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn minimize_update(
|
||||
original: Self::FullConfig,
|
||||
async fn get_diff(
|
||||
original: Self::Config,
|
||||
update: Self::PartialConfig,
|
||||
) -> anyhow::Result<Self::PartialConfig> {
|
||||
Ok(original.partial_diff(update).into())
|
||||
) -> anyhow::Result<Self::ConfigDiff> {
|
||||
Ok(original.partial_diff(update))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,11 +145,11 @@ impl PartialDiff<PartialAlerterConfig, AlerterConfigDiff>
|
||||
}
|
||||
}
|
||||
|
||||
impl MaybeNone for PartialAlerterConfig {
|
||||
impl MaybeNone for AlerterConfigDiff {
|
||||
fn is_none(&self) -> bool {
|
||||
match self {
|
||||
PartialAlerterConfig::Custom(config) => config.is_none(),
|
||||
PartialAlerterConfig::Slack(config) => config.is_none(),
|
||||
AlerterConfigDiff::Custom(config) => config.is_none(),
|
||||
AlerterConfigDiff::Slack(config) => config.is_none(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,11 +129,11 @@ impl PartialDiff<PartialBuilderConfig, BuilderConfigDiff>
|
||||
}
|
||||
}
|
||||
|
||||
impl MaybeNone for PartialBuilderConfig {
|
||||
impl MaybeNone for BuilderConfigDiff {
|
||||
fn is_none(&self) -> bool {
|
||||
match self {
|
||||
PartialBuilderConfig::Server(config) => config.is_none(),
|
||||
PartialBuilderConfig::Aws(config) => config.is_none(),
|
||||
BuilderConfigDiff::Server(config) => config.is_none(),
|
||||
BuilderConfigDiff::Aws(config) => config.is_none(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,10 +109,10 @@ impl
|
||||
}
|
||||
}
|
||||
|
||||
impl MaybeNone for PartialServerTemplateConfig {
|
||||
impl MaybeNone for ServerTemplateConfigDiff {
|
||||
fn is_none(&self) -> bool {
|
||||
match self {
|
||||
PartialServerTemplateConfig::Aws(config) => config.is_none(),
|
||||
ServerTemplateConfigDiff::Aws(config) => config.is_none(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user