1use reqwest::Method;
2
3use crate::VaultClient;
4use crate::api::traits::IdentityOperations;
5use crate::client::{encode_path, to_body};
6use crate::types::error::VaultError;
7use crate::types::identity::*;
8
9#[derive(Debug)]
10pub struct IdentityHandler<'a> {
11 pub(crate) client: &'a VaultClient,
12}
13
14impl IdentityOperations for IdentityHandler<'_> {
15 async fn create_entity(&self, params: &EntityCreateRequest) -> Result<Entity, VaultError> {
16 let body = to_body(params)?;
17 self.client
18 .exec_with_data(Method::POST, "identity/entity", Some(&body))
19 .await
20 }
21
22 async fn read_entity(&self, id: &str) -> Result<Entity, VaultError> {
23 self.client
24 .exec_with_data(
25 Method::GET,
26 &format!("identity/entity/id/{}", encode_path(id)),
27 None,
28 )
29 .await
30 }
31
32 async fn read_entity_by_name(&self, name: &str) -> Result<Entity, VaultError> {
33 self.client
34 .exec_with_data(
35 Method::GET,
36 &format!("identity/entity/name/{}", encode_path(name)),
37 None,
38 )
39 .await
40 }
41
42 async fn update_entity(
43 &self,
44 id: &str,
45 params: &EntityCreateRequest,
46 ) -> Result<(), VaultError> {
47 let body = to_body(params)?;
48 self.client
49 .exec_empty(
50 Method::POST,
51 &format!("identity/entity/id/{}", encode_path(id)),
52 Some(&body),
53 )
54 .await
55 }
56
57 async fn delete_entity(&self, id: &str) -> Result<(), VaultError> {
58 self.client
59 .exec_empty(
60 Method::DELETE,
61 &format!("identity/entity/id/{}", encode_path(id)),
62 None,
63 )
64 .await
65 }
66
67 async fn list_entities(&self) -> Result<Vec<String>, VaultError> {
68 self.client.exec_list("identity/entity/id").await
69 }
70
71 async fn create_entity_alias(
72 &self,
73 params: &EntityAliasCreateRequest,
74 ) -> Result<EntityAliasResponse, VaultError> {
75 let body = to_body(params)?;
76 self.client
77 .exec_with_data(Method::POST, "identity/entity-alias", Some(&body))
78 .await
79 }
80
81 async fn read_entity_alias(&self, id: &str) -> Result<EntityAliasResponse, VaultError> {
82 self.client
83 .exec_with_data(
84 Method::GET,
85 &format!("identity/entity-alias/id/{}", encode_path(id)),
86 None,
87 )
88 .await
89 }
90
91 async fn delete_entity_alias(&self, id: &str) -> Result<(), VaultError> {
92 self.client
93 .exec_empty(
94 Method::DELETE,
95 &format!("identity/entity-alias/id/{}", encode_path(id)),
96 None,
97 )
98 .await
99 }
100
101 async fn list_entity_aliases(&self) -> Result<Vec<String>, VaultError> {
102 self.client.exec_list("identity/entity-alias/id").await
103 }
104
105 async fn create_group(&self, params: &GroupCreateRequest) -> Result<Group, VaultError> {
106 let body = to_body(params)?;
107 self.client
108 .exec_with_data(Method::POST, "identity/group", Some(&body))
109 .await
110 }
111
112 async fn read_group(&self, id: &str) -> Result<Group, VaultError> {
113 self.client
114 .exec_with_data(
115 Method::GET,
116 &format!("identity/group/id/{}", encode_path(id)),
117 None,
118 )
119 .await
120 }
121
122 async fn read_group_by_name(&self, name: &str) -> Result<Group, VaultError> {
123 self.client
124 .exec_with_data(
125 Method::GET,
126 &format!("identity/group/name/{}", encode_path(name)),
127 None,
128 )
129 .await
130 }
131
132 async fn update_group(&self, id: &str, params: &GroupCreateRequest) -> Result<(), VaultError> {
133 let body = to_body(params)?;
134 self.client
135 .exec_empty(
136 Method::POST,
137 &format!("identity/group/id/{}", encode_path(id)),
138 Some(&body),
139 )
140 .await
141 }
142
143 async fn delete_group(&self, id: &str) -> Result<(), VaultError> {
144 self.client
145 .exec_empty(
146 Method::DELETE,
147 &format!("identity/group/id/{}", encode_path(id)),
148 None,
149 )
150 .await
151 }
152
153 async fn list_groups(&self) -> Result<Vec<String>, VaultError> {
154 self.client.exec_list("identity/group/id").await
155 }
156
157 async fn create_group_alias(
158 &self,
159 params: &GroupAliasCreateRequest,
160 ) -> Result<GroupAliasResponse, VaultError> {
161 let body = to_body(params)?;
162 self.client
163 .exec_with_data(Method::POST, "identity/group-alias", Some(&body))
164 .await
165 }
166
167 async fn read_group_alias(&self, id: &str) -> Result<GroupAliasResponse, VaultError> {
168 self.client
169 .exec_with_data(
170 Method::GET,
171 &format!("identity/group-alias/id/{}", encode_path(id)),
172 None,
173 )
174 .await
175 }
176
177 async fn delete_group_alias(&self, id: &str) -> Result<(), VaultError> {
178 self.client
179 .exec_empty(
180 Method::DELETE,
181 &format!("identity/group-alias/id/{}", encode_path(id)),
182 None,
183 )
184 .await
185 }
186
187 async fn list_group_aliases(&self) -> Result<Vec<String>, VaultError> {
188 self.client.exec_list("identity/group-alias/id").await
189 }
190}