From 7dc18e4f9ea98b0222bf7c8ff3ff728cab789521 Mon Sep 17 00:00:00 2001 From: James Hodgkinson Date: Thu, 26 Oct 2023 13:40:45 +1000 Subject: [PATCH] adding service account patch methods (#2255) * adding service_account PATCH --- server/core/src/https/apidocs/mod.rs | 1 + server/core/src/https/v1.rs | 31 ++++++++++++++++++++++++++- server/testkit/tests/proto_v1_test.rs | 9 ++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/server/core/src/https/apidocs/mod.rs b/server/core/src/https/apidocs/mod.rs index 807483c7c..c3d69cf08 100644 --- a/server/core/src/https/apidocs/mod.rs +++ b/server/core/src/https/apidocs/mod.rs @@ -114,6 +114,7 @@ impl Modify for SecurityAddon { super::v1::service_account_post, super::v1::service_account_id_get, super::v1::service_account_id_delete, + super::v1::service_account_id_patch, super::v1::service_account_id_get_attr, super::v1::service_account_id_put_attr, super::v1::service_account_id_post_attr, diff --git a/server/core/src/https/v1.rs b/server/core/src/https/v1.rs index 01ccc6a13..9ab51a159 100644 --- a/server/core/src/https/v1.rs +++ b/server/core/src/https/v1.rs @@ -663,6 +663,33 @@ pub async fn service_account_post( json_rest_event_post(state, classes, obj, kopid).await } +#[utoipa::path( + patch, + path = "/v1/service_account/{id}", + responses( + DefaultApiResponse, + ), + // request_body=ProtoEntry, // TODO: can't deal with a HashMap in the attr + security(("token_jwt" = [])), + tag = "v1/service_account", +)] +pub async fn service_account_id_patch( + State(state): State, + Extension(kopid): Extension, + Path(id): Path, + Json(obj): Json, +) -> Result, WebError> { + // Update a value / attrs + let filter = filter_all!(f_eq(Attribute::Class, EntryClass::Account.into())); + let filter = Filter::join_parts_and(filter, filter_all!(f_id(id.as_str()))); + state + .qe_w_ref + .handle_internalpatch(kopid.uat, filter, obj, kopid.eventid) + .await + .map(Json::from) + .map_err(WebError::from) +} + #[utoipa::path( get, path = "/v1/service_account/{id}", @@ -2945,7 +2972,9 @@ pub(crate) fn route_setup(state: ServerState) -> Router { ) .route( "/v1/service_account/:id", - get(service_account_id_get).delete(service_account_id_delete), + get(service_account_id_get) + .delete(service_account_id_delete) + .patch(service_account_id_patch), ) .route( "/v1/service_account/:id/_attr/:attr", diff --git a/server/testkit/tests/proto_v1_test.rs b/server/testkit/tests/proto_v1_test.rs index 107e07fca..e71378017 100644 --- a/server/testkit/tests/proto_v1_test.rs +++ b/server/testkit/tests/proto_v1_test.rs @@ -1535,16 +1535,17 @@ async fn test_server_api_token_lifecycle(rsclient: KanidmClient) { .idm_service_account_update(test_service_account_username, None, None, None) .await .is_err()); + + // updating the service account details assert!(rsclient .idm_service_account_update( test_service_account_username, - Some(&format!("{}lol", test_service_account_username)), + None, Some(&format!("{}displayzzzz", test_service_account_username)), Some(&[format!("{}@example.crabs", test_service_account_username)]), ) .await - .is_err()); - + .is_ok()); let pw = rsclient .idm_service_account_generate_password(test_service_account_username) .await @@ -1581,8 +1582,6 @@ async fn test_server_api_token_lifecycle(rsclient: KanidmClient) { // .idm_person_account_delete(test_service_account_username) // .await // .is_ok()); - - // No need to test expiry, that's validated in the server internal tests. } #[kanidmd_testkit::test]