diff --git a/src/api/activations.rs b/src/api/activations.rs index 3374153..a9fb64f 100644 --- a/src/api/activations.rs +++ b/src/api/activations.rs @@ -4,8 +4,8 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::{ApiClient, Client, Result}; use crate::api::{DomainCollection, DomainExtension, DomainObject, domain_client, domain_read}; +use crate::{ApiClient, Client, Result}; domain_client!(ActivationStatus, activation_api); @@ -18,7 +18,7 @@ pub struct ActivationStatus { time_started: DateTime, changes: Vec, #[serde(default)] - status_per_site: Vec + status_per_site: Vec, } impl DomainExtension for ActivationStatus { @@ -44,7 +44,7 @@ pub struct SiteStatus { status_text: String, status_details: String, start_time: DateTime, - end_time: DateTime + end_time: DateTime, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -57,7 +57,7 @@ pub enum ChangePhase { Sync, Activate, Finishing, - Done + Done, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -66,7 +66,7 @@ pub enum ChangePhase { pub enum ChangeState { Success, Error, - Warning + Warning, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -74,7 +74,7 @@ pub enum ChangeState { pub struct ActivateChangeRequest { redirect: bool, sites: Vec, - force_foreign_changes: bool + force_foreign_changes: bool, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -82,7 +82,7 @@ pub struct ActivateChangeRequest { pub struct ActivationOptions { redirect: bool, sites: Vec, - force_foreign_changes: bool + force_foreign_changes: bool, } impl ActivationOptions { @@ -120,40 +120,38 @@ impl ActivationOptions { domain_read!(ActivationStatus); impl ApiClient { - pub async fn activate_pending_changes( - &self, - options: &ActivationOptions - ) -> Result { + pub async fn activate_pending_changes(&self, options: &ActivationOptions) -> Result { let etag = { let url = format!("{}/pending_changes", self.collection_root()); self.inner.get_etag(&url).await }?; let url = format!( "{}/domain-types/{}/actions/activate-changes/invoke", - self.inner.url, ActivationStatus::DOMAIN_TYPE + self.inner.url, + ActivationStatus::DOMAIN_TYPE ); - let request = self.inner.http + let request = self + .inner + .http .post(url) .json(&options) .header(reqwest::header::IF_MATCH, etag) .build() .unwrap(); - let response: DomainObject = - self.inner.query_api(request).await?; + let response: DomainObject = self.inner.query_api(request).await?; Ok(response.id) } pub async fn await_completion(&self, activation_id: impl Display) -> Result<()> { let url = format!( "{}/objects/{}/{}/actions/wait-for-completion/invoke", - self.inner.url, ActivationStatus::DOMAIN_TYPE, activation_id + self.inner.url, + ActivationStatus::DOMAIN_TYPE, + activation_id ); - let request = self.inner.http - .get(url) - .build() - .unwrap(); + let request = self.inner.http.get(url).build().unwrap(); self.inner.invoke_api(request).await } @@ -162,16 +160,14 @@ impl ApiClient { fn collection_root(&self) -> String { format!( "{}/domain-types/{}/collections", - self.inner.url, ActivationStatus::DOMAIN_TYPE + self.inner.url, + ActivationStatus::DOMAIN_TYPE ) } pub async fn read_running_activations(&self) -> Result> { let url = format!("{}/running", self.collection_root()); - let request = self.inner.http - .get(url) - .build() - .unwrap(); + let request = self.inner.http.get(url).build().unwrap(); let collection: DomainCollection<_> = self.inner.query_api(request).await?; Ok(collection.into()) @@ -179,14 +175,11 @@ impl ApiClient { pub async fn read_pending_changes(&self) -> Result> { let url = format!("{}/pending_changes", self.collection_root()); - let request = self.inner.http - .get(url) - .build() - .unwrap(); + let request = self.inner.http.get(url).build().unwrap(); #[derive(Deserialize)] struct ChangeCollection { - value: Vec + value: Vec, } let collection: ChangeCollection = self.inner.query_api(request).await?; diff --git a/src/api/folders.rs b/src/api/folders.rs index 3b5bf06..27cba09 100644 --- a/src/api/folders.rs +++ b/src/api/folders.rs @@ -8,9 +8,10 @@ use serde_json::Value; #[cfg(feature = "schemars")] use schemars::JsonSchema; -use crate::api::rules::contactgroups::HostContactGroups; -use crate::api::rules::snmp::SnmpCommunity; -use crate::api::{DomainExtension, domain_bulk_read, domain_bulk_update, domain_client, domain_create, domain_delete, domain_read, domain_update}; +use crate::api::{ + DomainExtension, domain_bulk_read, domain_bulk_update, domain_client, domain_create, + domain_delete, domain_read, domain_update, +}; use crate::{ApiClient, Client, Result}; pub const ROOT_FOLDER: &str = "/"; @@ -24,6 +25,7 @@ pub struct FolderConfig { pub attributes: FolderAttributes, } +#[allow(dead_code)] #[derive(Debug, Default, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct FolderAttributes { @@ -46,7 +48,6 @@ pub struct FolderAttributes { #[serde(default, flatten, skip_serializing_if = "HashMap::is_empty")] pub tags: HashMap, - // these fields are used to prevent tags from taking them up #[serde(default)] management_snmp_community: Option, @@ -112,8 +113,7 @@ impl FolderAttributes { } pub fn add_tag(&mut self, taggroup: impl Display, tagvalue: String) { - self.tags - .insert(format!("tag_{taggroup}"), tagvalue); + self.tags.insert(format!("tag_{taggroup}"), tagvalue); } pub fn with_tag(mut self, taggroup: impl Display, tagvalue: String) -> Self { self.add_tag(taggroup, tagvalue); @@ -130,6 +130,89 @@ pub struct MetaData { pub created_by: Option, } +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] +pub enum SnmpV3AuthProtocol { + #[serde(rename = "MD5-96")] + Md5, + #[serde(rename = "SHA-1-96")] + Sha96, + #[serde(rename = "SHA-2-224")] + Sha224, + #[serde(rename = "SHA-2-256")] + Sha256, + #[serde(rename = "SHA-2-384")] + Sha384, + #[serde(rename = "SHA-2-512")] + Sha512, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] +pub struct SnmpV3Auth { + pub auth_protocol: SnmpV3AuthProtocol, + pub security_name: String, + pub auth_password: String, +} + +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] +pub enum SnmpV3PrivProtocol { + #[serde(rename = "CBC-DES")] + Des, + #[serde(rename = "3DES-EDE")] + Des3, + #[serde(rename = "AES-128")] + Aes128, + #[serde(rename = "AES-192")] + Aes192, + #[serde(rename = "AES-256")] + Aes256, + #[serde(rename = "AES-192-Blumenthal")] + Aes192Blumenthal, + #[serde(rename = "AES-256-Blumenthal")] + Aes256Blumenthal, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] +pub struct SnmpV3Priv { + pub privacy_protocol: SnmpV3PrivProtocol, + pub privacy_password: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] +#[serde(tag = "type")] +pub enum SnmpCommunity { + V1V2Community { + community: String, + }, + NoAuthNoPriv { + security_name: String, + }, + AuthNoPriv { + #[serde(flatten)] + auth: SnmpV3Auth, + }, + AuthPriv { + #[serde(flatten)] + authentication: SnmpV3Auth, + #[serde(flatten)] + privacy: SnmpV3Priv, + }, +} + +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(JsonSchema))] +pub struct HostContactGroups { + pub groups: Vec, + pub r#use: bool, + pub use_for_services: bool, + pub recurse_use: bool, + pub recurse_perms: bool, +} + impl DomainExtension for FolderConfig { const DOMAIN_TYPE: super::DomainType = super::DomainType::FolderConfig; } diff --git a/src/api/groups.rs b/src/api/groups.rs index ea7474a..3325a6c 100644 --- a/src/api/groups.rs +++ b/src/api/groups.rs @@ -1,19 +1,17 @@ use core::ops::Deref; -use serde::{Deserialize, Serialize}; #[cfg(feature = "schemars")] use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; -use crate::api::{ - DomainCollection, DomainObject, DomainType, domain_client -}; +use crate::api::{DomainCollection, DomainObject, DomainType, domain_client}; use crate::{ApiClient, Client, Result}; #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Group { pub name: String, - pub alias: String + pub alias: String, } impl Group { @@ -28,7 +26,6 @@ impl From> for Group { } } - macro_rules! domain_group { ($id:ident, $typ:expr, $func:ident) => { #[derive(Debug, Clone, Serialize, Deserialize)] @@ -61,14 +58,13 @@ macro_rules! domain_group { self.inner.create($typ, group, &()).await } pub async fn read(&self, id: &str) -> Result<$id> { - let obj: DomainObject = - self.inner.read($typ, id, &()).await?; + let obj: DomainObject = self.inner.read($typ, id, &()).await?; Ok($id::from(obj)) } pub async fn update(&self, id: &str, alias: &str) -> Result<()> { #[derive(Serialize)] struct Body<'a> { - alias: &'a str + alias: &'a str, } self.inner.update($typ, id, &Body { alias }).await @@ -83,45 +79,48 @@ macro_rules! domain_group { pub async fn bulk_read(&self) -> Result> { let collection: DomainCollection = self.inner.bulk_read($typ, &()).await?; - let groups = collection.value - .into_iter() - .map($id::from) - .collect(); + let groups = collection.value.into_iter().map($id::from).collect(); Ok(groups) } pub async fn bulk_update(&self, entries: &[Group]) -> Result<()> { #[derive(Serialize)] struct UpdateAttributes<'a> { - alias: &'a str + alias: &'a str, } #[derive(Serialize)] struct UpdateRequest<'a> { name: &'a str, - attributes: UpdateAttributes<'a> + attributes: UpdateAttributes<'a>, } - impl <'a> UpdateRequest<'a> { + impl<'a> UpdateRequest<'a> { fn from(value: &'a Group) -> Self { Self { name: value.name.as_str(), attributes: UpdateAttributes { - alias: value.alias.as_str() - } + alias: value.alias.as_str(), + }, } } } - let entries = entries.iter() - .map(UpdateRequest::from) - .collect::>(); + let entries = entries.iter().map(UpdateRequest::from).collect::>(); self.inner.bulk_update($typ, &entries).await } pub async fn bulk_delete(&self, entries: &[String]) -> Result<()> { self.inner.bulk_delete($typ, entries).await } } - } + }; } domain_group!(HostGroup, DomainType::HostGroupConfig, host_group_api); -domain_group!(ServiceGroup, DomainType::ServiceGroupConfig, service_group_api); -domain_group!(ContactGroup, DomainType::ContactGroupConfig, contact_group_api); +domain_group!( + ServiceGroup, + DomainType::ServiceGroupConfig, + service_group_api +); +domain_group!( + ContactGroup, + DomainType::ContactGroupConfig, + contact_group_api +); diff --git a/src/api/hosts.rs b/src/api/hosts.rs index be7ceed..57da5e7 100644 --- a/src/api/hosts.rs +++ b/src/api/hosts.rs @@ -1,17 +1,17 @@ use std::fmt::Display; use std::net::{Ipv4Addr, Ipv6Addr}; -use serde::{Deserialize, Serialize}; #[cfg(feature = "schemars")] use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use crate::api::folders::FolderAttributes; use crate::api::{ - DomainExtension, domain_bulk_create, domain_bulk_delete, domain_bulk_read, domain_bulk_update, domain_client, domain_create, domain_delete, domain_read, domain_update + DomainExtension, domain_bulk_create, domain_bulk_delete, domain_bulk_read, domain_bulk_update, + domain_client, domain_create, domain_delete, domain_read, domain_update, }; use crate::{ApiClient, Client, Result}; - domain_client!(HostConfig, host_api); #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -25,7 +25,6 @@ pub struct HostConfig { pub cluster_nodes: Option>, } - #[derive(Debug, Default, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct HostAttributes { @@ -41,7 +40,7 @@ pub struct HostAttributes { additional_ipv6addresses: Vec, #[serde(flatten, default)] - folder_attributes: FolderAttributes + folder_attributes: FolderAttributes, } impl DomainExtension for HostConfig { diff --git a/src/api/mod.rs b/src/api/mod.rs index ab9f623..4e8bddc 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,8 +1,7 @@ pub mod activations; pub mod folders; -pub mod hosts; pub mod groups; -pub(crate) mod rules; +pub mod hosts; pub mod tags; use std::fmt::{self, Display}; @@ -35,7 +34,7 @@ impl fmt::Display for DomainType { DomainType::HostGroupConfig => write!(f, "host_group_config"), DomainType::ServiceGroupConfig => write!(f, "service_group_config"), DomainType::HostTagGroup => write!(f, "host_tag_group"), - DomainType::ActivationRun => write!(f, "activation_run") + DomainType::ActivationRun => write!(f, "activation_run"), } } } @@ -91,12 +90,9 @@ pub(crate) struct DomainCollection { // pub extensions: Option, } -impl From> for Vec { +impl From> for Vec { fn from(value: DomainCollection) -> Self { - value.value - .into_iter() - .map(|obj| obj.extensions) - .collect() + value.value.into_iter().map(|obj| obj.extensions).collect() } } @@ -105,15 +101,11 @@ pub trait DomainExtension: DeserializeOwned + Serialize { } impl InnerClient { - pub(crate) async fn create_domain_object( - &self, - object: &O, - query: &Q, - ) -> Result<()> + pub(crate) async fn create_domain_object(&self, object: &O, query: &Q) -> Result<()> where E: DomainExtension, O: Serialize, - Q: Serialize + Q: Serialize, { self.create(E::DOMAIN_TYPE, object, query).await } @@ -124,7 +116,7 @@ impl InnerClient { ) -> Result> where E: DomainExtension, - Q: Serialize + Q: Serialize, { self.read(E::DOMAIN_TYPE, id, query).await } @@ -135,18 +127,14 @@ impl InnerClient { ) -> Result<()> where E: DomainExtension, - O: Serialize + O: Serialize, { self.update(E::DOMAIN_TYPE, id, object).await } - pub(crate) async fn delete_domain_object( - &self, - id: impl Display, - query: &Q, - ) -> Result<()> + pub(crate) async fn delete_domain_object(&self, id: impl Display, query: &Q) -> Result<()> where E: DomainExtension, - Q: Serialize + Q: Serialize, { self.delete(E::DOMAIN_TYPE, id, query).await } @@ -159,7 +147,7 @@ impl InnerClient { where E: DomainExtension, O: Serialize, - Q: Serialize + Q: Serialize, { self.bulk_create(E::DOMAIN_TYPE, entries, query).await } @@ -169,33 +157,25 @@ impl InnerClient { ) -> Result> where E: DomainExtension, - Q: Serialize + Q: Serialize, { self.bulk_read(E::DOMAIN_TYPE, query).await } - pub(crate) async fn bulk_update_domain_objects( - &self, - entries: &[O], - ) -> Result<()> + pub(crate) async fn bulk_update_domain_objects(&self, entries: &[O]) -> Result<()> where E: DomainExtension, - O: Serialize + O: Serialize, { self.bulk_update(E::DOMAIN_TYPE, entries).await } - pub(crate) async fn bulk_delete_domain_objects( - &self, - entries: &[String], - ) -> Result<()> + pub(crate) async fn bulk_delete_domain_objects(&self, entries: &[String]) -> Result<()> where - E: DomainExtension + E: DomainExtension, { self.bulk_delete(E::DOMAIN_TYPE, entries).await } } - - macro_rules! domain_client { ($id:ident, $func:ident) => { impl Client { @@ -211,7 +191,7 @@ macro_rules! domain_client { Self::new(value) } } - } + }; } pub(super) use domain_client; @@ -219,14 +199,18 @@ macro_rules! domain_create { ($id:ident, $object:ident) => { impl ApiClient<$id> { pub async fn create(&self, object: &$object) -> Result<()> { - self.inner.create_domain_object::<$id, _, _>(object, &()).await + self.inner + .create_domain_object::<$id, _, _>(object, &()) + .await } } }; ($id:ident, $object:ident, $qry:ident) => { impl ApiClient<$id> { pub async fn create(&self, object: &$object, query: &$qry) -> Result<()> { - self.inner.create_domain_object::<$id, _, _>(object, query).await + self.inner + .create_domain_object::<$id, _, _>(object, query) + .await } } }; @@ -237,7 +221,9 @@ macro_rules! domain_read { ($id:ident) => { impl ApiClient<$id> { pub async fn read(&self, id: impl Display) -> Result<$id> { - self.inner.read_domain_object::<$id, _>(id, &()).await + self.inner + .read_domain_object::<$id, _>(id, &()) + .await .map(|obj| obj.extensions) } } @@ -245,7 +231,9 @@ macro_rules! domain_read { ($id:ident, $qry:ident) => { impl ApiClient<$id> { pub async fn read(&self, id: impl Display, query: &$qry) -> Result<$id> { - self.inner.read_domain_object::<$id, _>(id, &query).await + self.inner + .read_domain_object::<$id, _>(id, &query) + .await .map(|obj| obj.extensions) } } @@ -286,14 +274,18 @@ macro_rules! domain_bulk_create { ($id:ident, $object:ident) => { impl ApiClient<$id> { pub async fn bulk_create(&self, entries: &[$object]) -> Result<()> { - self.inner.bulk_create_domain_objects::<$id, _, _>(entries, &()).await + self.inner + .bulk_create_domain_objects::<$id, _, _>(entries, &()) + .await } } }; ($id:ident, $object:ident, $qry:ident) => { impl ApiClient<$id> { pub async fn bulk_create(&self, entries: &[$object], query: &$qry) -> Result<()> { - self.inner.bulk_create_domain_objects::<$id, _, _>(entries, query).await + self.inner + .bulk_create_domain_objects::<$id, _, _>(entries, query) + .await } } }; @@ -312,7 +304,10 @@ macro_rules! domain_bulk_read { ($id:ident, $qry:ident) => { impl ApiClient<$id> { pub async fn bulk_read(&self, query: &$qry) -> Result> { - let collection = self.inner.bulk_read_domain_objects::<$id, _>(&query).await?; + let collection = self + .inner + .bulk_read_domain_objects::<$id, _>(&query) + .await?; Ok(collection.into()) } } @@ -324,7 +319,9 @@ macro_rules! domain_bulk_update { ($id:ident, $object:ident) => { impl ApiClient<$id> { pub async fn bulk_update(&self, entries: &[$object]) -> Result<()> { - self.inner.bulk_update_domain_objects::<$id, _>(entries).await + self.inner + .bulk_update_domain_objects::<$id, _>(entries) + .await } } }; diff --git a/src/api/rules/contactgroups.rs b/src/api/rules/contactgroups.rs deleted file mode 100644 index 3a27b9a..0000000 --- a/src/api/rules/contactgroups.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[cfg(feature = "schemars")] -use schemars::JsonSchema; - -#[derive(Debug, Clone, Default, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(JsonSchema))] -pub struct HostContactGroups { - pub groups: Vec, - pub r#use: bool, - pub use_for_services: bool, - pub recurse_use: bool, - pub recurse_perms: bool, -} diff --git a/src/api/rules/mod.rs b/src/api/rules/mod.rs deleted file mode 100644 index 58797ea..0000000 --- a/src/api/rules/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod contactgroups; -pub mod snmp; diff --git a/src/api/rules/snmp.rs b/src/api/rules/snmp.rs deleted file mode 100644 index 4e95ec7..0000000 --- a/src/api/rules/snmp.rs +++ /dev/null @@ -1,77 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[cfg(feature = "schemars")] -use schemars::JsonSchema; - -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(JsonSchema))] -pub enum SnmpV3AuthProtocol { - #[serde(rename = "MD5-96")] - Md5, - #[serde(rename = "SHA-1-96")] - Sha96, - #[serde(rename = "SHA-2-224")] - Sha224, - #[serde(rename = "SHA-2-256")] - Sha256, - #[serde(rename = "SHA-2-384")] - Sha384, - #[serde(rename = "SHA-2-512")] - Sha512, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(JsonSchema))] -pub struct SnmpV3Auth { - pub auth_protocol: SnmpV3AuthProtocol, - pub security_name: String, - pub auth_password: String, -} - -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(JsonSchema))] -pub enum SnmpV3PrivProtocol { - #[serde(rename = "CBC-DES")] - Des, - #[serde(rename = "3DES-EDE")] - Des3, - #[serde(rename = "AES-128")] - Aes128, - #[serde(rename = "AES-192")] - Aes192, - #[serde(rename = "AES-256")] - Aes256, - #[serde(rename = "AES-192-Blumenthal")] - Aes192Blumenthal, - #[serde(rename = "AES-256-Blumenthal")] - Aes256Blumenthal, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(JsonSchema))] -pub struct SnmpV3Priv { - pub privacy_protocol: SnmpV3PrivProtocol, - pub privacy_password: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(tag = "type")] -pub enum SnmpCommunity { - V1V2Community { - community: String, - }, - NoAuthNoPriv { - security_name: String, - }, - AuthNoPriv { - #[serde(flatten)] - auth: SnmpV3Auth, - }, - AuthPriv { - #[serde(flatten)] - authentication: SnmpV3Auth, - #[serde(flatten)] - privacy: SnmpV3Priv, - }, -} diff --git a/src/api/tags.rs b/src/api/tags.rs index abcb97d..1cf149c 100644 --- a/src/api/tags.rs +++ b/src/api/tags.rs @@ -1,10 +1,13 @@ use crate::api::Display; -use serde::{Deserialize, Serialize}; #[cfg(feature = "schemars")] use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; -use crate::api::{DomainExtension, DomainType, domain_bulk_read, domain_client, domain_create, domain_delete, domain_read, domain_update}; +use crate::api::{ + DomainExtension, DomainType, domain_bulk_read, domain_client, domain_create, domain_delete, + domain_read, domain_update, +}; use crate::{ApiClient, Client, Result}; domain_client!(TagGroup, tag_api); @@ -15,7 +18,7 @@ pub struct ExtendedTagGroup { pub id: String, pub title: String, #[serde(flatten, default)] - pub inner: TagGroup + pub inner: TagGroup, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -25,7 +28,7 @@ pub struct TagGroup { pub topic: String, #[serde(default, skip_serializing_if = "String::is_empty")] pub help: String, - pub tags: Vec + pub tags: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -33,12 +36,16 @@ pub struct TagGroup { pub struct Tag { pub id: Option, pub title: String, - pub aux_tags: Vec + pub aux_tags: Vec, } impl ExtendedTagGroup { pub fn new(id: String, title: String) -> Self { - Self { id, title, inner: Default::default() } + Self { + id, + title, + inner: Default::default(), + } } pub fn set_topic(&mut self, topic: String) { @@ -69,14 +76,14 @@ impl Tag { Self { id: Some(id), title, - aux_tags: Vec::new() + aux_tags: Vec::new(), } } pub fn new_default(title: String) -> Self { Self { id: None, title, - aux_tags: Vec::new() + aux_tags: Vec::new(), } } @@ -95,12 +102,16 @@ pub struct TagUpdateRequest { title: String, #[serde(flatten, default)] inner: TagGroup, - repair: bool + repair: bool, } impl TagUpdateRequest { pub fn new(title: String, repair: bool) -> Self { - Self { title, repair, inner: Default::default() } + Self { + title, + repair, + inner: Default::default(), + } } pub fn set_topic(&mut self, topic: String) { @@ -130,7 +141,7 @@ impl TagUpdateRequest { #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct TagDeleteQuery { repair: bool, - mode: Option + mode: Option, } impl TagDeleteQuery { @@ -143,7 +154,8 @@ impl TagDeleteQuery { #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub enum TagDeleteMode { Abort, - #[default] Delete, + #[default] + Delete, Remove, } diff --git a/src/client.rs b/src/client.rs index b2fcc43..1d442d9 100644 --- a/src/client.rs +++ b/src/client.rs @@ -10,9 +10,7 @@ use serde::Serialize; use serde::de::DeserializeOwned; use tokio::sync::Semaphore; -use crate::api::{ - DomainCollection, DomainType, -}; +use crate::api::{DomainCollection, DomainType}; use crate::{Error, Result}; #[derive(Clone)] @@ -288,11 +286,11 @@ impl InnerClient { &self, domain_type: DomainType, object: &O, - query: &Q + query: &Q, ) -> Result<()> where O: Serialize, - Q: Serialize + Q: Serialize, { let url = self.collection_url(domain_type); let request = self @@ -314,15 +312,10 @@ impl InnerClient { ) -> Result where O: DeserializeOwned, - Q: Serialize + Q: Serialize, { let url = self.object_url(domain_type, id); - let request = self - .http - .get(url) - .query(query) - .build() - .unwrap(); + let request = self.http.get(url).query(query).build().unwrap(); self.query_api(request).await } @@ -358,12 +351,7 @@ impl InnerClient { Q: Serialize, { let url = self.object_url(domain_type, id); - let request = self - .http - .delete(url) - .query(&query) - .build() - .unwrap(); + let request = self.http.delete(url).query(&query).build().unwrap(); self.invoke_api(request).await } @@ -399,27 +387,18 @@ impl InnerClient { pub(crate) async fn bulk_read( &self, domain_type: DomainType, - query: &Q + query: &Q, ) -> Result> where O: DeserializeOwned, - Q: Serialize + Q: Serialize, { let url = self.collection_url(domain_type); - let request = self.http - .get(url) - .query(query) - .build() - .unwrap(); + let request = self.http.get(url).query(query).build().unwrap(); self.query_api(request).await - } - pub(crate) async fn bulk_update( - &self, - domain_type: DomainType, - entries: &[O], - ) -> Result<()> + pub(crate) async fn bulk_update(&self, domain_type: DomainType, entries: &[O]) -> Result<()> where O: Serialize, { @@ -431,19 +410,14 @@ impl InnerClient { let url = self.bulk_action_url(domain_type, BulkAction::Update); let body = Request:: { entries }; - let request = self - .http - .put(url) - .json(&body) - .build() - .unwrap(); + let request = self.http.put(url).json(&body).build().unwrap(); self.invoke_api(request).await } pub(crate) async fn bulk_delete( &self, domain_type: DomainType, - entries: &[String] + entries: &[String], ) -> Result<()> { #[derive(Serialize)] struct Request<'a> { @@ -453,12 +427,7 @@ impl InnerClient { let url = self.bulk_action_url(domain_type, BulkAction::Delete); let body = Request { entries }; - let request = self - .http - .post(url) - .json(&body) - .build() - .unwrap(); + let request = self.http.post(url).json(&body).build().unwrap(); self.invoke_api(request).await } @@ -487,7 +456,7 @@ pub struct ApiClient { _marker: PhantomData, } -impl ApiClient { +impl ApiClient { pub(crate) fn new(inner: &Client) -> Self { Self { inner: inner.0.clone(), diff --git a/src/main.rs b/src/main.rs index 9af8c57..7fdf741 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,8 +93,8 @@ async fn test_folders(client: Client) -> Result<()> { } async fn test_hosts(client: Client) -> Result<()> { - use checkmk_api::api::hosts::*; use checkmk_api::api::folders::FolderAttributes; + use checkmk_api::api::hosts::*; const TESTHOST: &str = "test-host"; info!("testing hosts"); @@ -102,17 +102,17 @@ async fn test_hosts(client: Client) -> Result<()> { let creq = HostCreationRequest::new( TESTHOST.to_string(), "~".to_string(), - FolderAttributes::default().with_site("dev".to_string()) + FolderAttributes::default().with_site("dev".to_string()), ); let cquery = HostCreationQuery::new(false); let rquery = HostReadQuery::new(true); let ureq1 = HostUpdateRequest::replace( FolderAttributes::default() .with_site("dev".to_string()) - .with_label("environment".to_string(), "test".to_string()) + .with_label("environment".to_string(), "test".to_string()), ); let ureq2 = HostUpdateRequest::update( - FolderAttributes::default().with_label("purpose".to_string(), "testing".to_string()) + FolderAttributes::default().with_label("purpose".to_string(), "testing".to_string()), ); info!("creating test host"); @@ -211,9 +211,12 @@ async fn test_host_groups(client: Client) -> Result<()> { let api = client.host_group_api(); info!("creating test host group"); - api.create(&HostGroup::new(TESTGROUP.to_string(), "Test Host Group".to_string())) - .await - .inspect_err(|e| error!("failed to create host group: {e}"))?; + api.create(&HostGroup::new( + TESTGROUP.to_string(), + "Test Host Group".to_string(), + )) + .await + .inspect_err(|e| error!("failed to create host group: {e}"))?; let group = api .read(TESTGROUP) @@ -228,8 +231,14 @@ async fn test_host_groups(client: Client) -> Result<()> { info!("bulk creating additional host groups"); api.bulk_create(&[ - HostGroup::new("test-host-group-2".to_string(), "Test Host Group 2".to_string()), - HostGroup::new("test-host-group-3".to_string(), "Test Host Group 3".to_string()), + HostGroup::new( + "test-host-group-2".to_string(), + "Test Host Group 2".to_string(), + ), + HostGroup::new( + "test-host-group-3".to_string(), + "Test Host Group 3".to_string(), + ), ]) .await .inspect_err(|e| error!("failed to bulk create host groups: {e}"))?; @@ -242,8 +251,14 @@ async fn test_host_groups(client: Client) -> Result<()> { info!("bulk updating host groups"); api.bulk_update(&[ - Group::new("test-host-group-2".to_string(), "Updated Host Group 2".to_string()), - Group::new("test-host-group-3".to_string(), "Updated Host Group 3".to_string()), + Group::new( + "test-host-group-2".to_string(), + "Updated Host Group 2".to_string(), + ), + Group::new( + "test-host-group-3".to_string(), + "Updated Host Group 3".to_string(), + ), ]) .await .inspect_err(|e| error!("failed to bulk update host groups: {e}"))?; @@ -272,9 +287,12 @@ async fn test_service_groups(client: Client) -> Result<()> { let api = client.service_group_api(); info!("creating test service group"); - api.create(&ServiceGroup::new(TESTGROUP.to_string(), "Test Service Group".to_string())) - .await - .inspect_err(|e| error!("failed to create service group: {e}"))?; + api.create(&ServiceGroup::new( + TESTGROUP.to_string(), + "Test Service Group".to_string(), + )) + .await + .inspect_err(|e| error!("failed to create service group: {e}"))?; let group = api .read(TESTGROUP) @@ -289,8 +307,14 @@ async fn test_service_groups(client: Client) -> Result<()> { info!("bulk creating additional service groups"); api.bulk_create(&[ - ServiceGroup::new("test-service-group-2".to_string(), "Test Service Group 2".to_string()), - ServiceGroup::new("test-service-group-3".to_string(), "Test Service Group 3".to_string()), + ServiceGroup::new( + "test-service-group-2".to_string(), + "Test Service Group 2".to_string(), + ), + ServiceGroup::new( + "test-service-group-3".to_string(), + "Test Service Group 3".to_string(), + ), ]) .await .inspect_err(|e| error!("failed to bulk create service groups: {e}"))?; @@ -303,8 +327,14 @@ async fn test_service_groups(client: Client) -> Result<()> { info!("bulk updating service groups"); api.bulk_update(&[ - Group::new("test-service-group-2".to_string(), "Updated Service Group 2".to_string()), - Group::new("test-service-group-3".to_string(), "Updated Service Group 3".to_string()), + Group::new( + "test-service-group-2".to_string(), + "Updated Service Group 2".to_string(), + ), + Group::new( + "test-service-group-3".to_string(), + "Updated Service Group 3".to_string(), + ), ]) .await .inspect_err(|e| error!("failed to bulk update service groups: {e}"))?; @@ -372,9 +402,12 @@ async fn test_contact_groups(client: Client) -> Result<()> { let api = client.contact_group_api(); info!("creating test contact group"); - api.create(&ContactGroup::new(TESTGROUP.to_string(), "Test Contact Group".to_string())) - .await - .inspect_err(|e| error!("failed to create contact group: {e}"))?; + api.create(&ContactGroup::new( + TESTGROUP.to_string(), + "Test Contact Group".to_string(), + )) + .await + .inspect_err(|e| error!("failed to create contact group: {e}"))?; let group = api .read(TESTGROUP) @@ -389,8 +422,14 @@ async fn test_contact_groups(client: Client) -> Result<()> { info!("bulk creating additional contact groups"); api.bulk_create(&[ - ContactGroup::new("test-contact-group-2".to_string(), "Test Contact Group 2".to_string()), - ContactGroup::new("test-contact-group-3".to_string(), "Test Contact Group 3".to_string()), + ContactGroup::new( + "test-contact-group-2".to_string(), + "Test Contact Group 2".to_string(), + ), + ContactGroup::new( + "test-contact-group-3".to_string(), + "Test Contact Group 3".to_string(), + ), ]) .await .inspect_err(|e| error!("failed to bulk create contact groups: {e}"))?; @@ -403,8 +442,14 @@ async fn test_contact_groups(client: Client) -> Result<()> { info!("bulk updating contact groups"); api.bulk_update(&[ - Group::new("test-contact-group-2".to_string(), "Updated Contact Group 2".to_string()), - Group::new("test-contact-group-3".to_string(), "Updated Contact Group 3".to_string()), + Group::new( + "test-contact-group-2".to_string(), + "Updated Contact Group 2".to_string(), + ), + Group::new( + "test-contact-group-3".to_string(), + "Updated Contact Group 3".to_string(), + ), ]) .await .inspect_err(|e| error!("failed to bulk update contact groups: {e}"))?;