Skip to main content

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