Skip to main content

openstack_sdk_identity/v3/domain/config/
head.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//! Check if config option exists.
19//!
20//! GET/HEAD /v3/domains/{domain_id}/config GET/HEAD
21//! /v3/domains/{domain_id}/config/{group} GET/HEAD
22//! /v3/domains/{domain_id}/config/{group}/{option}
23//!
24use derive_builder::Builder;
25use http::{HeaderMap, HeaderName, HeaderValue};
26
27use openstack_sdk_core::api::rest_endpoint_prelude::*;
28
29use std::borrow::Cow;
30
31#[derive(Builder, Debug, Clone)]
32#[builder(setter(strip_option))]
33pub struct Request<'a> {
34    /// domain_id parameter for /v3/domains/{domain_id}/config/{group}/{option}
35    /// API
36    #[builder(default, setter(into))]
37    domain_id: 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 Config.
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::HEAD
80    }
81
82    fn endpoint(&self) -> Cow<'static, str> {
83        format!(
84            "domains/{domain_id}/config",
85            domain_id = self.domain_id.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        None
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::RawQuery;
120    use openstack_sdk_core::test::client::FakeOpenStackClient;
121    use openstack_sdk_core::types::ServiceType;
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::HEAD).path(format!(
143                "/domains/{domain_id}/config",
144                domain_id = "domain_id",
145            ));
146
147            then.status(200).header("content-type", "application/json");
148        });
149
150        let endpoint = Request::builder().domain_id("domain_id").build().unwrap();
151        let _ = endpoint.raw_query(&client).unwrap();
152        mock.assert();
153    }
154
155    #[cfg(feature = "sync")]
156    #[test]
157    fn endpoint_headers() {
158        let server = MockServer::start();
159        let client = FakeOpenStackClient::new(server.base_url());
160        let mock = server.mock(|when, then| {
161            when.method(httpmock::Method::HEAD)
162                .path(format!(
163                    "/domains/{domain_id}/config",
164                    domain_id = "domain_id",
165                ))
166                .header("foo", "bar")
167                .header("not_foo", "not_bar");
168            then.status(200).header("content-type", "application/json");
169        });
170
171        let endpoint = Request::builder()
172            .domain_id("domain_id")
173            .headers(
174                [(
175                    Some(HeaderName::from_static("foo")),
176                    HeaderValue::from_static("bar"),
177                )]
178                .into_iter(),
179            )
180            .header(
181                HeaderName::from_static("not_foo"),
182                HeaderValue::from_static("not_bar"),
183            )
184            .build()
185            .unwrap();
186        let _ = endpoint.raw_query(&client).unwrap();
187        mock.assert();
188    }
189}