From c785b9b3f19fcaab587803e1ef7f584407e289e8 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 23 Oct 2024 20:45:51 +0200 Subject: [PATCH] Implement create- and delete-group. --- galenectl/galenectl.go | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/galenectl/galenectl.go b/galenectl/galenectl.go index c454d45..4fe891d 100644 --- a/galenectl/galenectl.go +++ b/galenectl/galenectl.go @@ -53,6 +53,14 @@ var commands = map[string]command{ command: deletePasswordCmd, description: "delete a user's password", }, + "create-group": { + command: createGroupCmd, + description: "create a group", + }, + "delete-group": { + command: deleteGroupCmd, + description: "delete a group", + }, } func main() { @@ -451,3 +459,55 @@ func deletePasswordCmd(cmdname string, args []string) { log.Fatalf("Delete password: %v", err) } } + +func createGroupCmd(cmdname string, args []string) { + cmd := flag.NewFlagSet(cmdname, flag.ExitOnError) + setUsage(cmd, cmdname, + "%v [option...] %v [option...] group\n", + os.Args[0], cmdname, + ) + cmd.Parse(args) + + if cmd.NArg() != 1 { + cmd.Usage() + os.Exit(1) + } + + url, err := url.JoinPath( + serverURL, "/galene-api/v0/.groups", cmd.Args()[0], + ) + if err != nil { + log.Fatalf("Build URL: %v", err) + } + + err = putJSON(url, map[string]any{}, false) + if err != nil { + log.Fatalf("Create group: %v", err) + } +} + +func deleteGroupCmd(cmdname string, args []string) { + cmd := flag.NewFlagSet(cmdname, flag.ExitOnError) + setUsage(cmd, cmdname, + "%v [option...] %v [option...] group\n", + os.Args[0], cmdname, + ) + cmd.Parse(args) + + if cmd.NArg() != 1 { + cmd.Usage() + os.Exit(1) + } + + url, err := url.JoinPath( + serverURL, "/galene-api/v0/.groups", cmd.Args()[0], + ) + if err != nil { + log.Fatalf("Build URL: %v", err) + } + + err = deleteValue(url) + if err != nil { + log.Fatalf("Delete group: %v", err) + } +}