icinga2_api/types/
metadata.rs

1//! structs related to the query metadata parameter
2//! and the result of queries including metadata
3use serde::{Deserialize, Serialize};
4
5use super::common::{object::IcingaObject, source_location::IcingaSourceLocation};
6
7/// possible meta parameter values
8#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
9pub enum IcingaMetadataType {
10    /// includes information about the other icinga objects using each returned object
11    UsedBy,
12    /// includes information about the config file location of each returned object
13    Location,
14}
15
16impl std::fmt::Display for IcingaMetadataType {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            IcingaMetadataType::UsedBy => write!(f, "used_by"),
20            IcingaMetadataType::Location => write!(f, "location"),
21        }
22    }
23}
24
25/// metadata
26#[derive(Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
27pub struct IcingaMetadata {
28    /// which other icinga objects use this object
29    pub used_by: Option<Vec<IcingaObject>>,
30    /// where in the config file this object is defined
31    pub location: Option<IcingaSourceLocation>,
32}
33
34/// shared code for all handlers that have a meta parameter
35pub(crate) fn add_meta_to_url(
36    url: &mut url::Url,
37    meta: &[IcingaMetadataType],
38) -> Result<(), crate::error::Error> {
39    if !meta.is_empty() {
40        for v in meta {
41            url.query_pairs_mut().append_pair("meta", &v.to_string());
42        }
43    }
44    Ok(())
45}