diff --git a/src/api/identity/entity/requests.rs b/src/api/identity/entity/requests.rs index 1c6b5c8..fa46337 100644 --- a/src/api/identity/entity/requests.rs +++ b/src/api/identity/entity/requests.rs @@ -19,7 +19,7 @@ use super::responses::{ #[builder(setter(into, strip_option), default)] pub struct CreateEntityRequest { /// Name of the entity. - pub name: String, + pub name: Option, /// ID of the entity. If set, updates the corresponding existing entity. pub id: Option, /// Metadata to be associated with the entity. diff --git a/src/api/identity/group/requests.rs b/src/api/identity/group/requests.rs index d2ef78a..8972e23 100644 --- a/src/api/identity/group/requests.rs +++ b/src/api/identity/group/requests.rs @@ -18,7 +18,7 @@ use std::{collections::HashMap, fmt::Debug}; #[builder(setter(into, strip_option), default)] pub struct CreateGroupRequest { /// Name of the group. If set (and ID is not set), updates the corresponding existing group. - pub name: String, + pub name: Option, /// ID of the group. If set, updates the corresponding existing group. pub id: Option, /// Type of the group, internal or external. Defaults to internal. diff --git a/src/identity/entity.rs b/src/identity/entity.rs index c155be0..dc6b7ee 100644 --- a/src/identity/entity.rs +++ b/src/identity/entity.rs @@ -27,11 +27,10 @@ use crate::{ #[instrument(skip(client, opts), err)] pub async fn create( client: &impl Client, - name: &str, opts: Option<&mut CreateEntityRequestBuilder>, ) -> Result<(), ClientError> { let mut t = CreateEntityRequest::builder(); - let endpoint = opts.unwrap_or(&mut t).name(name).build().unwrap(); + let endpoint = opts.unwrap_or(&mut t).build().unwrap(); api::exec_with_empty(client, endpoint).await } diff --git a/src/identity/group.rs b/src/identity/group.rs index 674eb04..7716e43 100644 --- a/src/identity/group.rs +++ b/src/identity/group.rs @@ -24,11 +24,10 @@ use crate::{ #[instrument(skip(client, opts), err)] pub async fn create( client: &impl Client, - name: &str, opts: Option<&mut CreateGroupRequestBuilder>, ) -> Result<(), ClientError> { let mut t = CreateGroupRequest::builder(); - let endpoint = opts.unwrap_or(&mut t).name(name).build().unwrap(); + let endpoint = opts.unwrap_or(&mut t).build().unwrap(); api::exec_with_empty(client, endpoint).await } diff --git a/tests/identity.rs b/tests/identity.rs index 885108c..3470e83 100644 --- a/tests/identity.rs +++ b/tests/identity.rs @@ -93,8 +93,11 @@ fn test_group_and_group_alias() { async fn test_create_entity(client: &VaultClient) -> String { identity::entity::create( client, - ENTITY_NAME, - Some(&mut CreateEntityRequestBuilder::default().policies(vec![POLICY.to_string()])), + Some( + &mut CreateEntityRequestBuilder::default() + .policies(vec![POLICY.to_string()]) + .name(ENTITY_NAME), + ), ) .await .unwrap(); @@ -106,10 +109,10 @@ async fn test_create_entity(client: &VaultClient) -> String { identity::entity::create( client, - ENTITY_NAME, Some( &mut CreateEntityRequestBuilder::default() .disabled(true) + .name(ENTITY_NAME) .id(&entity.id), ), ) @@ -208,12 +211,18 @@ async fn test_delete_entity_by_name(client: &VaultClient) { } async fn test_batch_delete_entity(client: &VaultClient) { - identity::entity::create(client, "test-entity1", None) - .await - .unwrap(); - identity::entity::create(client, "test-entity2", None) - .await - .unwrap(); + identity::entity::create( + client, + Some(CreateEntityRequestBuilder::default().name("test-entity1")), + ) + .await + .unwrap(); + identity::entity::create( + client, + Some(CreateEntityRequestBuilder::default().name("test-entity2")), + ) + .await + .unwrap(); let entity1 = identity::entity::read_by_name(client, "test-entity1") .await .unwrap(); @@ -242,15 +251,24 @@ async fn test_batch_delete_entity(client: &VaultClient) { } async fn test_merge_entity(client: &VaultClient) { - identity::entity::create(client, "test-entity1", None) - .await - .unwrap(); - identity::entity::create(client, "test-entity2", None) - .await - .unwrap(); - identity::entity::create(client, "test-entity3", None) - .await - .unwrap(); + identity::entity::create( + client, + Some(CreateEntityRequestBuilder::default().name("test-entity1")), + ) + .await + .unwrap(); + identity::entity::create( + client, + Some(CreateEntityRequestBuilder::default().name("test-entity2")), + ) + .await + .unwrap(); + identity::entity::create( + client, + Some(CreateEntityRequestBuilder::default().name("test-entity3")), + ) + .await + .unwrap(); let entity1 = identity::entity::read_by_name(client, "test-entity1") .await .unwrap(); @@ -376,8 +394,11 @@ async fn test_list_entity_alias_by_id(client: &VaultClient, alias_id: &str, expe async fn test_create_group(client: &VaultClient) -> String { identity::group::create( client, - GROUP_NAME, - Some(&mut CreateGroupRequestBuilder::default().policies(vec![POLICY.to_string()])), + Some( + &mut CreateGroupRequestBuilder::default() + .policies(vec![POLICY.to_string()]) + .name(GROUP_NAME), + ), ) .await .unwrap(); @@ -391,10 +412,10 @@ async fn test_create_group(client: &VaultClient) -> String { // This one it's called in "updating mode". identity::group::create( client, - GROUP_NAME, Some( &mut CreateGroupRequestBuilder::default() .metadata(metadata.clone()) + .name(GROUP_NAME) .id(&group.id), ), )