Skip to main content

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