From c5a66709add0e12eb15b410f16055644d31f636a Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 11 Jun 2023 17:49:14 +0000 Subject: [PATCH] partial derive working --- Cargo.lock | 21 ++++++++++ Cargo.toml | 2 + core/src/config.rs | 1 + core/src/main.rs | 2 +- core/src/resolvers/mod.rs | 2 +- lib/helpers/src/lib.rs | 2 +- lib/types/Cargo.toml | 4 +- lib/types/src/api/mod.rs | 2 +- lib/types/src/api/requests.rs | 1 + lib/types/src/entities/build.rs | 50 +++++++++++++++++++++++ lib/types/src/entities/deployment.rs | 49 ++++++++++++++++++++++ lib/types/src/entities/mod.rs | 1 + lib/types/src/entities/server/mod.rs | 2 +- lib/types/src/entities/server/stats.rs | 4 +- periphery/src/helpers/docker/build.rs | 2 +- periphery/src/helpers/docker/container.rs | 4 +- periphery/src/helpers/git.rs | 2 +- periphery/src/requests/mod.rs | 2 +- tests/Cargo.toml | 4 +- tests/src/main.rs | 48 +++++++++++----------- 20 files changed, 167 insertions(+), 38 deletions(-) create mode 100644 lib/types/src/entities/build.rs diff --git a/Cargo.lock b/Cargo.lock index aae39717a..e8ed2b0db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1069,6 +1069,12 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" +[[package]] +name = "make_option" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99f3d3fcb53f2f961c24cc6042513be5c782d2c969b04f02ae14d7edbdca34e5" + [[package]] name = "matchit" version = "0.7.0" @@ -1191,6 +1197,8 @@ dependencies = [ "bson", "derive_builder", "diff-struct", + "make_option", + "partial_derive2", "resolver_api", "serde", "serde_json", @@ -1400,6 +1408,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffa94c2e5674923c67d7f3dfce1279507b191e10eb064881b46ed3e1256e5ca6" +[[package]] +name = "partial_derive2" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75fabf7c9ed3ad64f33d05d4c8a7f180217c667892044a8088fe93f984bdeb17" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "percent-encoding" version = "2.3.0" @@ -1977,6 +1996,8 @@ dependencies = [ "monitor_client", "monitor_types", "periphery_client", + "serde", + "serde_json", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index a29118976..4093aeb38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,8 @@ strum = "0.24" strum_macros = "0.24" sysinfo = "0.29" async-trait = "0.1" +partial_derive2 = "0.1.2" +make_option = "0.1.2" # mogh run_command = { version = "0.0.6", features = ["async_tokio"] } slack = { package = "slack_client_rs", version = "0.0.8" } diff --git a/core/src/config.rs b/core/src/config.rs index e69de29bb..8b1378917 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -0,0 +1 @@ + diff --git a/core/src/main.rs b/core/src/main.rs index 383f17f76..f668bac3b 100644 --- a/core/src/main.rs +++ b/core/src/main.rs @@ -1,8 +1,8 @@ use termination_signal::tokio::immediate_term_handle; mod config; -mod state; mod resolvers; +mod state; async fn app() -> anyhow::Result<()> { Ok(()) diff --git a/core/src/resolvers/mod.rs b/core/src/resolvers/mod.rs index 8a4a5131f..c77b4a374 100644 --- a/core/src/resolvers/mod.rs +++ b/core/src/resolvers/mod.rs @@ -1,5 +1,5 @@ use resolver_api::derive::Resolver; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use crate::state::State; diff --git a/lib/helpers/src/lib.rs b/lib/helpers/src/lib.rs index 10ba8f7f9..75a29a9f3 100644 --- a/lib/helpers/src/lib.rs +++ b/lib/helpers/src/lib.rs @@ -1,3 +1,3 @@ pub fn to_monitor_name(name: &str) -> String { name.to_lowercase().replace(' ', "_") -} \ No newline at end of file +} diff --git a/lib/types/Cargo.toml b/lib/types/Cargo.toml index 454ca4800..defc4087a 100644 --- a/lib/types/Cargo.toml +++ b/lib/types/Cargo.toml @@ -20,4 +20,6 @@ bson.workspace = true async_timing_util.workspace = true resolver_api.workspace = true derive_builder.workspace = true -bollard.workspace = true \ No newline at end of file +bollard.workspace = true +partial_derive2.workspace = true +make_option.workspace = true \ No newline at end of file diff --git a/lib/types/src/api/mod.rs b/lib/types/src/api/mod.rs index 4e83d422e..0ad326568 100644 --- a/lib/types/src/api/mod.rs +++ b/lib/types/src/api/mod.rs @@ -1 +1 @@ -pub mod requests; \ No newline at end of file +pub mod requests; diff --git a/lib/types/src/api/requests.rs b/lib/types/src/api/requests.rs index e69de29bb..8b1378917 100644 --- a/lib/types/src/api/requests.rs +++ b/lib/types/src/api/requests.rs @@ -0,0 +1 @@ + diff --git a/lib/types/src/entities/build.rs b/lib/types/src/entities/build.rs new file mode 100644 index 000000000..8cc6a194d --- /dev/null +++ b/lib/types/src/entities/build.rs @@ -0,0 +1,50 @@ +use bson::serde_helpers::hex_string_as_object_id; +use derive_builder::Builder; +use diff::Diff; +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; + +use super::PermissionsMap; + +#[typeshare] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Diff, Builder)] +#[diff(attr(#[derive(Debug, Serialize)]))] +pub struct Deployment { + #[serde( + default, + rename = "_id", + skip_serializing_if = "String::is_empty", + with = "hex_string_as_object_id" + )] + #[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))] + #[builder(setter(skip))] + pub id: String, + + #[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))] + pub name: String, + + #[serde(default)] + #[builder(default)] + #[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))] + pub description: String, + + #[serde(default)] + #[diff(attr(#[serde(skip_serializing)]))] + #[builder(setter(skip))] + pub permissions: PermissionsMap, + + #[serde(default, skip_serializing_if = "String::is_empty")] + #[diff(attr(#[serde(skip)]))] + #[builder(setter(skip))] + pub created_at: String, + + #[serde(default)] + #[diff(attr(#[serde(skip)]))] + #[builder(setter(skip))] + pub updated_at: String, +} + +#[typeshare] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Diff, Builder)] +#[diff(attr(#[derive(Debug, Serialize)]))] +pub struct DeploymentConfig {} diff --git a/lib/types/src/entities/deployment.rs b/lib/types/src/entities/deployment.rs index 7e2b033fd..e14d84154 100644 --- a/lib/types/src/entities/deployment.rs +++ b/lib/types/src/entities/deployment.rs @@ -1,8 +1,57 @@ +use bson::serde_helpers::hex_string_as_object_id; +use derive_builder::Builder; use diff::Diff; +use partial_derive2::Partial; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; use typeshare::typeshare; +use super::PermissionsMap; + +#[typeshare] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Diff, Builder)] +#[diff(attr(#[derive(Debug, Serialize)]))] +pub struct Deployment { + #[serde( + default, + rename = "_id", + skip_serializing_if = "String::is_empty", + with = "hex_string_as_object_id" + )] + #[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))] + #[builder(setter(skip))] + pub id: String, + + #[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))] + pub name: String, + + #[serde(default)] + #[builder(default)] + #[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))] + pub description: String, + + #[serde(default)] + #[diff(attr(#[serde(skip_serializing)]))] + #[builder(setter(skip))] + pub permissions: PermissionsMap, + + #[serde(default, skip_serializing_if = "String::is_empty")] + #[diff(attr(#[serde(skip)]))] + #[builder(setter(skip))] + pub created_at: String, + + #[serde(default)] + #[diff(attr(#[serde(skip)]))] + #[builder(setter(skip))] + pub updated_at: String, +} + +#[typeshare] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Diff, Builder, Partial)] +#[partial_derive(Serialize, Deserialize, Debug, Clone, Default)] +#[diff(attr(#[derive(Debug, Serialize)]))] +pub struct DeploymentConfig {} + #[typeshare] #[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Diff)] #[diff(attr(#[derive(Debug, PartialEq, Serialize)]))] diff --git a/lib/types/src/entities/mod.rs b/lib/types/src/entities/mod.rs index 40f687397..fed95ad00 100644 --- a/lib/types/src/entities/mod.rs +++ b/lib/types/src/entities/mod.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; use typeshare::typeshare; +pub mod build; pub mod deployment; pub mod server; pub mod update; diff --git a/lib/types/src/entities/server/mod.rs b/lib/types/src/entities/server/mod.rs index 4fb51f62e..578082999 100644 --- a/lib/types/src/entities/server/mod.rs +++ b/lib/types/src/entities/server/mod.rs @@ -6,8 +6,8 @@ use typeshare::typeshare; use super::PermissionsMap; -pub mod docker_network; pub mod docker_image; +pub mod docker_network; pub mod stats; #[typeshare] diff --git a/lib/types/src/entities/server/stats.rs b/lib/types/src/entities/server/stats.rs index a1bf0bc03..f2c3dc062 100644 --- a/lib/types/src/entities/server/stats.rs +++ b/lib/types/src/entities/server/stats.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use typeshare::typeshare; use crate::{entities::Timelength, I64}; @@ -119,4 +119,4 @@ pub struct SystemComponent { pub max: f32, #[serde(skip_serializing_if = "Option::is_none")] pub critical: Option, -} \ No newline at end of file +} diff --git a/periphery/src/helpers/docker/build.rs b/periphery/src/helpers/docker/build.rs index 99ca6cbec..817d57716 100644 --- a/periphery/src/helpers/docker/build.rs +++ b/periphery/src/helpers/docker/build.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf}; use anyhow::{anyhow, Context}; use monitor_helpers::to_monitor_name; -use monitor_types::entities::{update::Log, Version, EnvironmentVar}; +use monitor_types::entities::{update::Log, EnvironmentVar, Version}; use crate::helpers::run_monitor_command; diff --git a/periphery/src/helpers/docker/container.rs b/periphery/src/helpers/docker/container.rs index 71160add9..f6c27c27a 100644 --- a/periphery/src/helpers/docker/container.rs +++ b/periphery/src/helpers/docker/container.rs @@ -1,7 +1,7 @@ -use anyhow::{Context, anyhow}; +use anyhow::{anyhow, Context}; use monitor_helpers::to_monitor_name; use monitor_types::entities::{ - deployment::{Conversion, RestartMode, TerminationSignal, DockerContainerStats}, + deployment::{Conversion, DockerContainerStats, RestartMode, TerminationSignal}, update::Log, EnvironmentVar, }; diff --git a/periphery/src/helpers/git.rs b/periphery/src/helpers/git.rs index 90784947f..11f7b31e9 100644 --- a/periphery/src/helpers/git.rs +++ b/periphery/src/helpers/git.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use anyhow::anyhow; use async_timing_util::unix_timestamp_ms; use monitor_helpers::to_monitor_name; -use monitor_types::entities::{update::Log, SystemCommand, CloneArgs}; +use monitor_types::entities::{update::Log, CloneArgs, SystemCommand}; use run_command::async_run_command; use super::run_monitor_command; diff --git a/periphery/src/requests/mod.rs b/periphery/src/requests/mod.rs index f5cfe5d99..a43a8f6f2 100644 --- a/periphery/src/requests/mod.rs +++ b/periphery/src/requests/mod.rs @@ -6,7 +6,7 @@ use resolver_api::{ }; use serde::{Deserialize, Serialize}; -use crate::{state::State, helpers::run_monitor_command}; +use crate::{helpers::run_monitor_command, state::State}; mod stats; pub use stats::*; diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 6856fc935..954d96372 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -10,4 +10,6 @@ monitor_types.workspace = true monitor_client.workspace = true periphery_client.workspace = true tokio.workspace = true -anyhow.workspace = true \ No newline at end of file +anyhow.workspace = true +serde.workspace = true +serde_json.workspace = true \ No newline at end of file diff --git a/tests/src/main.rs b/tests/src/main.rs index ce1daffd9..6492e8eef 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -4,38 +4,38 @@ use periphery_client::{requests, PeripheryClient}; async fn main() -> anyhow::Result<()> { let periphery = PeripheryClient::new("http://localhost:9001", "monitor_passkey"); - // let version = periphery.request(requests::GetVersion {}).await?; - // println!("{version:?}"); + let version = periphery.request(requests::GetVersion {}).await?; + println!("{version:?}"); - // let system_info = periphery.request(requests::GetSystemInformation {}).await?; - // println!("{system_info:#?}"); + let system_info = periphery.request(requests::GetSystemInformation {}).await?; + println!("{system_info:#?}"); - // let processes = periphery.request(requests::GetSystemProcesses {}).await?; - // // println!("{system_stats:#?}"); + let processes = periphery.request(requests::GetSystemProcesses {}).await?; + // println!("{system_stats:#?}"); - // let periphery_process = processes.into_iter().find(|p| p.name.contains("periphery")); - // println!("{periphery_process:#?}"); + let periphery_process = processes.into_iter().find(|p| p.name.contains("periphery")); + println!("{periphery_process:#?}"); - // let accounts = periphery.request(requests::GetAccounts {}).await?; - // println!("{accounts:#?}"); + let accounts = periphery.request(requests::GetAccounts {}).await?; + println!("{accounts:#?}"); - // let secrets = periphery.request(requests::GetSecrets {}).await?; - // println!("{secrets:#?}"); + let secrets = periphery.request(requests::GetSecrets {}).await?; + println!("{secrets:#?}"); - // let container_stats = periphery - // .request(requests::GetContainerStatsList {}) - // .await?; - // println!("{container_stats:#?}"); + let container_stats = periphery + .request(requests::GetContainerStatsList {}) + .await?; + println!("{container_stats:#?}"); - // let res = periphery.request(requests::GetNetworkList {}).await?; - // println!("{res:#?}"); + let res = periphery.request(requests::GetNetworkList {}).await?; + println!("{res:#?}"); - // let res = periphery - // .request(requests::GetContainerStats { - // name: "monitor-mongo".into(), - // }) - // .await?; - // println!("{res:#?}"); + let res = periphery + .request(requests::GetContainerStats { + name: "monitor-mongo".into(), + }) + .await?; + println!("{res:#?}"); let res = periphery .request(requests::GetContainerLog {