Skip to main content

openstack_sdk_identity/v3/domain/config/
list.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 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 openstack_sdk_core::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::GET
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        Some("config".into())
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    use http::{HeaderName, HeaderValue};
116    use httpmock::MockServer;
117    #[cfg(feature = "sync")]
118    use openstack_sdk_core::api::Query;
119    use openstack_sdk_core::test::client::FakeOpenStackClient;
120    use openstack_sdk_core::types::ServiceType;
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_eq!(
134            Request::builder().build().unwrap().response_key().unwrap(),
135            "config"
136        );
137    }
138
139    #[cfg(feature = "sync")]
140    #[test]
141    fn endpoint() {
142        let server = MockServer::start();
143        let client = FakeOpenStackClient::new(server.base_url());
144        let mock = server.mock(|when, then| {
145            when.method(httpmock::Method::GET).path(format!(
146                "/domains/{domain_id}/config",
147                domain_id = "domain_id",
148            ));
149
150            then.status(200)
151                .header("content-type", "application/json")
152                .json_body(json!({ "config": {} }));
153        });
154
155        let endpoint = Request::builder().domain_id("domain_id").build().unwrap();
156        let _: serde_json::Value = endpoint.query(&client).unwrap();
157        mock.assert();
158    }
159
160    #[cfg(feature = "sync")]
161    #[test]
162    fn endpoint_headers() {
163        let server = MockServer::start();
164        let client = FakeOpenStackClient::new(server.base_url());
165        let mock = server.mock(|when, then| {
166            when.method(httpmock::Method::GET)
167                .path(format!(
168                    "/domains/{domain_id}/config",
169                    domain_id = "domain_id",
170                ))
171                .header("foo", "bar")
172                .header("not_foo", "not_bar");
173            then.status(200)
174                .header("content-type", "application/json")
175                .json_body(json!({ "config": {} }));
176        });
177
178        let endpoint = Request::builder()
179            .domain_id("domain_id")
180            .headers(
181                [(
182                    Some(HeaderName::from_static("foo")),
183                    HeaderValue::from_static("bar"),
184                )]
185                .into_iter(),
186            )
187            .header(
188                HeaderName::from_static("not_foo"),
189                HeaderValue::from_static("not_bar"),
190            )
191            .build()
192            .unwrap();
193        let _: serde_json::Value = endpoint.query(&client).unwrap();
194        mock.assert();
195    }
196}