Skip to main content

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