openstack_sdk/api/dns/v2/tsigkey/
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//! Delete a tsigkey
19//!
20use derive_builder::Builder;
21use http::{HeaderMap, HeaderName, HeaderValue};
22
23use crate::api::rest_endpoint_prelude::*;
24
25use std::borrow::Cow;
26
27#[derive(Builder, Debug, Clone)]
28#[builder(setter(strip_option))]
29pub struct Request<'a> {
30    /// tsigkey_id parameter for /v2/tsigkeys/{tsigkey_id} API
31    #[builder(default, setter(into))]
32    id: Cow<'a, str>,
33
34    #[builder(setter(name = "_headers"), default, private)]
35    _headers: Option<HeaderMap>,
36}
37impl<'a> Request<'a> {
38    /// Create a builder for the endpoint.
39    pub fn builder() -> RequestBuilder<'a> {
40        RequestBuilder::default()
41    }
42}
43
44impl RequestBuilder<'_> {
45    /// Add a single header to the Tsigkey.
46    pub fn header(&mut self, header_name: &'static str, header_value: &'static str) -> &mut Self
47where {
48        self._headers
49            .get_or_insert(None)
50            .get_or_insert_with(HeaderMap::new)
51            .insert(header_name, HeaderValue::from_static(header_value));
52        self
53    }
54
55    /// Add multiple headers.
56    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
57    where
58        I: Iterator<Item = T>,
59        T: Into<(Option<HeaderName>, HeaderValue)>,
60    {
61        self._headers
62            .get_or_insert(None)
63            .get_or_insert_with(HeaderMap::new)
64            .extend(iter.map(Into::into));
65        self
66    }
67}
68
69impl RestEndpoint for Request<'_> {
70    fn method(&self) -> http::Method {
71        http::Method::DELETE
72    }
73
74    fn endpoint(&self) -> Cow<'static, str> {
75        format!("tsigkeys/{id}", id = self.id.as_ref(),).into()
76    }
77
78    fn parameters(&self) -> QueryParams {
79        QueryParams::default()
80    }
81
82    fn service_type(&self) -> ServiceType {
83        ServiceType::Dns
84    }
85
86    fn response_key(&self) -> Option<Cow<'static, str>> {
87        None
88    }
89
90    /// Returns headers to be set into the request
91    fn request_headers(&self) -> Option<&HeaderMap> {
92        self._headers.as_ref()
93    }
94
95    /// Returns required API version
96    fn api_version(&self) -> Option<ApiVersion> {
97        Some(ApiVersion::new(2, 0))
98    }
99}
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104    #[cfg(feature = "sync")]
105    use crate::api::Query;
106    use crate::test::client::FakeOpenStackClient;
107    use crate::types::ServiceType;
108    use http::{HeaderName, HeaderValue};
109    use httpmock::MockServer;
110    use serde_json::json;
111
112    #[test]
113    fn test_service_type() {
114        assert_eq!(
115            Request::builder().build().unwrap().service_type(),
116            ServiceType::Dns
117        );
118    }
119
120    #[test]
121    fn test_response_key() {
122        assert!(Request::builder().build().unwrap().response_key().is_none())
123    }
124
125    #[cfg(feature = "sync")]
126    #[test]
127    fn endpoint() {
128        let server = MockServer::start();
129        let client = FakeOpenStackClient::new(server.base_url());
130        let mock = server.mock(|when, then| {
131            when.method(httpmock::Method::DELETE)
132                .path(format!("/tsigkeys/{id}", id = "id",));
133
134            then.status(200)
135                .header("content-type", "application/json")
136                .json_body(json!({ "dummy": {} }));
137        });
138
139        let endpoint = Request::builder().id("id").build().unwrap();
140        let _: serde_json::Value = endpoint.query(&client).unwrap();
141        mock.assert();
142    }
143
144    #[cfg(feature = "sync")]
145    #[test]
146    fn endpoint_headers() {
147        let server = MockServer::start();
148        let client = FakeOpenStackClient::new(server.base_url());
149        let mock = server.mock(|when, then| {
150            when.method(httpmock::Method::DELETE)
151                .path(format!("/tsigkeys/{id}", id = "id",))
152                .header("foo", "bar")
153                .header("not_foo", "not_bar");
154            then.status(200)
155                .header("content-type", "application/json")
156                .json_body(json!({ "dummy": {} }));
157        });
158
159        let endpoint = Request::builder()
160            .id("id")
161            .headers(
162                [(
163                    Some(HeaderName::from_static("foo")),
164                    HeaderValue::from_static("bar"),
165                )]
166                .into_iter(),
167            )
168            .header("not_foo", "not_bar")
169            .build()
170            .unwrap();
171        let _: serde_json::Value = endpoint.query(&client).unwrap();
172        mock.assert();
173    }
174}