mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-09-13 14:59:09 +00:00
add user commands
This commit is contained in:
parent
78a9b08a6f
commit
ce995fb1a5
12 changed files with 356 additions and 3 deletions
71
user/create.go
Normal file
71
user/create.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/speatzle/go-passbolt-cli/util"
|
||||
"github.com/speatzle/go-passbolt/helper"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// UserCreateCmd Creates a Passbolt User
|
||||
var UserCreateCmd = &cobra.Command{
|
||||
Use: "user",
|
||||
Short: "Creates a Passbolt User",
|
||||
Long: `Creates a Passbolt User and Returns the Users ID`,
|
||||
RunE: UserCreate,
|
||||
}
|
||||
|
||||
func init() {
|
||||
UserCreateCmd.Flags().StringP("username", "u", "", "Username (needs to be a email address)")
|
||||
UserCreateCmd.Flags().StringP("firstname", "f", "", "First Name")
|
||||
UserCreateCmd.Flags().StringP("lastname", "l", "", "Last Name")
|
||||
UserCreateCmd.Flags().StringP("role", "r", "user", "Role of User.\nPossible: user, admin")
|
||||
|
||||
UserCreateCmd.MarkFlagRequired("username")
|
||||
UserCreateCmd.MarkFlagRequired("firstname")
|
||||
UserCreateCmd.MarkFlagRequired("lastname")
|
||||
}
|
||||
|
||||
func UserCreate(cmd *cobra.Command, args []string) error {
|
||||
username, err := cmd.Flags().GetString("username")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
firstname, err := cmd.Flags().GetString("firstname")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lastname, err := cmd.Flags().GetString("lastname")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
role, err := cmd.Flags().GetString("role")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx := util.GetContext()
|
||||
|
||||
client, err := util.GetClient(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Logout(context.TODO())
|
||||
cmd.SilenceUsage = true
|
||||
|
||||
id, err := helper.CreateUser(
|
||||
ctx,
|
||||
client,
|
||||
role,
|
||||
username,
|
||||
firstname,
|
||||
lastname,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Creating User: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("UserID: %v\n", id)
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue