Skip to main content

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