Skip to main content

openstack_sdk_load_balancer/v2/l7policy/
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 L7 policies 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 L7 policies for other projects.
27//!
28//! The list might be empty.
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
37use openstack_sdk_core::api::Pageable;
38#[derive(Builder, Debug, Clone)]
39#[builder(setter(strip_option))]
40pub struct Request<'a> {
41    #[builder(default, setter(into))]
42    action: Option<Cow<'a, str>>,
43
44    #[builder(default)]
45    admin_state_up: Option<bool>,
46
47    #[builder(default, setter(into))]
48    description: Option<Cow<'a, str>>,
49
50    /// Page size
51    #[builder(default)]
52    limit: Option<i32>,
53
54    #[builder(default, setter(into))]
55    listener_id: Option<Cow<'a, str>>,
56
57    /// ID of the last item in the previous list
58    #[builder(default, setter(into))]
59    marker: Option<Cow<'a, str>>,
60
61    #[builder(default, setter(into))]
62    name: Option<Cow<'a, str>>,
63
64    #[builder(default, setter(into))]
65    operating_status: Option<Cow<'a, str>>,
66
67    /// The page direction.
68    #[builder(default)]
69    page_reverse: Option<bool>,
70
71    #[builder(default, setter(into))]
72    position: Option<Cow<'a, str>>,
73
74    #[builder(default, setter(into))]
75    project_id: Option<Cow<'a, str>>,
76
77    #[builder(default, setter(into))]
78    provisioning_status: Option<Cow<'a, str>>,
79
80    #[builder(default, setter(into))]
81    redirect_pool_id: Option<Cow<'a, str>>,
82
83    #[builder(default, setter(into))]
84    redirect_prefix: Option<Cow<'a, str>>,
85
86    #[builder(default, setter(into))]
87    redirect_url: Option<Cow<'a, str>>,
88
89    #[builder(setter(name = "_headers"), default, private)]
90    _headers: Option<HeaderMap>,
91}
92impl<'a> Request<'a> {
93    /// Create a builder for the endpoint.
94    pub fn builder() -> RequestBuilder<'a> {
95        RequestBuilder::default()
96    }
97}
98
99impl<'a> RequestBuilder<'a> {
100    /// Add a single header to the L7Policy.
101    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
102    where
103        K: Into<HeaderName>,
104        V: Into<HeaderValue>,
105    {
106        self._headers
107            .get_or_insert(None)
108            .get_or_insert_with(HeaderMap::new)
109            .insert(header_name.into(), header_value.into());
110        self
111    }
112
113    /// Add multiple headers.
114    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
115    where
116        I: Iterator<Item = T>,
117        T: Into<(Option<HeaderName>, HeaderValue)>,
118    {
119        self._headers
120            .get_or_insert(None)
121            .get_or_insert_with(HeaderMap::new)
122            .extend(iter.map(Into::into));
123        self
124    }
125}
126
127impl RestEndpoint for Request<'_> {
128    fn method(&self) -> http::Method {
129        http::Method::GET
130    }
131
132    fn endpoint(&self) -> Cow<'static, str> {
133        "lbaas/l7policies".to_string().into()
134    }
135
136    fn parameters(&self) -> QueryParams<'_> {
137        let mut params = QueryParams::default();
138        params.push_opt("action", self.action.as_ref());
139        params.push_opt("admin_state_up", self.admin_state_up);
140        params.push_opt("description", self.description.as_ref());
141        params.push_opt("limit", self.limit);
142        params.push_opt("listener_id", self.listener_id.as_ref());
143        params.push_opt("marker", self.marker.as_ref());
144        params.push_opt("name", self.name.as_ref());
145        params.push_opt("operating_status", self.operating_status.as_ref());
146        params.push_opt("page_reverse", self.page_reverse);
147        params.push_opt("position", self.position.as_ref());
148        params.push_opt("project_id", self.project_id.as_ref());
149        params.push_opt("provisioning_status", self.provisioning_status.as_ref());
150        params.push_opt("redirect_pool_id", self.redirect_pool_id.as_ref());
151        params.push_opt("redirect_prefix", self.redirect_prefix.as_ref());
152        params.push_opt("redirect_url", self.redirect_url.as_ref());
153
154        params
155    }
156
157    fn service_type(&self) -> ServiceType {
158        ServiceType::LoadBalancer
159    }
160
161    fn response_key(&self) -> Option<Cow<'static, str>> {
162        Some("l7policies".into())
163    }
164
165    /// Returns headers to be set into the request
166    fn request_headers(&self) -> Option<&HeaderMap> {
167        self._headers.as_ref()
168    }
169
170    /// Returns required API version
171    fn api_version(&self) -> Option<ApiVersion> {
172        Some(ApiVersion::new(2, 0))
173    }
174}
175impl Pageable for Request<'_> {}
176
177#[cfg(test)]
178mod tests {
179    use super::*;
180    use http::{HeaderName, HeaderValue};
181    use httpmock::MockServer;
182    #[cfg(feature = "sync")]
183    use openstack_sdk_core::api::Query;
184    use openstack_sdk_core::test::client::FakeOpenStackClient;
185    use openstack_sdk_core::types::ServiceType;
186    use serde_json::json;
187
188    #[test]
189    fn test_service_type() {
190        assert_eq!(
191            Request::builder().build().unwrap().service_type(),
192            ServiceType::LoadBalancer
193        );
194    }
195
196    #[test]
197    fn test_response_key() {
198        assert_eq!(
199            Request::builder().build().unwrap().response_key().unwrap(),
200            "l7policies"
201        );
202    }
203
204    #[cfg(feature = "sync")]
205    #[test]
206    fn endpoint() {
207        let server = MockServer::start();
208        let client = FakeOpenStackClient::new(server.base_url());
209        let mock = server.mock(|when, then| {
210            when.method(httpmock::Method::GET)
211                .path("/lbaas/l7policies".to_string());
212
213            then.status(200)
214                .header("content-type", "application/json")
215                .json_body(json!({ "l7policies": {} }));
216        });
217
218        let endpoint = Request::builder().build().unwrap();
219        let _: serde_json::Value = endpoint.query(&client).unwrap();
220        mock.assert();
221    }
222
223    #[cfg(feature = "sync")]
224    #[test]
225    fn endpoint_headers() {
226        let server = MockServer::start();
227        let client = FakeOpenStackClient::new(server.base_url());
228        let mock = server.mock(|when, then| {
229            when.method(httpmock::Method::GET)
230                .path("/lbaas/l7policies".to_string())
231                .header("foo", "bar")
232                .header("not_foo", "not_bar");
233            then.status(200)
234                .header("content-type", "application/json")
235                .json_body(json!({ "l7policies": {} }));
236        });
237
238        let endpoint = Request::builder()
239            .headers(
240                [(
241                    Some(HeaderName::from_static("foo")),
242                    HeaderValue::from_static("bar"),
243                )]
244                .into_iter(),
245            )
246            .header(
247                HeaderName::from_static("not_foo"),
248                HeaderValue::from_static("not_bar"),
249            )
250            .build()
251            .unwrap();
252        let _: serde_json::Value = endpoint.query(&client).unwrap();
253        mock.assert();
254    }
255}