Skip to main content

openstack_sdk_identity/v3/role_assignment/
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 all role assignments.
19//!
20//! GET/HEAD /v3/role_assignments
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
29#[derive(Builder, Debug, Clone)]
30#[builder(setter(strip_option))]
31pub struct Request<'a> {
32    #[builder(default, setter(into))]
33    effective: Option<Cow<'a, str>>,
34
35    #[builder(default, setter(into))]
36    group_id: Option<Cow<'a, str>>,
37
38    #[builder(default, setter(into))]
39    include_names: Option<Cow<'a, str>>,
40
41    #[builder(default, setter(into))]
42    include_subtree: Option<Cow<'a, str>>,
43
44    #[builder(default, setter(into))]
45    role_id: Option<Cow<'a, str>>,
46
47    /// The ID of the domain.
48    #[builder(default, setter(into))]
49    scope_domain_id: Option<Cow<'a, str>>,
50
51    #[builder(default, setter(into))]
52    scope_os_inherit_inherited_to: Option<Cow<'a, str>>,
53
54    /// The ID of the project.
55    #[builder(default, setter(into))]
56    scope_project_id: Option<Cow<'a, str>>,
57
58    #[builder(default, setter(into))]
59    scope_system: Option<Cow<'a, str>>,
60
61    /// The ID of the user.
62    #[builder(default, setter(into))]
63    user_id: Option<Cow<'a, str>>,
64
65    #[builder(setter(name = "_headers"), default, private)]
66    _headers: Option<HeaderMap>,
67}
68impl<'a> Request<'a> {
69    /// Create a builder for the endpoint.
70    pub fn builder() -> RequestBuilder<'a> {
71        RequestBuilder::default()
72    }
73}
74
75impl<'a> RequestBuilder<'a> {
76    /// Add a single header to the Role_Assignment.
77    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
78    where
79        K: Into<HeaderName>,
80        V: Into<HeaderValue>,
81    {
82        self._headers
83            .get_or_insert(None)
84            .get_or_insert_with(HeaderMap::new)
85            .insert(header_name.into(), header_value.into());
86        self
87    }
88
89    /// Add multiple headers.
90    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
91    where
92        I: Iterator<Item = T>,
93        T: Into<(Option<HeaderName>, HeaderValue)>,
94    {
95        self._headers
96            .get_or_insert(None)
97            .get_or_insert_with(HeaderMap::new)
98            .extend(iter.map(Into::into));
99        self
100    }
101}
102
103impl RestEndpoint for Request<'_> {
104    fn method(&self) -> http::Method {
105        http::Method::HEAD
106    }
107
108    fn endpoint(&self) -> Cow<'static, str> {
109        "role_assignments".to_string().into()
110    }
111
112    fn parameters(&self) -> QueryParams<'_> {
113        let mut params = QueryParams::default();
114        params.push_opt("effective", self.effective.as_ref());
115        params.push_opt("group.id", self.group_id.as_ref());
116        params.push_opt("include_names", self.include_names.as_ref());
117        params.push_opt("include_subtree", self.include_subtree.as_ref());
118        params.push_opt("role.id", self.role_id.as_ref());
119        params.push_opt(
120            "scope.OS-INHERIT:inherited_to",
121            self.scope_os_inherit_inherited_to.as_ref(),
122        );
123        params.push_opt("scope.domain.id", self.scope_domain_id.as_ref());
124        params.push_opt("scope.project.id", self.scope_project_id.as_ref());
125        params.push_opt("scope.system", self.scope_system.as_ref());
126        params.push_opt("user.id", self.user_id.as_ref());
127
128        params
129    }
130
131    fn service_type(&self) -> ServiceType {
132        ServiceType::Identity
133    }
134
135    fn response_key(&self) -> Option<Cow<'static, str>> {
136        None
137    }
138
139    /// Returns headers to be set into the request
140    fn request_headers(&self) -> Option<&HeaderMap> {
141        self._headers.as_ref()
142    }
143
144    /// Returns required API version
145    fn api_version(&self) -> Option<ApiVersion> {
146        Some(ApiVersion::new(3, 0))
147    }
148}
149
150#[cfg(test)]
151mod tests {
152    use super::*;
153    use http::{HeaderName, HeaderValue};
154    use httpmock::MockServer;
155    #[cfg(feature = "sync")]
156    use openstack_sdk_core::api::RawQuery;
157    use openstack_sdk_core::test::client::FakeOpenStackClient;
158    use openstack_sdk_core::types::ServiceType;
159
160    #[test]
161    fn test_service_type() {
162        assert_eq!(
163            Request::builder().build().unwrap().service_type(),
164            ServiceType::Identity
165        );
166    }
167
168    #[test]
169    fn test_response_key() {
170        assert!(Request::builder().build().unwrap().response_key().is_none())
171    }
172
173    #[cfg(feature = "sync")]
174    #[test]
175    fn endpoint() {
176        let server = MockServer::start();
177        let client = FakeOpenStackClient::new(server.base_url());
178        let mock = server.mock(|when, then| {
179            when.method(httpmock::Method::HEAD)
180                .path("/role_assignments".to_string());
181
182            then.status(200).header("content-type", "application/json");
183        });
184
185        let endpoint = Request::builder().build().unwrap();
186        let _ = endpoint.raw_query(&client).unwrap();
187        mock.assert();
188    }
189
190    #[cfg(feature = "sync")]
191    #[test]
192    fn endpoint_headers() {
193        let server = MockServer::start();
194        let client = FakeOpenStackClient::new(server.base_url());
195        let mock = server.mock(|when, then| {
196            when.method(httpmock::Method::HEAD)
197                .path("/role_assignments".to_string())
198                .header("foo", "bar")
199                .header("not_foo", "not_bar");
200            then.status(200).header("content-type", "application/json");
201        });
202
203        let endpoint = Request::builder()
204            .headers(
205                [(
206                    Some(HeaderName::from_static("foo")),
207                    HeaderValue::from_static("bar"),
208                )]
209                .into_iter(),
210            )
211            .header(
212                HeaderName::from_static("not_foo"),
213                HeaderValue::from_static("not_bar"),
214            )
215            .build()
216            .unwrap();
217        let _ = endpoint.raw_query(&client).unwrap();
218        mock.assert();
219    }
220}