-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
68 lines (61 loc) · 1.57 KB
/
user.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
package main
import (
"fmt"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
)
func userInfo(cmd *cobra.Command, args []string) {
user, err := host.RequestUserInfo()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to fetch user info:", err)
os.Exit(1)
}
fmt.Println("Name:", user.Name)
fmt.Println("Email:", user.Email)
fmt.Println("UserID:", user.UserID)
fmt.Print("Groups: ")
for _, g := range user.Groups {
var access = "execute"
if g.WriteAccess {
access = "write"
}
fmt.Printf("%s-%s ", g.Name, access)
}
fmt.Println()
}
func userLs(cmd *cobra.Command, args []string) {
users, err := host.UserAll()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to fetch users:", err)
os.Exit(1)
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, columnPadding, ' ', 0)
fmt.Fprintln(w, "NAME\tUSERID\tEMAIL\tID\t")
for _, u := range users {
fmt.Fprintf(w, "%s\t", u.Name)
fmt.Fprintf(w, "%s\t", u.UserID)
fmt.Fprintf(w, "%s\t", u.Email)
fmt.Fprintf(w, "%s\t", u.ID)
fmt.Fprintf(w, "\n")
}
w.Flush()
}
func userCreate(cmd *cobra.Command, args []string) {
email := args[0]
password := args[1]
name := ""
if len(args) > 2 {
name = args[2]
}
if err := host.UserCreate(email, name, password); err != nil {
fmt.Fprintln(os.Stderr, "Failed to create user:", err)
os.Exit(1)
}
if occonfigTrue, _ := cmd.Flags().GetBool("occonfig"); occonfigTrue {
fmt.Printf("framework-server = \"%s\"\n", frameworkHost)
fmt.Printf("mqtt-server = \"%s\"\n", mqttServer)
fmt.Printf("auth-id = \"%s\"\n", email)
fmt.Printf("auth-token = \"%s\"\n", "MUST_GENERATE")
}
}