Skip to main content

conductor/client/
authorization_client.rs

1// Copyright {{.Year}} Conductor OSS
2// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3
4use crate::error::Result;
5use crate::http::{ApiClient, ApiPath};
6use crate::models::{
7    AccessKey, AccessType, ConductorApplication, ConductorUser, CreateOrUpdateApplicationRequest,
8    CreatedAccessKey, GrantedPermission, Group, MetadataTag, SubjectRef, TargetRef,
9    UpsertGroupRequest, UpsertUserRequest,
10};
11use serde::Deserialize;
12use std::collections::HashMap;
13
14/// Client for authorization operations.
15#[derive(Clone)]
16pub struct AuthorizationClient {
17    api: ApiClient,
18}
19
20/// The server wraps granted-permissions lists in an envelope object rather
21/// than returning a bare JSON array; this mirrors that shape purely for
22/// deserialization so the public methods below can keep returning
23/// `Vec<GrantedPermission>` directly.
24#[derive(Debug, Default, Deserialize)]
25#[serde(rename_all = "camelCase")]
26struct GrantedAccessResponse {
27    #[serde(default)]
28    granted_access: Vec<GrantedPermission>,
29}
30
31impl AuthorizationClient {
32    /// Create a new authorization client.
33    #[must_use]
34    pub fn new(api: ApiClient) -> Self {
35        Self { api }
36    }
37
38    // ===========================
39    // Applications
40    // ===========================
41
42    /// Create an application.
43    ///
44    /// # Errors
45    ///
46    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
47    pub async fn create_application(
48        &self,
49        request: &CreateOrUpdateApplicationRequest,
50    ) -> Result<ConductorApplication> {
51        self.api.post("/applications", request).await
52    }
53
54    /// Get an application by ID.
55    ///
56    /// # Errors
57    ///
58    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
59    pub async fn get_application(&self, application_id: &str) -> Result<ConductorApplication> {
60        let path = format!("/applications/{application_id}");
61        self.api
62            .get(ApiPath::templated(&path, "/applications/{applicationId}"))
63            .await
64    }
65
66    /// List all applications.
67    ///
68    /// # Errors
69    ///
70    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
71    pub async fn list_applications(&self) -> Result<Vec<ConductorApplication>> {
72        self.api.get("/applications").await
73    }
74
75    /// Update an application.
76    ///
77    /// # Errors
78    ///
79    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
80    pub async fn update_application(
81        &self,
82        request: &CreateOrUpdateApplicationRequest,
83        application_id: &str,
84    ) -> Result<ConductorApplication> {
85        let path = format!("/applications/{application_id}");
86        self.api
87            .put(
88                ApiPath::templated(&path, "/applications/{applicationId}"),
89                request,
90            )
91            .await
92    }
93
94    /// Delete an application.
95    ///
96    /// # Errors
97    ///
98    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
99    pub async fn delete_application(&self, application_id: &str) -> Result<()> {
100        let path = format!("/applications/{application_id}");
101        self.api
102            .delete_no_content(ApiPath::templated(&path, "/applications/{applicationId}"))
103            .await
104    }
105
106    /// Get application ID by access key ID.
107    ///
108    /// # Errors
109    ///
110    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
111    pub async fn get_app_by_access_key_id(&self, access_key_id: &str) -> Result<String> {
112        let path = format!("/applications/key/{access_key_id}");
113        self.api
114            .get(ApiPath::templated(&path, "/applications/key/{accessKeyId}"))
115            .await
116    }
117
118    /// Add a role to application user.
119    ///
120    /// # Errors
121    ///
122    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
123    pub async fn add_role_to_application_user(
124        &self,
125        application_id: &str,
126        role: &str,
127    ) -> Result<()> {
128        let path = format!("/applications/{application_id}/roles/{role}");
129        self.api
130            .post_no_body_no_response(ApiPath::templated(
131                &path,
132                "/applications/{applicationId}/roles/{role}",
133            ))
134            .await
135    }
136
137    /// Remove a role from application user.
138    ///
139    /// # Errors
140    ///
141    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
142    pub async fn remove_role_from_application_user(
143        &self,
144        application_id: &str,
145        role: &str,
146    ) -> Result<()> {
147        let path = format!("/applications/{application_id}/roles/{role}");
148        self.api
149            .delete_no_content(ApiPath::templated(
150                &path,
151                "/applications/{applicationId}/roles/{role}",
152            ))
153            .await
154    }
155
156    /// Set tags for an application.
157    ///
158    /// # Errors
159    ///
160    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
161    pub async fn set_application_tags(
162        &self,
163        tags: &[MetadataTag],
164        application_id: &str,
165    ) -> Result<()> {
166        let path = format!("/applications/{application_id}/tags");
167        self.api
168            .put_no_response(
169                ApiPath::templated(&path, "/applications/{applicationId}/tags"),
170                tags,
171            )
172            .await
173    }
174
175    /// Get tags for an application.
176    ///
177    /// # Errors
178    ///
179    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
180    pub async fn get_application_tags(&self, application_id: &str) -> Result<Vec<MetadataTag>> {
181        let path = format!("/applications/{application_id}/tags");
182        self.api
183            .get(ApiPath::templated(
184                &path,
185                "/applications/{applicationId}/tags",
186            ))
187            .await
188    }
189
190    /// Delete tags from an application.
191    ///
192    /// # Errors
193    ///
194    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
195    pub async fn delete_application_tags(
196        &self,
197        tags: &[MetadataTag],
198        application_id: &str,
199    ) -> Result<()> {
200        let path = format!("/applications/{application_id}/tags");
201        self.api
202            .delete_with_body(
203                ApiPath::templated(&path, "/applications/{applicationId}/tags"),
204                tags,
205            )
206            .await
207    }
208
209    /// Create an access key for an application.
210    ///
211    /// # Errors
212    ///
213    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
214    pub async fn create_access_key(&self, application_id: &str) -> Result<CreatedAccessKey> {
215        let path = format!("/applications/{application_id}/accessKeys");
216        self.api
217            .post_no_body(ApiPath::templated(
218                &path,
219                "/applications/{applicationId}/accessKeys",
220            ))
221            .await
222    }
223
224    /// Get access keys for an application.
225    ///
226    /// # Errors
227    ///
228    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
229    pub async fn get_access_keys(&self, application_id: &str) -> Result<Vec<AccessKey>> {
230        let path = format!("/applications/{application_id}/accessKeys");
231        self.api
232            .get(ApiPath::templated(
233                &path,
234                "/applications/{applicationId}/accessKeys",
235            ))
236            .await
237    }
238
239    /// Toggle the status of an access key.
240    ///
241    /// # Errors
242    ///
243    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
244    pub async fn toggle_access_key_status(
245        &self,
246        application_id: &str,
247        key_id: &str,
248    ) -> Result<AccessKey> {
249        let path = format!("/applications/{application_id}/accessKeys/{key_id}/status");
250        self.api
251            .post_no_body(ApiPath::templated(
252                &path,
253                "/applications/{applicationId}/accessKeys/{keyId}/status",
254            ))
255            .await
256    }
257
258    /// Delete an access key.
259    ///
260    /// # Errors
261    ///
262    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
263    pub async fn delete_access_key(&self, application_id: &str, key_id: &str) -> Result<()> {
264        let path = format!("/applications/{application_id}/accessKeys/{key_id}");
265        self.api
266            .delete_no_content(ApiPath::templated(
267                &path,
268                "/applications/{applicationId}/accessKeys/{keyId}",
269            ))
270            .await
271    }
272
273    // ===========================
274    // Users
275    // ===========================
276
277    /// Create or update a user.
278    ///
279    /// # Errors
280    ///
281    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
282    pub async fn upsert_user(
283        &self,
284        request: &UpsertUserRequest,
285        user_id: &str,
286    ) -> Result<ConductorUser> {
287        let path = format!("/users/{user_id}");
288        self.api
289            .put(ApiPath::templated(&path, "/users/{userId}"), request)
290            .await
291    }
292
293    /// Get a user by ID.
294    ///
295    /// # Errors
296    ///
297    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
298    pub async fn get_user(&self, user_id: &str) -> Result<ConductorUser> {
299        let path = format!("/users/{user_id}");
300        self.api
301            .get(ApiPath::templated(&path, "/users/{userId}"))
302            .await
303    }
304
305    /// List all users.
306    ///
307    /// # Errors
308    ///
309    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
310    pub async fn list_users(&self, apps: bool) -> Result<Vec<ConductorUser>> {
311        if apps {
312            self.api
313                .get_with_params("/users", &[("apps", "true")])
314                .await
315        } else {
316            self.api.get("/users").await
317        }
318    }
319
320    /// Delete a user.
321    ///
322    /// # Errors
323    ///
324    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
325    pub async fn delete_user(&self, user_id: &str) -> Result<()> {
326        let path = format!("/users/{user_id}");
327        self.api
328            .delete_no_content(ApiPath::templated(&path, "/users/{userId}"))
329            .await
330    }
331
332    /// Get permissions granted to a user.
333    ///
334    /// # Errors
335    ///
336    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
337    pub async fn get_granted_permissions_for_user(
338        &self,
339        user_id: &str,
340    ) -> Result<Vec<GrantedPermission>> {
341        let path = format!("/users/{user_id}/permissions");
342        let response: GrantedAccessResponse = self
343            .api
344            .get(ApiPath::templated(&path, "/users/{userId}/permissions"))
345            .await?;
346        Ok(response.granted_access)
347    }
348
349    /// Check if user has permissions over a target.
350    ///
351    /// # Errors
352    ///
353    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
354    pub async fn check_permissions(
355        &self,
356        user_id: &str,
357        target_type: &str,
358        target_id: &str,
359    ) -> Result<HashMap<String, bool>> {
360        let path = format!("/users/{user_id}/permissions/{target_type}/{target_id}");
361        self.api
362            .get(ApiPath::templated(
363                &path,
364                "/users/{userId}/permissions/{targetType}/{targetId}",
365            ))
366            .await
367    }
368
369    // ===========================
370    // Groups
371    // ===========================
372
373    /// Create or update a group.
374    ///
375    /// # Errors
376    ///
377    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
378    pub async fn upsert_group(
379        &self,
380        request: &UpsertGroupRequest,
381        group_id: &str,
382    ) -> Result<Group> {
383        let path = format!("/groups/{group_id}");
384        self.api
385            .put(ApiPath::templated(&path, "/groups/{groupId}"), request)
386            .await
387    }
388
389    /// Get a group by ID.
390    ///
391    /// # Errors
392    ///
393    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
394    pub async fn get_group(&self, group_id: &str) -> Result<Group> {
395        let path = format!("/groups/{group_id}");
396        self.api
397            .get(ApiPath::templated(&path, "/groups/{groupId}"))
398            .await
399    }
400
401    /// List all groups.
402    ///
403    /// # Errors
404    ///
405    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
406    pub async fn list_groups(&self) -> Result<Vec<Group>> {
407        self.api.get("/groups").await
408    }
409
410    /// Delete a group.
411    ///
412    /// # Errors
413    ///
414    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
415    pub async fn delete_group(&self, group_id: &str) -> Result<()> {
416        let path = format!("/groups/{group_id}");
417        self.api
418            .delete_no_content(ApiPath::templated(&path, "/groups/{groupId}"))
419            .await
420    }
421
422    /// Get permissions granted to a group.
423    ///
424    /// # Errors
425    ///
426    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
427    pub async fn get_granted_permissions_for_group(
428        &self,
429        group_id: &str,
430    ) -> Result<Vec<GrantedPermission>> {
431        let path = format!("/groups/{group_id}/permissions");
432        let response: GrantedAccessResponse = self
433            .api
434            .get(ApiPath::templated(&path, "/groups/{groupId}/permissions"))
435            .await?;
436        Ok(response.granted_access)
437    }
438
439    /// Add a user to a group.
440    ///
441    /// # Errors
442    ///
443    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
444    pub async fn add_user_to_group(&self, group_id: &str, user_id: &str) -> Result<()> {
445        let path = format!("/groups/{group_id}/users/{user_id}");
446        self.api
447            .post_no_body_no_response(ApiPath::templated(
448                &path,
449                "/groups/{groupId}/users/{userId}",
450            ))
451            .await
452    }
453
454    /// Add multiple users to a group.
455    ///
456    /// # Errors
457    ///
458    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
459    pub async fn add_users_to_group(&self, group_id: &str, user_ids: &[String]) -> Result<()> {
460        let path = format!("/groups/{group_id}/users");
461        self.api
462            .post_no_response(
463                ApiPath::templated(&path, "/groups/{groupId}/users"),
464                user_ids,
465            )
466            .await
467    }
468
469    /// Get all users in a group.
470    ///
471    /// # Errors
472    ///
473    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
474    pub async fn get_users_in_group(&self, group_id: &str) -> Result<Vec<ConductorUser>> {
475        let path = format!("/groups/{group_id}/users");
476        self.api
477            .get(ApiPath::templated(&path, "/groups/{groupId}/users"))
478            .await
479    }
480
481    /// Remove a user from a group.
482    ///
483    /// # Errors
484    ///
485    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
486    pub async fn remove_user_from_group(&self, group_id: &str, user_id: &str) -> Result<()> {
487        let path = format!("/groups/{group_id}/users/{user_id}");
488        self.api
489            .delete_no_content(ApiPath::templated(
490                &path,
491                "/groups/{groupId}/users/{userId}",
492            ))
493            .await
494    }
495
496    /// Remove multiple users from a group.
497    ///
498    /// # Errors
499    ///
500    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
501    pub async fn remove_users_from_group(&self, group_id: &str, user_ids: &[String]) -> Result<()> {
502        let path = format!("/groups/{group_id}/users");
503        self.api
504            .delete_with_body(
505                ApiPath::templated(&path, "/groups/{groupId}/users"),
506                user_ids,
507            )
508            .await
509    }
510
511    // ===========================
512    // Permissions
513    // ===========================
514
515    /// Grant permissions to a subject over a target.
516    ///
517    /// # Errors
518    ///
519    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
520    pub async fn grant_permissions(
521        &self,
522        subject: &SubjectRef,
523        target: &TargetRef,
524        access: &[AccessType],
525    ) -> Result<()> {
526        let body = serde_json::json!({
527            "subject": subject,
528            "target": target,
529            "access": access
530        });
531        self.api
532            .post_no_response("/auth/authorization", &body)
533            .await
534    }
535
536    /// Get permissions for a target.
537    ///
538    /// # Errors
539    ///
540    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
541    pub async fn get_permissions(
542        &self,
543        target: &TargetRef,
544    ) -> Result<HashMap<String, Vec<SubjectRef>>> {
545        // Serialize target_type and extract the string value without quotes
546        let target_type_str = serde_json::to_string(&target.target_type)?;
547        let path = format!(
548            "/auth/authorization/{}/{}",
549            target_type_str.trim_matches('"'),
550            target.id
551        );
552        self.api
553            .get(ApiPath::templated(
554                &path,
555                "/auth/authorization/{targetType}/{targetId}",
556            ))
557            .await
558    }
559
560    /// Remove permissions from a subject over a target.
561    ///
562    /// # Errors
563    ///
564    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
565    pub async fn remove_permissions(
566        &self,
567        subject: &SubjectRef,
568        target: &TargetRef,
569        access: &[AccessType],
570    ) -> Result<()> {
571        let body = serde_json::json!({
572            "subject": subject,
573            "target": target,
574            "access": access
575        });
576        self.api
577            .delete_with_body("/auth/authorization", &body)
578            .await
579    }
580
581    // ===========================
582    // Roles
583    // ===========================
584
585    /// List all roles.
586    ///
587    /// # Errors
588    ///
589    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
590    pub async fn list_all_roles(&self) -> Result<Vec<serde_json::Value>> {
591        self.api.get("/roles").await
592    }
593
594    /// List system roles.
595    ///
596    /// # Errors
597    ///
598    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
599    pub async fn list_system_roles(&self) -> Result<HashMap<String, serde_json::Value>> {
600        self.api.get("/roles/system").await
601    }
602
603    /// List custom roles.
604    ///
605    /// # Errors
606    ///
607    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
608    pub async fn list_custom_roles(&self) -> Result<Vec<serde_json::Value>> {
609        self.api.get("/roles/custom").await
610    }
611
612    /// List available permissions.
613    ///
614    /// # Errors
615    ///
616    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
617    pub async fn list_available_permissions(&self) -> Result<HashMap<String, serde_json::Value>> {
618        self.api.get("/roles/permissions").await
619    }
620
621    /// Create a custom role.
622    ///
623    /// # Errors
624    ///
625    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
626    pub async fn create_role(&self, request: &serde_json::Value) -> Result<serde_json::Value> {
627        self.api.post("/roles", request).await
628    }
629
630    /// Get a role by name.
631    ///
632    /// # Errors
633    ///
634    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
635    pub async fn get_role(&self, role_name: &str) -> Result<serde_json::Value> {
636        let path = format!("/roles/{role_name}");
637        self.api
638            .get(ApiPath::templated(&path, "/roles/{roleName}"))
639            .await
640    }
641
642    /// Update a custom role.
643    ///
644    /// # Errors
645    ///
646    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
647    pub async fn update_role(
648        &self,
649        role_name: &str,
650        request: &serde_json::Value,
651    ) -> Result<serde_json::Value> {
652        let path = format!("/roles/{role_name}");
653        self.api
654            .put(ApiPath::templated(&path, "/roles/{roleName}"), request)
655            .await
656    }
657
658    /// Delete a custom role.
659    ///
660    /// # Errors
661    ///
662    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
663    pub async fn delete_role(&self, role_name: &str) -> Result<()> {
664        let path = format!("/roles/{role_name}");
665        self.api
666            .delete_no_content(ApiPath::templated(&path, "/roles/{roleName}"))
667            .await
668    }
669
670    // ===========================
671    // Token / User Info
672    // ===========================
673
674    /// Get user info from the current token.
675    ///
676    /// # Errors
677    ///
678    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
679    pub async fn get_user_info_from_token(&self) -> Result<serde_json::Value> {
680        self.api.get("/auth/userInfo").await
681    }
682
683    /// Generate a token using access key credentials.
684    ///
685    /// # Errors
686    ///
687    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
688    pub async fn generate_token(
689        &self,
690        key_id: &str,
691        key_secret: &str,
692    ) -> Result<serde_json::Value> {
693        let body = serde_json::json!({
694            "keyId": key_id,
695            "keySecret": key_secret
696        });
697        self.api.post("/token", &body).await
698    }
699
700    // ===========================
701    // API Gateway Authentication Config
702    // ===========================
703
704    /// Create API Gateway authentication configuration.
705    ///
706    /// # Errors
707    ///
708    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
709    pub async fn create_gateway_auth_config(
710        &self,
711        auth_config: &serde_json::Value,
712    ) -> Result<serde_json::Value> {
713        self.api.post("/api-gateway/auth-config", auth_config).await
714    }
715
716    /// Get API Gateway authentication configuration by ID.
717    ///
718    /// # Errors
719    ///
720    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
721    pub async fn get_gateway_auth_config(&self, config_id: &str) -> Result<serde_json::Value> {
722        let path = format!("/api-gateway/auth-config/{config_id}");
723        self.api
724            .get(ApiPath::templated(
725                &path,
726                "/api-gateway/auth-config/{configId}",
727            ))
728            .await
729    }
730
731    /// List all API Gateway authentication configurations.
732    ///
733    /// # Errors
734    ///
735    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
736    pub async fn list_gateway_auth_configs(&self) -> Result<Vec<serde_json::Value>> {
737        self.api.get("/api-gateway/auth-config").await
738    }
739
740    /// Update API Gateway authentication configuration.
741    ///
742    /// # Errors
743    ///
744    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
745    pub async fn update_gateway_auth_config(
746        &self,
747        config_id: &str,
748        auth_config: &serde_json::Value,
749    ) -> Result<serde_json::Value> {
750        let path = format!("/api-gateway/auth-config/{config_id}");
751        self.api
752            .put(
753                ApiPath::templated(&path, "/api-gateway/auth-config/{configId}"),
754                auth_config,
755            )
756            .await
757    }
758
759    /// Delete API Gateway authentication configuration.
760    ///
761    /// # Errors
762    ///
763    /// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
764    pub async fn delete_gateway_auth_config(&self, config_id: &str) -> Result<()> {
765        let path = format!("/api-gateway/auth-config/{config_id}");
766        self.api
767            .delete_no_content(ApiPath::templated(
768                &path,
769                "/api-gateway/auth-config/{configId}",
770            ))
771            .await
772    }
773}
774
775#[cfg(test)]
776mod tests {
777    use super::*;
778    use crate::Configuration;
779
780    #[test]
781    fn test_authorization_client_creation() {
782        let config = Configuration::new("http://localhost:8080/api");
783        let api = ApiClient::new(config).unwrap();
784        let _client = AuthorizationClient::new(api);
785    }
786}