icinga2_api/api/action/
generate_ticket.rs

1//! API Action generate-ticket
2//!
3//! [Official Documentation](https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#generate-ticket)
4
5use serde::{Deserialize, Serialize};
6
7use crate::types::action::GenerateTicketResponse;
8use crate::types::query::ResultsWrapper;
9use crate::types::rest::{RestApiEndpoint, RestApiResponse};
10
11/// REST API Endpoint for the generate-ticket call
12#[derive(Debug, Clone, derive_builder::Builder, Serialize, Deserialize)]
13#[builder(build_fn(error = "crate::error::Error"), derive(Debug))]
14pub struct GenerateTicket {
15    /// The host’s common name for which the ticket should be generated.
16    cn: String,
17}
18
19impl GenerateTicket {
20    /// create a new builder for this endpoint
21    ///
22    /// this is usually the first step to calling this REST API endpoint
23    #[must_use]
24    pub fn builder() -> GenerateTicketBuilder {
25        GenerateTicketBuilder::default()
26    }
27}
28
29impl RestApiEndpoint for GenerateTicket {
30    type RequestBody = GenerateTicket;
31
32    fn method(&self) -> Result<reqwest::Method, crate::error::Error> {
33        Ok(reqwest::Method::POST)
34    }
35
36    fn url(&self, base_url: &url::Url) -> Result<url::Url, crate::error::Error> {
37        base_url
38            .join("v1/actions/generate-ticket")
39            .map_err(crate::error::Error::CouldNotParseUrlFragment)
40    }
41
42    fn request_body(
43        &self,
44    ) -> Result<Option<std::borrow::Cow<Self::RequestBody>>, crate::error::Error>
45    where
46        Self::RequestBody: Clone + serde::Serialize + std::fmt::Debug,
47    {
48        Ok(Some(std::borrow::Cow::Borrowed(self)))
49    }
50}
51
52impl RestApiResponse<GenerateTicket> for ResultsWrapper<GenerateTicketResponse> {}