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