-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_list.go
78 lines (70 loc) · 1.4 KB
/
user_list.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package commands
import (
"golang.org/x/net/context"
"io"
"os"
"strings"
pb "github.com/jaypipes/procession/proto"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
var userListCommand = &cobra.Command{
Use: "list",
Short: "List information about users",
Run: userList,
}
func setupUserListFlags() {
addListOptions(userListCommand)
}
func init() {
setupUserListFlags()
}
func userList(cmd *cobra.Command, args []string) {
checkAuthUser(cmd)
filters := &pb.UserListFilters{}
if len(args) > 0 {
filters.Identifiers = strings.Split(args[0], ",")
}
conn := connect()
defer conn.Close()
client := pb.NewIAMClient(conn)
req := &pb.UserListRequest{
Session: &pb.Session{User: authUser},
Filters: filters,
Options: buildSearchOptions(cmd),
}
stream, err := client.UserList(context.Background(), req)
exitIfConnectErr(err)
users := make([]*pb.User, 0)
for {
user, err := stream.Recv()
if err == io.EOF {
break
}
exitIfForbidden(err)
exitIfError(err)
users = append(users, user)
}
if len(users) == 0 {
exitNoRecords()
}
headers := []string{
"UUID",
"Display Name",
"Email",
"Slug",
}
rows := make([][]string, len(users))
for x, user := range users {
rows[x] = []string{
user.Uuid,
user.DisplayName,
user.Email,
user.Slug,
}
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(headers)
table.AppendBulk(rows)
table.Render()
}