Skip to main content

openstack_sdk_identity/v3/user/
head.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//! List users.
19//!
20//! GET/HEAD /v3/users
21//!
22use derive_builder::Builder;
23use http::{HeaderMap, HeaderName, HeaderValue};
24
25use openstack_sdk_core::api::rest_endpoint_prelude::*;
26
27use std::borrow::Cow;
28
29use openstack_sdk_core::api::Pageable;
30#[derive(Builder, Debug, Clone)]
31#[builder(setter(strip_option))]
32pub struct Request<'a> {
33    /// The ID of the domain.
34    #[builder(default, setter(into))]
35    domain_id: Option<Cow<'a, str>>,
36
37    /// Whether the identity provider is enabled or not
38    #[builder(default)]
39    enabled: Option<bool>,
40
41    /// Filters the response by an identity provider ID.
42    #[builder(default, setter(into))]
43    idp_id: Option<Cow<'a, str>>,
44
45    #[builder(default)]
46    limit: Option<u32>,
47
48    /// ID of the last fetched entry
49    #[builder(default, setter(into))]
50    marker: Option<Cow<'a, str>>,
51
52    /// The resource name.
53    #[builder(default, setter(into))]
54    name: Option<Cow<'a, str>>,
55
56    /// Filter results based on which user passwords have expired. The query
57    /// should include an operator and a timestamp with a colon (:) separating
58    /// the two, for example: `password_expires_at={operator}:{timestamp}`
59    /// Valid operators are: lt, lte, gt, gte, eq, and neq
60    ///
61    /// - lt: expiration time lower than the timestamp
62    /// - lte: expiration time lower than or equal to the timestamp
63    /// - gt: expiration time higher than the timestamp
64    /// - gte: expiration time higher than or equal to the timestamp
65    /// - eq: expiration time equal to the timestamp
66    /// - neq: expiration time not equal to the timestamp
67    ///
68    /// Valid timestamps are of the form: `YYYY-MM-DDTHH:mm:ssZ`.For
69    /// example:`/v3/users?password_expires_at=lt:2016-12-08T22:02:00Z` The
70    /// example would return a list of users whose password expired before the
71    /// timestamp `(2016-12-08T22:02:00Z).`
72    #[builder(default, setter(into))]
73    password_expires_at: Option<Cow<'a, str>>,
74
75    /// Filters the response by a protocol ID.
76    #[builder(default, setter(into))]
77    protocol_id: Option<Cow<'a, str>>,
78
79    /// Sort direction. A valid value is asc (ascending) or desc (descending).
80    #[builder(default, setter(into))]
81    sort_dir: Option<Cow<'a, str>>,
82
83    /// Sorts resources by attribute.
84    #[builder(default, setter(into))]
85    sort_key: Option<Cow<'a, str>>,
86
87    /// Filters the response by a unique ID.
88    #[builder(default, setter(into))]
89    unique_id: Option<Cow<'a, str>>,
90
91    #[builder(setter(name = "_headers"), default, private)]
92    _headers: Option<HeaderMap>,
93}
94impl<'a> Request<'a> {
95    /// Create a builder for the endpoint.
96    pub fn builder() -> RequestBuilder<'a> {
97        RequestBuilder::default()
98    }
99}
100
101impl<'a> RequestBuilder<'a> {
102    /// Add a single header to the User.
103    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
104    where
105        K: Into<HeaderName>,
106        V: Into<HeaderValue>,
107    {
108        self._headers
109            .get_or_insert(None)
110            .get_or_insert_with(HeaderMap::new)
111            .insert(header_name.into(), header_value.into());
112        self
113    }
114
115    /// Add multiple headers.
116    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
117    where
118        I: Iterator<Item = T>,
119        T: Into<(Option<HeaderName>, HeaderValue)>,
120    {
121        self._headers
122            .get_or_insert(None)
123            .get_or_insert_with(HeaderMap::new)
124            .extend(iter.map(Into::into));
125        self
126    }
127}
128
129impl RestEndpoint for Request<'_> {
130    fn method(&self) -> http::Method {
131        http::Method::HEAD
132    }
133
134    fn endpoint(&self) -> Cow<'static, str> {
135        "users".to_string().into()
136    }
137
138    fn parameters(&self) -> QueryParams<'_> {
139        let mut params = QueryParams::default();
140        params.push_opt("domain_id", self.domain_id.as_ref());
141        params.push_opt("enabled", self.enabled);
142        params.push_opt("idp_id", self.idp_id.as_ref());
143        params.push_opt("limit", self.limit);
144        params.push_opt("marker", self.marker.as_ref());
145        params.push_opt("name", self.name.as_ref());
146        params.push_opt("password_expires_at", self.password_expires_at.as_ref());
147        params.push_opt("protocol_id", self.protocol_id.as_ref());
148        params.push_opt("sort_dir", self.sort_dir.as_ref());
149        params.push_opt("sort_key", self.sort_key.as_ref());
150        params.push_opt("unique_id", self.unique_id.as_ref());
151
152        params
153    }
154
155    fn service_type(&self) -> ServiceType {
156        ServiceType::Identity
157    }
158
159    fn response_key(&self) -> Option<Cow<'static, str>> {
160        None
161    }
162
163    /// Returns headers to be set into the request
164    fn request_headers(&self) -> Option<&HeaderMap> {
165        self._headers.as_ref()
166    }
167
168    /// Returns required API version
169    fn api_version(&self) -> Option<ApiVersion> {
170        Some(ApiVersion::new(3, 0))
171    }
172}
173impl Pageable for Request<'_> {}
174
175#[cfg(test)]
176mod tests {
177    use super::*;
178    use http::{HeaderName, HeaderValue};
179    use httpmock::MockServer;
180    #[cfg(feature = "sync")]
181    use openstack_sdk_core::api::RawQuery;
182    use openstack_sdk_core::test::client::FakeOpenStackClient;
183    use openstack_sdk_core::types::ServiceType;
184
185    #[test]
186    fn test_service_type() {
187        assert_eq!(
188            Request::builder().build().unwrap().service_type(),
189            ServiceType::Identity
190        );
191    }
192
193    #[test]
194    fn test_response_key() {
195        assert!(Request::builder().build().unwrap().response_key().is_none())
196    }
197
198    #[cfg(feature = "sync")]
199    #[test]
200    fn endpoint() {
201        let server = MockServer::start();
202        let client = FakeOpenStackClient::new(server.base_url());
203        let mock = server.mock(|when, then| {
204            when.method(httpmock::Method::HEAD)
205                .path("/users".to_string());
206
207            then.status(200).header("content-type", "application/json");
208        });
209
210        let endpoint = Request::builder().build().unwrap();
211        let _ = endpoint.raw_query(&client).unwrap();
212        mock.assert();
213    }
214
215    #[cfg(feature = "sync")]
216    #[test]
217    fn endpoint_headers() {
218        let server = MockServer::start();
219        let client = FakeOpenStackClient::new(server.base_url());
220        let mock = server.mock(|when, then| {
221            when.method(httpmock::Method::HEAD)
222                .path("/users".to_string())
223                .header("foo", "bar")
224                .header("not_foo", "not_bar");
225            then.status(200).header("content-type", "application/json");
226        });
227
228        let endpoint = Request::builder()
229            .headers(
230                [(
231                    Some(HeaderName::from_static("foo")),
232                    HeaderValue::from_static("bar"),
233                )]
234                .into_iter(),
235            )
236            .header(
237                HeaderName::from_static("not_foo"),
238                HeaderValue::from_static("not_bar"),
239            )
240            .build()
241            .unwrap();
242        let _ = endpoint.raw_query(&client).unwrap();
243        mock.assert();
244    }
245}