dfns_sdk_rust/permissions/
mod.rs1pub mod types;
4
5#[allow(unused_imports)]
6use types::*;
7
8#[derive(Clone)]
10pub struct PermissionsClient {
11 client: crate::client::Client,
12}
13
14impl PermissionsClient {
15 pub fn new(client: crate::client::Client) -> Self {
16 PermissionsClient { client }
17 }
18
19 pub async fn archive_permission(
21 &self,
22 permission_id: String,
23 body: ArchivePermissionRequest,
24 ) -> Result<ArchivePermissionResponse, crate::error::Error> {
25 let path = format!(
26 "/permissions/{}/archive",
27 urlencoding::encode(&permission_id)
28 );
29 let body = serde_json::to_value(&body)?;
30 self.client
31 .request::<ArchivePermissionResponse>(reqwest::Method::PUT, &path, Some(&body), true)
32 .await
33 }
34
35 pub async fn list_permission_assignments(
37 &self,
38 permission_id: String,
39 query: Option<ListPermissionAssignmentsQuery>,
40 ) -> Result<ListPermissionAssignmentsResponse, crate::error::Error> {
41 let mut path = format!(
42 "/permissions/{}/assignments",
43 urlencoding::encode(&permission_id)
44 );
45 if let Some(query) = &query {
46 let mut q: Vec<String> = Vec::new();
47 if let Some(v) = &query.limit {
48 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
49 }
50 if let Some(v) = &query.pagination_token {
51 q.push(format!(
52 "paginationToken={}",
53 urlencoding::encode(&v.to_string())
54 ));
55 }
56 if !q.is_empty() {
57 path.push('?');
58 path.push_str(&q.join("&"));
59 }
60 }
61 self.client
62 .request::<ListPermissionAssignmentsResponse>(reqwest::Method::GET, &path, None, false)
63 .await
64 }
65
66 pub async fn assign_permission(
68 &self,
69 permission_id: String,
70 body: AssignPermissionRequest,
71 ) -> Result<AssignPermissionResponse, crate::error::Error> {
72 let path = format!(
73 "/permissions/{}/assignments",
74 urlencoding::encode(&permission_id)
75 );
76 let body = serde_json::to_value(&body)?;
77 self.client
78 .request::<AssignPermissionResponse>(reqwest::Method::POST, &path, Some(&body), true)
79 .await
80 }
81
82 pub async fn list_permissions(
84 &self,
85 query: Option<ListPermissionsQuery>,
86 ) -> Result<ListPermissionsResponse, crate::error::Error> {
87 let mut path = String::from("/permissions");
88 if let Some(query) = &query {
89 let mut q: Vec<String> = Vec::new();
90 if let Some(v) = &query.limit {
91 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
92 }
93 if let Some(v) = &query.pagination_token {
94 q.push(format!(
95 "paginationToken={}",
96 urlencoding::encode(&v.to_string())
97 ));
98 }
99 if !q.is_empty() {
100 path.push('?');
101 path.push_str(&q.join("&"));
102 }
103 }
104 self.client
105 .request::<ListPermissionsResponse>(reqwest::Method::GET, &path, None, false)
106 .await
107 }
108
109 pub async fn create_permission(
111 &self,
112 body: CreatePermissionRequest,
113 ) -> Result<CreatePermissionResponse, crate::error::Error> {
114 let path = String::from("/permissions");
115 let body = serde_json::to_value(&body)?;
116 self.client
117 .request::<CreatePermissionResponse>(reqwest::Method::POST, &path, Some(&body), true)
118 .await
119 }
120
121 pub async fn revoke_permission(
123 &self,
124 permission_id: String,
125 assignment_id: String,
126 query: Option<RevokePermissionQuery>,
127 ) -> Result<(), crate::error::Error> {
128 let mut path = format!(
129 "/permissions/{}/assignments/{}",
130 urlencoding::encode(&permission_id),
131 urlencoding::encode(&assignment_id)
132 );
133 if let Some(query) = &query {
134 let mut q: Vec<String> = Vec::new();
135 if let Some(v) = &query.force {
136 q.push(format!("force={}", urlencoding::encode(&v.to_string())));
137 }
138 if !q.is_empty() {
139 path.push('?');
140 path.push_str(&q.join("&"));
141 }
142 }
143 self.client
144 .request_no_content(reqwest::Method::DELETE, &path, None, true)
145 .await
146 }
147
148 pub async fn get_permission(
150 &self,
151 permission_id: String,
152 ) -> Result<GetPermissionResponse, crate::error::Error> {
153 let path = format!("/permissions/{}", urlencoding::encode(&permission_id));
154 self.client
155 .request::<GetPermissionResponse>(reqwest::Method::GET, &path, None, false)
156 .await
157 }
158
159 pub async fn update_permission(
161 &self,
162 permission_id: String,
163 body: UpdatePermissionRequest,
164 ) -> Result<UpdatePermissionResponse, crate::error::Error> {
165 let path = format!("/permissions/{}", urlencoding::encode(&permission_id));
166 let body = serde_json::to_value(&body)?;
167 self.client
168 .request::<UpdatePermissionResponse>(reqwest::Method::PUT, &path, Some(&body), true)
169 .await
170 }
171}