Skip to main content

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