Skip to main content

dfns_sdk_rust/permissions/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9/// Client for permissions operations.
10#[derive(Clone)]
11pub struct PermissionsClient {
12    client: crate::client::Client,
13}
14
15impl PermissionsClient {
16    pub fn new(client: crate::client::Client) -> Self {
17        PermissionsClient { client }
18    }
19
20    /// Archives or unarchives a permission (role). Archived permissions are effectively soft-deleted.
21    pub async fn archive_permission(
22        &self,
23        permission_id: String,
24        body: ArchivePermissionRequest,
25    ) -> Result<ArchivePermissionResponse, crate::error::Error> {
26        let path = format!(
27            "/permissions/{}/archive",
28            urlencoding::encode(&permission_id)
29        );
30        let body = serde_json::to_value(&body)?;
31        self.client
32            .request::<ArchivePermissionResponse>(reqwest::Method::PUT, &path, Some(&body), true)
33            .await
34    }
35
36    /// Lists all permission (role) assignments for a given permission.
37    pub async fn list_permission_assignments(
38        &self,
39        permission_id: String,
40        query: Option<ListPermissionAssignmentsQuery>,
41    ) -> Result<ListPermissionAssignmentsResponse, crate::error::Error> {
42        let mut path = format!(
43            "/permissions/{}/assignments",
44            urlencoding::encode(&permission_id)
45        );
46        if let Some(query) = &query {
47            let mut q: Vec<String> = Vec::new();
48            if let Some(v) = &query.limit {
49                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
50            }
51            if let Some(v) = &query.pagination_token {
52                q.push(format!(
53                    "paginationToken={}",
54                    urlencoding::encode(&v.to_string())
55                ));
56            }
57            if !q.is_empty() {
58                path.push('?');
59                path.push_str(&q.join("&"));
60            }
61        }
62        self.client
63            .request::<ListPermissionAssignmentsResponse>(reqwest::Method::GET, &path, None, false)
64            .await
65    }
66
67    /// Assigns a permission (role) to an identity (user, PAT or service account), granting it access to the operations defined in the permission. Returns the assignment on success (200), or a pending change request if approval is required (202).
68    pub async fn assign_permission(
69        &self,
70        permission_id: String,
71        body: AssignPermissionRequest,
72    ) -> Result<AssignPermissionResponse, crate::error::Error> {
73        let path = format!(
74            "/permissions/{}/assignments",
75            urlencoding::encode(&permission_id)
76        );
77        let body = serde_json::to_value(&body)?;
78        self.client
79            .request::<AssignPermissionResponse>(reqwest::Method::POST, &path, Some(&body), true)
80            .await
81    }
82
83    /// Lists all permissions (roles) in the organization.
84    pub async fn list_permissions(
85        &self,
86        query: Option<ListPermissionsQuery>,
87    ) -> Result<ListPermissionsResponse, crate::error::Error> {
88        let mut path = String::from("/permissions");
89        if let Some(query) = &query {
90            let mut q: Vec<String> = Vec::new();
91            if let Some(v) = &query.limit {
92                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
93            }
94            if let Some(v) = &query.pagination_token {
95                q.push(format!(
96                    "paginationToken={}",
97                    urlencoding::encode(&v.to_string())
98                ));
99            }
100            if !q.is_empty() {
101                path.push('?');
102                path.push_str(&q.join("&"));
103            }
104        }
105        self.client
106            .request::<ListPermissionsResponse>(reqwest::Method::GET, &path, None, false)
107            .await
108    }
109
110    /// Creates a new permission (also referred to as "role" in the dashboard) that grants access to the specified API operations.
111    pub async fn create_permission(
112        &self,
113        body: CreatePermissionRequest,
114    ) -> Result<CreatePermissionResponse, crate::error::Error> {
115        let path = String::from("/permissions");
116        let body = serde_json::to_value(&body)?;
117        self.client
118            .request::<CreatePermissionResponse>(reqwest::Method::POST, &path, Some(&body), true)
119            .await
120    }
121
122    /// Revokes a permission (role) assignment, removing the identity's access to the operations granted by the permission.
123    pub async fn revoke_permission(
124        &self,
125        permission_id: String,
126        assignment_id: String,
127        query: Option<RevokePermissionQuery>,
128    ) -> Result<(), crate::error::Error> {
129        let mut path = format!(
130            "/permissions/{}/assignments/{}",
131            urlencoding::encode(&permission_id),
132            urlencoding::encode(&assignment_id)
133        );
134        if let Some(query) = &query {
135            let mut q: Vec<String> = Vec::new();
136            if let Some(v) = &query.force {
137                q.push(format!("force={}", urlencoding::encode(&v.to_string())));
138            }
139            if !q.is_empty() {
140                path.push('?');
141                path.push_str(&q.join("&"));
142            }
143        }
144        self.client
145            .request_no_content(reqwest::Method::DELETE, &path, None, true)
146            .await
147    }
148
149    /// Retrieves a permission (role) by ID, including any pending change request.
150    pub async fn get_permission(
151        &self,
152        permission_id: String,
153    ) -> Result<GetPermissionResponse, crate::error::Error> {
154        let path = format!("/permissions/{}", urlencoding::encode(&permission_id));
155        self.client
156            .request::<GetPermissionResponse>(reqwest::Method::GET, &path, None, false)
157            .await
158    }
159
160    /// Updates the name or operations of an existing permission (role).
161    pub async fn update_permission(
162        &self,
163        permission_id: String,
164        body: UpdatePermissionRequest,
165    ) -> Result<UpdatePermissionResponse, crate::error::Error> {
166        let path = format!("/permissions/{}", urlencoding::encode(&permission_id));
167        let body = serde_json::to_value(&body)?;
168        self.client
169            .request::<UpdatePermissionResponse>(reqwest::Method::PUT, &path, Some(&body), true)
170            .await
171    }
172}