vaultrs/identity/
group_alias.rs

1use 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            // In the case the response as an empty HTTP Body
37            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
49/// Reads group alias by `id`.
50///
51/// See [ReadGroupAliasByIdRequest]
52pub 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
61/// Update group alias by `id`.
62///
63/// See [UpdateGroupAliasByIdRequest]
64pub 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
80/// Delete group alias by `id`.
81///
82/// See [DeleteGroupAliasByIdRequest]
83pub 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
91/// List groups aliases by ID.
92///
93/// See [ListGroupAliasesByIdRequest]
94pub 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}