openstack_sdk/api/dns/v2/zone/task/export/
delete.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18//! This will just delete the record of the zone export, not the exported zone.
19//!
20//! The zone will have to be deleted from the zone delete API
21//!
22use derive_builder::Builder;
23use http::{HeaderMap, HeaderName, HeaderValue};
24
25use crate::api::rest_endpoint_prelude::*;
26
27use std::borrow::Cow;
28
29#[derive(Builder, Debug, Clone)]
30#[builder(setter(strip_option))]
31pub struct Request<'a> {
32    /// zone_export_id parameter for /v2/zones/tasks/exports/{zone_export_id}
33    /// API
34    #[builder(default, setter(into))]
35    zone_export_id: Cow<'a, str>,
36
37    #[builder(setter(name = "_headers"), default, private)]
38    _headers: Option<HeaderMap>,
39}
40impl<'a> Request<'a> {
41    /// Create a builder for the endpoint.
42    pub fn builder() -> RequestBuilder<'a> {
43        RequestBuilder::default()
44    }
45}
46
47impl<'a> RequestBuilder<'a> {
48    /// Add a single header to the Export.
49    pub fn header(&mut self, header_name: &'static str, header_value: &'static str) -> &mut Self
50where {
51        self._headers
52            .get_or_insert(None)
53            .get_or_insert_with(HeaderMap::new)
54            .insert(header_name, HeaderValue::from_static(header_value));
55        self
56    }
57
58    /// Add multiple headers.
59    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
60    where
61        I: Iterator<Item = T>,
62        T: Into<(Option<HeaderName>, HeaderValue)>,
63    {
64        self._headers
65            .get_or_insert(None)
66            .get_or_insert_with(HeaderMap::new)
67            .extend(iter.map(Into::into));
68        self
69    }
70}
71
72impl RestEndpoint for Request<'_> {
73    fn method(&self) -> http::Method {
74        http::Method::DELETE
75    }
76
77    fn endpoint(&self) -> Cow<'static, str> {
78        format!(
79            "zones/tasks/exports/{zone_export_id}",
80            zone_export_id = self.zone_export_id.as_ref(),
81        )
82        .into()
83    }
84
85    fn parameters(&self) -> QueryParams {
86        QueryParams::default()
87    }
88
89    fn service_type(&self) -> ServiceType {
90        ServiceType::Dns
91    }
92
93    fn response_key(&self) -> Option<Cow<'static, str>> {
94        None
95    }
96
97    /// Returns headers to be set into the request
98    fn request_headers(&self) -> Option<&HeaderMap> {
99        self._headers.as_ref()
100    }
101
102    /// Returns required API version
103    fn api_version(&self) -> Option<ApiVersion> {
104        Some(ApiVersion::new(2, 0))
105    }
106}
107
108#[cfg(test)]
109mod tests {
110    use super::*;
111    #[cfg(feature = "sync")]
112    use crate::api::Query;
113    use crate::test::client::FakeOpenStackClient;
114    use crate::types::ServiceType;
115    use http::{HeaderName, HeaderValue};
116    use httpmock::MockServer;
117    use serde_json::json;
118
119    #[test]
120    fn test_service_type() {
121        assert_eq!(
122            Request::builder().build().unwrap().service_type(),
123            ServiceType::Dns
124        );
125    }
126
127    #[test]
128    fn test_response_key() {
129        assert!(Request::builder().build().unwrap().response_key().is_none())
130    }
131
132    #[cfg(feature = "sync")]
133    #[test]
134    fn endpoint() {
135        let server = MockServer::start();
136        let client = FakeOpenStackClient::new(server.base_url());
137        let mock = server.mock(|when, then| {
138            when.method(httpmock::Method::DELETE).path(format!(
139                "/zones/tasks/exports/{zone_export_id}",
140                zone_export_id = "zone_export_id",
141            ));
142
143            then.status(200)
144                .header("content-type", "application/json")
145                .json_body(json!({ "dummy": {} }));
146        });
147
148        let endpoint = Request::builder()
149            .zone_export_id("zone_export_id")
150            .build()
151            .unwrap();
152        let _: serde_json::Value = endpoint.query(&client).unwrap();
153        mock.assert();
154    }
155
156    #[cfg(feature = "sync")]
157    #[test]
158    fn endpoint_headers() {
159        let server = MockServer::start();
160        let client = FakeOpenStackClient::new(server.base_url());
161        let mock = server.mock(|when, then| {
162            when.method(httpmock::Method::DELETE)
163                .path(format!(
164                    "/zones/tasks/exports/{zone_export_id}",
165                    zone_export_id = "zone_export_id",
166                ))
167                .header("foo", "bar")
168                .header("not_foo", "not_bar");
169            then.status(200)
170                .header("content-type", "application/json")
171                .json_body(json!({ "dummy": {} }));
172        });
173
174        let endpoint = Request::builder()
175            .zone_export_id("zone_export_id")
176            .headers(
177                [(
178                    Some(HeaderName::from_static("foo")),
179                    HeaderValue::from_static("bar"),
180                )]
181                .into_iter(),
182            )
183            .header("not_foo", "not_bar")
184            .build()
185            .unwrap();
186        let _: serde_json::Value = endpoint.query(&client).unwrap();
187        mock.assert();
188    }
189}