generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
user_delete.go
58 lines (45 loc) · 1.17 KB
/
user_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package datumuser
import (
"context"
"encoding/json"
"github.com/spf13/cobra"
"github.com/spf13/viper"
datum "github.com/datumforge/datum/cmd/cli/cmd"
"github.com/datumforge/datum/pkg/datumclient"
)
var userDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete an existing datum user",
RunE: func(cmd *cobra.Command, args []string) error {
return deleteUser(cmd.Context())
},
}
func init() {
userCmd.AddCommand(userDeleteCmd)
userDeleteCmd.Flags().StringP("id", "i", "", "user id to delete")
datum.ViperBindFlag("user.delete.id", userDeleteCmd.Flags().Lookup("id"))
}
func deleteUser(ctx context.Context) error {
// setup datum http client
cli, err := datum.GetGraphClient(ctx)
if err != nil {
return err
}
// save session cookies on function exit
client, _ := cli.Client.(*datumclient.Client)
defer datum.StoreSessionCookies(client)
var s []byte
userID := viper.GetString("user.delete.id")
if userID == "" {
return datum.NewRequiredFieldMissingError("user id")
}
o, err := cli.Client.DeleteUser(ctx, userID, cli.Interceptor)
if err != nil {
return err
}
s, err = json.Marshal(o)
if err != nil {
return err
}
return datum.JSONPrint(s)
}