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