adding service account patch methods (#2255)

* adding service_account PATCH
This commit is contained in:
James Hodgkinson 2023-10-26 13:40:45 +10:00 committed by GitHub
parent 55bd543434
commit 7dc18e4f9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 6 deletions

View file

@ -114,6 +114,7 @@ impl Modify for SecurityAddon {
super::v1::service_account_post, super::v1::service_account_post,
super::v1::service_account_id_get, super::v1::service_account_id_get,
super::v1::service_account_id_delete, super::v1::service_account_id_delete,
super::v1::service_account_id_patch,
super::v1::service_account_id_get_attr, super::v1::service_account_id_get_attr,
super::v1::service_account_id_put_attr, super::v1::service_account_id_put_attr,
super::v1::service_account_id_post_attr, super::v1::service_account_id_post_attr,

View file

@ -663,6 +663,33 @@ pub async fn service_account_post(
json_rest_event_post(state, classes, obj, kopid).await 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<ServerState>,
Extension(kopid): Extension<KOpId>,
Path(id): Path<String>,
Json(obj): Json<ProtoEntry>,
) -> Result<Json<()>, 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( #[utoipa::path(
get, get,
path = "/v1/service_account/{id}", path = "/v1/service_account/{id}",
@ -2945,7 +2972,9 @@ pub(crate) fn route_setup(state: ServerState) -> Router<ServerState> {
) )
.route( .route(
"/v1/service_account/:id", "/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( .route(
"/v1/service_account/:id/_attr/:attr", "/v1/service_account/:id/_attr/:attr",

View file

@ -1535,16 +1535,17 @@ async fn test_server_api_token_lifecycle(rsclient: KanidmClient) {
.idm_service_account_update(test_service_account_username, None, None, None) .idm_service_account_update(test_service_account_username, None, None, None)
.await .await
.is_err()); .is_err());
// updating the service account details
assert!(rsclient assert!(rsclient
.idm_service_account_update( .idm_service_account_update(
test_service_account_username, test_service_account_username,
Some(&format!("{}lol", test_service_account_username)), None,
Some(&format!("{}displayzzzz", test_service_account_username)), Some(&format!("{}displayzzzz", test_service_account_username)),
Some(&[format!("{}@example.crabs", test_service_account_username)]), Some(&[format!("{}@example.crabs", test_service_account_username)]),
) )
.await .await
.is_err()); .is_ok());
let pw = rsclient let pw = rsclient
.idm_service_account_generate_password(test_service_account_username) .idm_service_account_generate_password(test_service_account_username)
.await .await
@ -1581,8 +1582,6 @@ async fn test_server_api_token_lifecycle(rsclient: KanidmClient) {
// .idm_person_account_delete(test_service_account_username) // .idm_person_account_delete(test_service_account_username)
// .await // .await
// .is_ok()); // .is_ok());
// No need to test expiry, that's validated in the server internal tests.
} }
#[kanidmd_testkit::test] #[kanidmd_testkit::test]