mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-09-13 14:59:09 +00:00
add group commands
This commit is contained in:
parent
1b129332ae
commit
36c8318db1
12 changed files with 398 additions and 0 deletions
79
group/create.go
Normal file
79
group/create.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/speatzle/go-passbolt-cli/util"
|
||||
"github.com/speatzle/go-passbolt/helper"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GroupCreateCmd Creates a Passbolt Group
|
||||
var GroupCreateCmd = &cobra.Command{
|
||||
Use: "group",
|
||||
Short: "Creates a Passbolt Group",
|
||||
Long: `Creates a Passbolt Group and Returns the Groups ID`,
|
||||
RunE: GroupCreate,
|
||||
}
|
||||
|
||||
func init() {
|
||||
GroupCreateCmd.Flags().StringP("name", "n", "", "Group Name")
|
||||
|
||||
GroupCreateCmd.Flags().StringArrayP("users", "u", []string{}, "Users to Add to Group")
|
||||
GroupCreateCmd.Flags().StringArrayP("managers", "m", []string{}, "Managers to Add to Group (atleast 1 is required)")
|
||||
|
||||
GroupCreateCmd.MarkFlagRequired("name")
|
||||
GroupCreateCmd.MarkFlagRequired("managers")
|
||||
}
|
||||
|
||||
func GroupCreate(cmd *cobra.Command, args []string) error {
|
||||
name, err := cmd.Flags().GetString("name")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
users, err := cmd.Flags().GetStringArray("users")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
managers, err := cmd.Flags().GetStringArray("managers")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ops := []helper.GroupMembershipOperation{}
|
||||
for _, user := range users {
|
||||
ops = append(ops, helper.GroupMembershipOperation{
|
||||
UserID: user,
|
||||
IsGroupManager: false,
|
||||
})
|
||||
}
|
||||
for _, manager := range managers {
|
||||
ops = append(ops, helper.GroupMembershipOperation{
|
||||
UserID: manager,
|
||||
IsGroupManager: true,
|
||||
})
|
||||
}
|
||||
|
||||
ctx := util.GetContext()
|
||||
|
||||
client, err := util.GetClient(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Logout(context.TODO())
|
||||
cmd.SilenceUsage = true
|
||||
|
||||
id, err := helper.CreateGroup(
|
||||
ctx,
|
||||
client,
|
||||
name,
|
||||
ops,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Creating Group: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("GroupID: %v\n", id)
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue