From 2ea8a0ed88e4006f9f38475d1921fbf3c000cb4b Mon Sep 17 00:00:00 2001 From: Firstyear Date: Fri, 23 Aug 2024 16:18:29 +1000 Subject: [PATCH] Expose group rename (#2999) * feat(cli): add group rename --- libs/client/src/group.rs | 5 +++++ tools/cli/src/cli/group/mod.rs | 16 +++++++++++++++- tools/cli/src/opt/kanidm.rs | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libs/client/src/group.rs b/libs/client/src/group.rs index eecac4ef9..68eef5791 100644 --- a/libs/client/src/group.rs +++ b/libs/client/src/group.rs @@ -20,6 +20,11 @@ impl KanidmClient { .await } + pub async fn group_rename(&self, name: &str, new_name: &str) -> Result<(), ClientError> { + self.perform_put_request(&format!("/v1/group/{}/_attr/name", name), vec![new_name]) + .await + } + pub async fn group_account_policy_authsession_expiry_set( &self, id: &str, diff --git a/tools/cli/src/cli/group/mod.rs b/tools/cli/src/cli/group/mod.rs index 9af8c0f70..d86fd3116 100644 --- a/tools/cli/src/cli/group/mod.rs +++ b/tools/cli/src/cli/group/mod.rs @@ -16,7 +16,7 @@ impl GroupOpt { GroupOpt::RemoveMembers(gcopt) => gcopt.copt.debug, GroupOpt::SetMembers(gcopt) => gcopt.copt.debug, GroupOpt::PurgeMembers(gcopt) => gcopt.copt.debug, - GroupOpt::SetMail { copt, .. } => copt.debug, + GroupOpt::Rename { copt, .. } | GroupOpt::SetMail { copt, .. } => copt.debug, GroupOpt::Posix { commands } => match commands { GroupPosix::Show(gcopt) => gcopt.copt.debug, GroupPosix::Set(gcopt) => gcopt.copt.debug, @@ -178,6 +178,20 @@ impl GroupOpt { Ok(_) => println!("Successfully set mail for group {}", name.as_str()), } } + GroupOpt::Rename { + copt, + name, + new_name, + } => { + let client = copt.to_client(OpType::Write).await; + + let result = client.group_rename(name.as_str(), new_name.as_str()).await; + + match result { + Err(e) => handle_client_error(e, copt.output_mode), + Ok(_) => println!("Successfully renamed group {} to {}", name, new_name), + } + } GroupOpt::SetEntryManagedBy { name, entry_managed_by, diff --git a/tools/cli/src/opt/kanidm.rs b/tools/cli/src/opt/kanidm.rs index 053c5acf3..515c68ffe 100644 --- a/tools/cli/src/opt/kanidm.rs +++ b/tools/cli/src/opt/kanidm.rs @@ -284,6 +284,16 @@ pub enum GroupOpt { #[clap(flatten)] copt: CommonOpt, }, + /// Rename an existing group + #[clap(name = "rename")] + Rename { + /// The name of the group + name: String, + /// The new name of the group + new_name: String, + #[clap(flatten)] + copt: CommonOpt, + }, /// Delete all members of a group. #[clap(name = "purge-members")] PurgeMembers(Named),