-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathusers.go
More file actions
76 lines (63 loc) · 1.72 KB
/
users.go
File metadata and controls
76 lines (63 loc) · 1.72 KB
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
package cmd
import (
"fmt"
"github.com/drycc/controller-sdk-go/users"
"github.com/drycc/workflow-cli/settings"
)
// UsersList lists users registered with the controller.
func (d *DryccCmd) UsersList(results int) error {
s, err := settings.Load(d.ConfigFile)
if err != nil {
return err
}
if results == defaultLimit {
results = s.Limit
}
users, _, err := users.List(s.Client, results)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
table := d.getDefaultFormatTable([]string{"USERNAME", "EMAIL", "ADMIN", "STAFF", "ACTIVE", "DATE-JOIN"})
for _, user := range users {
table.Append([]string{
user.Username,
user.Email,
fmt.Sprintf("%v", user.IsSuperuser),
fmt.Sprintf("%v", user.IsStaff),
fmt.Sprintf("%v", user.IsActive),
user.DateJoined,
})
}
table.Render()
return nil
}
// UsersEnable enable user with the controller.
func (d *DryccCmd) UsersEnable(username string) error {
s, err := settings.Load(d.ConfigFile)
if err != nil {
return err
}
d.Printf("Enabling user %s... ", username)
err = users.Enable(s.Client, username)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
d.Println("This modification is only temporary and will be reverted when the user login again.")
return nil
}
// UsersDisable disable user with the controller.
func (d *DryccCmd) UsersDisable(username string) error {
s, err := settings.Load(d.ConfigFile)
if err != nil {
return err
}
d.Printf("Disabling user %s... ", username)
err = users.Disable(s.Client, username)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
d.Println("This modification is only temporary and will be reverted when the user login again.")
return nil
}