icinga2_api/types/
join_types.rs1use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6
7pub mod dependency;
8pub mod host;
9pub mod notification;
10pub mod service;
11pub mod user;
12pub mod zone;
13
14pub trait IcingaJoinType {}
16
17#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
19pub enum IcingaJoins<'a, JT>
20where
21 JT: IcingaJoinType + Ord + std::fmt::Display,
22{
23 NoJoins,
25 SpecificJoins {
27 full: Vec<JT>,
29 partial: BTreeMap<JT, Vec<&'a str>>,
31 },
32 AllJoins,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
38#[serde(untagged)]
39pub enum IcingaJoinResult<T> {
40 Full(T),
42 Partial(BTreeMap<String, serde_json::Value>),
44}
45
46pub(crate) fn add_joins_to_url<JT: IcingaJoinType + Ord + std::fmt::Display>(
48 url: &mut url::Url,
49 joins: &IcingaJoins<JT>,
50) -> Result<(), crate::error::Error> {
51 match joins {
52 IcingaJoins::NoJoins => (),
53 IcingaJoins::AllJoins => {
54 url.query_pairs_mut().append_pair("all_joins", "1");
55 }
56 IcingaJoins::SpecificJoins { full, partial } => {
57 for j in full {
58 url.query_pairs_mut().append_pair("joins", &j.to_string());
59 }
60 for (j, fields) in partial {
61 for f in fields {
62 url.query_pairs_mut()
63 .append_pair("joins", &format!("{}.{}", &j.to_string(), &f));
64 }
65 }
66 }
67 }
68 Ok(())
69}