Skip to main content

openstack_sdk_load_balancer/v2/quota/
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 all quotas for the project.
19//!
20//! Use the `fields` query parameter to control which fields are returned in
21//! the response body. Additionally, you can filter results by using query
22//! string parameters. For information, see
23//! [Filtering and column selection](#filtering).
24//!
25//! Administrative users can specify a project ID that is different than their
26//! own to list quotas for other projects.
27//!
28//! If the quota is listed as `null` the quota is using the deployment default
29//! quota settings.
30//!
31//! A quota of `-1` means the quota is unlimited.
32//!
33//! The list might be empty.
34//!
35use derive_builder::Builder;
36use http::{HeaderMap, HeaderName, HeaderValue};
37
38use openstack_sdk_core::api::rest_endpoint_prelude::*;
39
40#[derive(Builder, Debug, Clone)]
41#[builder(setter(strip_option))]
42pub struct Request {
43    #[builder(setter(name = "_headers"), default, private)]
44    _headers: Option<HeaderMap>,
45}
46impl Request {
47    /// Create a builder for the endpoint.
48    pub fn builder() -> RequestBuilder {
49        RequestBuilder::default()
50    }
51}
52
53impl RequestBuilder {
54    /// Add a single header to the Quota.
55    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
56    where
57        K: Into<HeaderName>,
58        V: Into<HeaderValue>,
59    {
60        self._headers
61            .get_or_insert(None)
62            .get_or_insert_with(HeaderMap::new)
63            .insert(header_name.into(), header_value.into());
64        self
65    }
66
67    /// Add multiple headers.
68    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
69    where
70        I: Iterator<Item = T>,
71        T: Into<(Option<HeaderName>, HeaderValue)>,
72    {
73        self._headers
74            .get_or_insert(None)
75            .get_or_insert_with(HeaderMap::new)
76            .extend(iter.map(Into::into));
77        self
78    }
79}
80
81impl RestEndpoint for Request {
82    fn method(&self) -> http::Method {
83        http::Method::GET
84    }
85
86    fn endpoint(&self) -> Cow<'static, str> {
87        "lbaas/quotas".to_string().into()
88    }
89
90    fn parameters(&self) -> QueryParams<'_> {
91        QueryParams::default()
92    }
93
94    fn service_type(&self) -> ServiceType {
95        ServiceType::LoadBalancer
96    }
97
98    fn response_key(&self) -> Option<Cow<'static, str>> {
99        Some("quotas".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(2, 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::LoadBalancer
129        );
130    }
131
132    #[test]
133    fn test_response_key() {
134        assert_eq!(
135            Request::builder().build().unwrap().response_key().unwrap(),
136            "quotas"
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("/lbaas/quotas".to_string());
148
149            then.status(200)
150                .header("content-type", "application/json")
151                .json_body(json!({ "quotas": {} }));
152        });
153
154        let endpoint = Request::builder().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("/lbaas/quotas".to_string())
167                .header("foo", "bar")
168                .header("not_foo", "not_bar");
169            then.status(200)
170                .header("content-type", "application/json")
171                .json_body(json!({ "quotas": {} }));
172        });
173
174        let endpoint = Request::builder()
175            .headers(
176                [(
177                    Some(HeaderName::from_static("foo")),
178                    HeaderValue::from_static("bar"),
179                )]
180                .into_iter(),
181            )
182            .header(
183                HeaderName::from_static("not_foo"),
184                HeaderValue::from_static("not_bar"),
185            )
186            .build()
187            .unwrap();
188        let _: serde_json::Value = endpoint.query(&client).unwrap();
189        mock.assert();
190    }
191}