vaultrs/identity/
entity_alias.rsuse crate::{
api::{
self,
identity::entity_alias::{
requests::{
CreateEntityAliasRequest, CreateEntityAliasRequestBuilder,
DeleteEntityAliasByIdRequest, ListEntityAliasesByIdRequest,
ReadEntityAliasByIdRequest, UpdateEntityAliasByIdRequest,
UpdateEntityAliasByIdRequestBuilder,
},
responses::{
CreateEntityAliasResponse, ListEntityAliasesByIdResponse,
ReadEntityAliasByIdResponse,
},
},
},
client::Client,
error::ClientError,
};
pub async fn create(
client: &impl Client,
name: &str,
canonical_id: &str,
mount_accessor: &str,
opts: Option<&mut CreateEntityAliasRequestBuilder>,
) -> Result<CreateEntityAliasResponse, ClientError> {
let mut t = CreateEntityAliasRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.name(name)
.canonical_id(canonical_id)
.mount_accessor(mount_accessor)
.build()
.unwrap();
api::exec_with_result(client, endpoint)
.await
.map_err(|err| {
if matches!(
err,
ClientError::RestClientError {
source: rustify::errors::ClientError::ResponseParseError { .. }
}
) {
return ClientError::InvalidUpdateParameter;
}
err
})
}
pub async fn read_by_id(
client: &impl Client,
id: &str,
) -> Result<ReadEntityAliasByIdResponse, ClientError> {
let endpoint = ReadEntityAliasByIdRequest::builder()
.id(id)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn update_by_id(
client: &impl Client,
id: &str,
opts: Option<&mut UpdateEntityAliasByIdRequestBuilder>,
) -> Result<(), ClientError> {
let mut t = UpdateEntityAliasByIdRequest::builder();
let endpoint = opts.unwrap_or(&mut t).id(id).build().unwrap();
api::exec_with_empty(client, endpoint).await
}
pub async fn delete_by_id(client: &impl Client, id: &str) -> Result<(), ClientError> {
let endpoint = DeleteEntityAliasByIdRequest::builder()
.id(id)
.build()
.unwrap();
api::exec_with_empty(client, endpoint).await
}
pub async fn list_by_id(
client: &impl Client,
) -> Result<ListEntityAliasesByIdResponse, ClientError> {
let endpoint = ListEntityAliasesByIdRequest::builder().build().unwrap();
api::exec_with_result(client, endpoint).await
}