1use crate::Client;
2use crate::ClientResult;
3
4pub struct RoleAssignments {
5 pub client: Client,
6}
7
8impl RoleAssignments {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 RoleAssignments { client }
12 }
13
14 pub async fn list(
28 &self,
29 customer: &str,
30 max_results: i64,
31 page_token: &str,
32 role_id: &str,
33 user_key: &str,
34 ) -> ClientResult<crate::Response<Vec<crate::types::RoleAssignment>>> {
35 let mut query_args: Vec<(String, String)> = Default::default();
36 if max_results > 0 {
37 query_args.push(("maxResults".to_string(), max_results.to_string()));
38 }
39 if !page_token.is_empty() {
40 query_args.push(("pageToken".to_string(), page_token.to_string()));
41 }
42 if !role_id.is_empty() {
43 query_args.push(("roleId".to_string(), role_id.to_string()));
44 }
45 if !user_key.is_empty() {
46 query_args.push(("userKey".to_string(), user_key.to_string()));
47 }
48 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
49 let url = self.client.url(
50 &format!(
51 "/admin/directory/v1/customer/{}/roleassignments?{}",
52 crate::progenitor_support::encode_path(customer),
53 query_
54 ),
55 None,
56 );
57 let resp: crate::Response<crate::types::RoleAssignments> = self
58 .client
59 .get(
60 &url,
61 crate::Message {
62 body: None,
63 content_type: None,
64 },
65 )
66 .await?;
67
68 Ok(crate::Response::new(
70 resp.status,
71 resp.headers,
72 resp.body.items.to_vec(),
73 ))
74 }
75 pub async fn list_all(
83 &self,
84 customer: &str,
85 role_id: &str,
86 user_key: &str,
87 ) -> ClientResult<crate::Response<Vec<crate::types::RoleAssignment>>> {
88 let mut query_args: Vec<(String, String)> = Default::default();
89 if !role_id.is_empty() {
90 query_args.push(("roleId".to_string(), role_id.to_string()));
91 }
92 if !user_key.is_empty() {
93 query_args.push(("userKey".to_string(), user_key.to_string()));
94 }
95 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
96 let url = self.client.url(
97 &format!(
98 "/admin/directory/v1/customer/{}/roleassignments?{}",
99 crate::progenitor_support::encode_path(customer),
100 query_
101 ),
102 None,
103 );
104 let crate::Response::<crate::types::RoleAssignments> {
105 mut status,
106 mut headers,
107 mut body,
108 } = self
109 .client
110 .get(
111 &url,
112 crate::Message {
113 body: None,
114 content_type: None,
115 },
116 )
117 .await?;
118
119 let mut items = body.items;
120 let mut page = body.next_page_token;
121
122 while !page.is_empty() {
124 if !url.contains('?') {
125 crate::Response::<crate::types::RoleAssignments> {
126 status,
127 headers,
128 body,
129 } = self
130 .client
131 .get(
132 &format!("{}?pageToken={}", url, page),
133 crate::Message {
134 body: None,
135 content_type: None,
136 },
137 )
138 .await?;
139 } else {
140 crate::Response::<crate::types::RoleAssignments> {
141 status,
142 headers,
143 body,
144 } = self
145 .client
146 .get(
147 &format!("{}&pageToken={}", url, page),
148 crate::Message {
149 body: None,
150 content_type: None,
151 },
152 )
153 .await?;
154 }
155
156 items.append(&mut body.items);
157
158 if !body.next_page_token.is_empty() && body.next_page_token != page {
159 page = body.next_page_token.to_string();
160 } else {
161 page = "".to_string();
162 }
163 }
164
165 Ok(crate::Response::new(status, headers, items))
167 }
168 pub async fn insert(
178 &self,
179 customer: &str,
180 body: &crate::types::RoleAssignment,
181 ) -> ClientResult<crate::Response<crate::types::RoleAssignment>> {
182 let url = self.client.url(
183 &format!(
184 "/admin/directory/v1/customer/{}/roleassignments",
185 crate::progenitor_support::encode_path(customer),
186 ),
187 None,
188 );
189 self.client
190 .post(
191 &url,
192 crate::Message {
193 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
194 content_type: Some("application/json".to_string()),
195 },
196 )
197 .await
198 }
199 pub async fn get(
210 &self,
211 customer: &str,
212 role_assignment_id: &str,
213 ) -> ClientResult<crate::Response<crate::types::RoleAssignment>> {
214 let url = self.client.url(
215 &format!(
216 "/admin/directory/v1/customer/{}/roleassignments/{}",
217 crate::progenitor_support::encode_path(customer),
218 crate::progenitor_support::encode_path(role_assignment_id),
219 ),
220 None,
221 );
222 self.client
223 .get(
224 &url,
225 crate::Message {
226 body: None,
227 content_type: None,
228 },
229 )
230 .await
231 }
232 pub async fn delete(
243 &self,
244 customer: &str,
245 role_assignment_id: &str,
246 ) -> ClientResult<crate::Response<()>> {
247 let url = self.client.url(
248 &format!(
249 "/admin/directory/v1/customer/{}/roleassignments/{}",
250 crate::progenitor_support::encode_path(customer),
251 crate::progenitor_support::encode_path(role_assignment_id),
252 ),
253 None,
254 );
255 self.client
256 .delete(
257 &url,
258 crate::Message {
259 body: None,
260 content_type: None,
261 },
262 )
263 .await
264 }
265}