Skip to main content

openstack_sdk_identity/v3/role_inference/
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 role inference rules.
19//!
20//! Relationship:
21//! `https://developer.openstack.org/api-ref/identity/v3/#list-all-role-inference-rules`
22//!
23use derive_builder::Builder;
24use http::{HeaderMap, HeaderName, HeaderValue};
25
26use openstack_sdk_core::api::rest_endpoint_prelude::*;
27
28#[derive(Builder, Debug, Clone)]
29#[builder(setter(strip_option))]
30pub struct Request {
31    #[builder(setter(name = "_headers"), default, private)]
32    _headers: Option<HeaderMap>,
33}
34impl Request {
35    /// Create a builder for the endpoint.
36    pub fn builder() -> RequestBuilder {
37        RequestBuilder::default()
38    }
39}
40
41impl RequestBuilder {
42    /// Add a single header to the Role_Inference.
43    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
44    where
45        K: Into<HeaderName>,
46        V: Into<HeaderValue>,
47    {
48        self._headers
49            .get_or_insert(None)
50            .get_or_insert_with(HeaderMap::new)
51            .insert(header_name.into(), header_value.into());
52        self
53    }
54
55    /// Add multiple headers.
56    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
57    where
58        I: Iterator<Item = T>,
59        T: Into<(Option<HeaderName>, HeaderValue)>,
60    {
61        self._headers
62            .get_or_insert(None)
63            .get_or_insert_with(HeaderMap::new)
64            .extend(iter.map(Into::into));
65        self
66    }
67}
68
69impl RestEndpoint for Request {
70    fn method(&self) -> http::Method {
71        http::Method::GET
72    }
73
74    fn endpoint(&self) -> Cow<'static, str> {
75        "role_inferences".to_string().into()
76    }
77
78    fn parameters(&self) -> QueryParams<'_> {
79        QueryParams::default()
80    }
81
82    fn service_type(&self) -> ServiceType {
83        ServiceType::Identity
84    }
85
86    fn response_key(&self) -> Option<Cow<'static, str>> {
87        Some("role_inferences".into())
88    }
89
90    /// Returns headers to be set into the request
91    fn request_headers(&self) -> Option<&HeaderMap> {
92        self._headers.as_ref()
93    }
94
95    /// Returns required API version
96    fn api_version(&self) -> Option<ApiVersion> {
97        Some(ApiVersion::new(3, 0))
98    }
99}
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104    use http::{HeaderName, HeaderValue};
105    use httpmock::MockServer;
106    #[cfg(feature = "sync")]
107    use openstack_sdk_core::api::Query;
108    use openstack_sdk_core::test::client::FakeOpenStackClient;
109    use openstack_sdk_core::types::ServiceType;
110    use serde_json::json;
111
112    #[test]
113    fn test_service_type() {
114        assert_eq!(
115            Request::builder().build().unwrap().service_type(),
116            ServiceType::Identity
117        );
118    }
119
120    #[test]
121    fn test_response_key() {
122        assert_eq!(
123            Request::builder().build().unwrap().response_key().unwrap(),
124            "role_inferences"
125        );
126    }
127
128    #[cfg(feature = "sync")]
129    #[test]
130    fn endpoint() {
131        let server = MockServer::start();
132        let client = FakeOpenStackClient::new(server.base_url());
133        let mock = server.mock(|when, then| {
134            when.method(httpmock::Method::GET)
135                .path("/role_inferences".to_string());
136
137            then.status(200)
138                .header("content-type", "application/json")
139                .json_body(json!({ "role_inferences": {} }));
140        });
141
142        let endpoint = Request::builder().build().unwrap();
143        let _: serde_json::Value = endpoint.query(&client).unwrap();
144        mock.assert();
145    }
146
147    #[cfg(feature = "sync")]
148    #[test]
149    fn endpoint_headers() {
150        let server = MockServer::start();
151        let client = FakeOpenStackClient::new(server.base_url());
152        let mock = server.mock(|when, then| {
153            when.method(httpmock::Method::GET)
154                .path("/role_inferences".to_string())
155                .header("foo", "bar")
156                .header("not_foo", "not_bar");
157            then.status(200)
158                .header("content-type", "application/json")
159                .json_body(json!({ "role_inferences": {} }));
160        });
161
162        let endpoint = Request::builder()
163            .headers(
164                [(
165                    Some(HeaderName::from_static("foo")),
166                    HeaderValue::from_static("bar"),
167                )]
168                .into_iter(),
169            )
170            .header(
171                HeaderName::from_static("not_foo"),
172                HeaderValue::from_static("not_bar"),
173            )
174            .build()
175            .unwrap();
176        let _: serde_json::Value = endpoint.query(&client).unwrap();
177        mock.assert();
178    }
179}