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