vaultrs/identity/
group_alias.rs1use crate::{
2 api::{
3 self,
4 identity::group_alias::{
5 requests::{
6 CreateGroupAliasRequest, CreateGroupAliasRequestBuilder,
7 DeleteGroupAliasByIdRequest, ListGroupAliasesByIdRequest,
8 ReadGroupAliasByIdRequest, UpdateGroupAliasByIdRequest,
9 UpdateGroupAliasByIdRequestBuilder,
10 },
11 responses::{
12 CreateGroupAliasResponse, ListGroupAliasesByIdResponse, ReadGroupAliasByIdResponse,
13 },
14 },
15 },
16 client::Client,
17 error::ClientError,
18};
19
20pub async fn create(
21 client: &impl Client,
22 name: &str,
23 mount_accessor: &str,
24 opts: Option<&mut CreateGroupAliasRequestBuilder>,
25) -> Result<CreateGroupAliasResponse, ClientError> {
26 let mut t = CreateGroupAliasRequest::builder();
27 let endpoint = opts
28 .unwrap_or(&mut t)
29 .name(name)
30 .mount_accessor(mount_accessor)
31 .build()
32 .unwrap();
33 api::exec_with_result(client, endpoint)
34 .await
35 .map_err(|err| {
36 if matches!(
38 err,
39 ClientError::RestClientError {
40 source: rustify::errors::ClientError::ResponseParseError { .. }
41 }
42 ) {
43 return ClientError::InvalidUpdateParameter;
44 }
45 err
46 })
47}
48
49pub async fn read_by_id(
53 client: &impl Client,
54 id: &str,
55) -> Result<ReadGroupAliasByIdResponse, ClientError> {
56 let endpoint = ReadGroupAliasByIdRequest::builder().id(id).build().unwrap();
57
58 api::exec_with_result(client, endpoint).await
59}
60
61pub async fn update_by_id(
65 client: &impl Client,
66 id: &str,
67 mount_accessor: &str,
68 opts: Option<&mut UpdateGroupAliasByIdRequestBuilder>,
69) -> Result<(), ClientError> {
70 let mut t = UpdateGroupAliasByIdRequest::builder();
71 let endpoint = opts
72 .unwrap_or(&mut t)
73 .id(id)
74 .mount_accessor(mount_accessor)
75 .build()
76 .unwrap();
77 api::exec_with_empty(client, endpoint).await
78}
79
80pub async fn delete_by_id(client: &impl Client, id: &str) -> Result<(), ClientError> {
84 let endpoint = DeleteGroupAliasByIdRequest::builder()
85 .id(id)
86 .build()
87 .unwrap();
88 api::exec_with_empty(client, endpoint).await
89}
90
91pub async fn list_by_id(client: &impl Client) -> Result<ListGroupAliasesByIdResponse, ClientError> {
95 let endpoint = ListGroupAliasesByIdRequest::builder().build().unwrap();
96 api::exec_with_result(client, endpoint).await
97}