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