diff --git a/Cargo.lock b/Cargo.lock index 47ac818e7..1221694ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,9 +536,9 @@ dependencies = [ [[package]] name = "bcrypt" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9df288bec72232f78c1ec5fe4e8f1d108aa0265476e93097593c803c8c02062a" +checksum = "28d1c9c15093eb224f0baa400f38fcd713fc1391a6f1c389d886beef146d60a3" dependencies = [ "base64 0.21.2", "blowfish", @@ -995,6 +995,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_variants" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dab95799d3c74d5c2f627e783e6b630b89f79d82a7b080c76086493a4cf651ef" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "digest" version = "0.10.7" @@ -1899,6 +1910,7 @@ dependencies = [ "bollard", "bson", "derive_builder", + "derive_variants", "make_option", "monitor_macros", "mungos", diff --git a/Cargo.toml b/Cargo.toml index 08c37dedb..608366616 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ rand = "0.8" jwt = "0.16" hmac = "0.12" sha2 = "0.10" -bcrypt = "0.14" +bcrypt = "0.15" hex = "0.4" aws-config = "0.55" aws-sdk-ec2 = "0.28" @@ -59,6 +59,7 @@ merge_config_files = "0.1.3" termination_signal = "0.1.2" async_timing_util = "0.1.14" partial_derive2 = "0.1.4" +derive_variants = "0.1.1" make_option = "0.1.3" resolver_api = "0.1.6" parse_csl = "0.1.0" diff --git a/lib/types/Cargo.toml b/lib/types/Cargo.toml index 8fd56a14e..d0493066d 100644 --- a/lib/types/Cargo.toml +++ b/lib/types/Cargo.toml @@ -21,6 +21,7 @@ async_timing_util.workspace = true resolver_api.workspace = true derive_builder.workspace = true bollard.workspace = true +derive_variants.workspace = true partial_derive2.workspace = true make_option.workspace = true mungos.workspace = true diff --git a/lib/types/src/entities/build.rs b/lib/types/src/entities/build.rs index 5522e7f0c..36ef9415b 100644 --- a/lib/types/src/entities/build.rs +++ b/lib/types/src/entities/build.rs @@ -1,11 +1,13 @@ use bson::{doc, serde_helpers::hex_string_as_object_id}; use derive_builder::Builder; +use derive_variants::EnumVariants; use mungos::MungosIndexed; use partial_derive2::Partial; use serde::{Deserialize, Serialize}; +use strum_macros::{Display, EnumString}; use typeshare::typeshare; -use crate::{i64_is_zero, I64, MongoId}; +use crate::{i64_is_zero, MongoId, I64}; use super::{EnvironmentVar, PermissionsMap, SystemCommand, Version}; @@ -155,7 +157,8 @@ pub struct BuildActionState { } #[typeshare] -#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed)] +#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed, EnumVariants)] +#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumString)] #[serde(tag = "type", content = "params")] pub enum BuildBuilderConfig { Server { server_id: String }, diff --git a/lib/types/src/entities/builder.rs b/lib/types/src/entities/builder.rs index 11b817d1f..d1ab0e23a 100644 --- a/lib/types/src/entities/builder.rs +++ b/lib/types/src/entities/builder.rs @@ -1,11 +1,13 @@ use bson::serde_helpers::hex_string_as_object_id; use derive_builder::Builder; +use derive_variants::EnumVariants; use mungos::MungosIndexed; use partial_derive2::Partial; use serde::{Deserialize, Serialize}; +use strum_macros::{Display, EnumString}; use typeshare::typeshare; -use crate::{i64_is_zero, I64, MongoId}; +use crate::{i64_is_zero, MongoId, I64}; use super::PermissionsMap; @@ -44,14 +46,16 @@ pub struct Builder { } #[typeshare] -#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed)] +#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed, EnumVariants)] +#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumString)] #[serde(tag = "type", content = "params")] pub enum BuilderConfig { AwsBuilder(AwsBuilder), } #[typeshare] -#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed)] +#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed, EnumVariants)] +#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumString)] #[serde(tag = "type", content = "params")] pub enum PartialBuilderConfig { AwsBuilder(PartialAwsBuilder), diff --git a/lib/types/src/entities/deployment.rs b/lib/types/src/entities/deployment.rs index 059124d4d..181a53cd4 100644 --- a/lib/types/src/entities/deployment.rs +++ b/lib/types/src/entities/deployment.rs @@ -1,12 +1,13 @@ use bson::{doc, serde_helpers::hex_string_as_object_id}; use derive_builder::Builder; +use derive_variants::EnumVariants; use mungos::MungosIndexed; use partial_derive2::Partial; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; use typeshare::typeshare; -use crate::{i64_is_zero, I64, MongoId}; +use crate::{i64_is_zero, MongoId, I64}; use super::{EnvironmentVar, PermissionsMap, Version}; @@ -161,7 +162,8 @@ impl From for DeploymentConfig { } #[typeshare] -#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed)] +#[derive(Serialize, Deserialize, Debug, Clone, MungosIndexed, EnumVariants)] +#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumString)] #[serde(tag = "type", content = "params")] pub enum DeploymentImage { Image { image: String }, diff --git a/lib/types/src/entities/server/stats.rs b/lib/types/src/entities/server/stats.rs index c2ddf80a9..f65b85b60 100644 --- a/lib/types/src/entities/server/stats.rs +++ b/lib/types/src/entities/server/stats.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, path::PathBuf}; use serde::{Deserialize, Serialize}; +use strum_macros::{Display, EnumString}; use typeshare::typeshare; use crate::{entities::Timelength, I64}; @@ -122,7 +123,7 @@ pub struct SystemComponent { } #[typeshare] -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, Display, EnumString)] pub enum StatsState { #[default] Ok, diff --git a/lib/types/src/entities/update.rs b/lib/types/src/entities/update.rs index 270fcb7b2..f769a6542 100644 --- a/lib/types/src/entities/update.rs +++ b/lib/types/src/entities/update.rs @@ -1,5 +1,6 @@ use async_timing_util::unix_timestamp_ms; use bson::serde_helpers::hex_string_as_object_id; +use derive_variants::EnumVariants; use mungos::MungosIndexed; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; @@ -7,7 +8,7 @@ use typeshare::typeshare; use crate::{entities::Operation, monitor_timestamp, I64, MongoId}; -use super::Version; +use super::{Version, build::Build, deployment::Deployment, server::Server, repo::Repo, builder::Builder}; #[typeshare] #[derive(Serialize, Deserialize, Debug, Clone, Default, MungosIndexed)] @@ -86,7 +87,8 @@ impl Log { } #[typeshare] -#[derive(Serialize, Deserialize, Debug, Clone, Default, MungosIndexed)] +#[derive(Serialize, Deserialize, Debug, Clone, Default, MungosIndexed, EnumVariants)] +#[variant_derive(Serialize, Deserialize, Debug, Clone, Copy, Display, EnumString)] #[serde(tag = "type", content = "id")] pub enum ResourceTarget { #[default] @@ -96,70 +98,37 @@ pub enum ResourceTarget { Deployment(String), Server(String), Repo(String), - // Procedure(String), - // Group(String), - // Command(String), } -// impl From<&Build> for UpdateTarget { -// fn from(build: &Build) -> Self { -// Self::Build(build.id.clone()) -// } -// } +impl From<&Build> for ResourceTarget { + fn from(build: &Build) -> Self { + Self::Build(build.id.clone()) + } +} -// impl From<&Build> for Option { -// fn from(build: &Build) -> Self { -// Some(UpdateTarget::Build(build.id.clone())) -// } -// } +impl From<&Deployment> for ResourceTarget { + fn from(deployment: &Deployment) -> Self { + Self::Deployment(deployment.id.clone()) + } +} -// impl From<&Deployment> for UpdateTarget { -// fn from(deployment: &Deployment) -> Self { -// Self::Deployment(deployment.id.clone()) -// } -// } +impl From<&Server> for ResourceTarget { + fn from(server: &Server) -> Self { + Self::Server(server.id.clone()) + } +} -// impl From<&Deployment> for Option { -// fn from(deployment: &Deployment) -> Self { -// Some(UpdateTarget::Deployment(deployment.id.clone())) -// } -// } +impl From<&Repo> for ResourceTarget { + fn from(repo: &Repo) -> Self { + Self::Repo(repo.id.clone()) + } +} -// impl From<&Server> for UpdateTarget { -// fn from(server: &Server) -> Self { -// Self::Server(server.id.clone()) -// } -// } - -// impl From<&Server> for Option { -// fn from(server: &Server) -> Self { -// Some(UpdateTarget::Server(server.id.clone())) -// } -// } - -// impl From<&Procedure> for UpdateTarget { -// fn from(procedure: &Procedure) -> Self { -// Self::Procedure(procedure.id.clone()) -// } -// } - -// impl From<&Procedure> for Option { -// fn from(procedure: &Procedure) -> Self { -// Some(UpdateTarget::Procedure(procedure.id.clone())) -// } -// } - -// impl From<&Group> for UpdateTarget { -// fn from(group: &Group) -> Self { -// Self::Group(group.id.clone()) -// } -// } - -// impl From<&Group> for Option { -// fn from(group: &Group) -> Self { -// Some(UpdateTarget::Group(group.id.clone())) -// } -// } +impl From<&Builder> for ResourceTarget { + fn from(builder: &Builder) -> Self { + Self::Builder(builder.id.clone()) + } +} #[typeshare] #[derive(