-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathperms.go
More file actions
84 lines (74 loc) · 1.94 KB
/
perms.go
File metadata and controls
84 lines (74 loc) · 1.94 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
77
78
79
80
81
82
83
84
package cmd
import (
"strings"
"github.com/drycc/controller-sdk-go/perms"
)
// PermList prints which users have permissions.
func (d *DryccCmd) PermList(appID string, results int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
perms, _, err := perms.List(s.Client, appID, results)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
table := d.getDefaultFormatTable([]string{"USERNAME", "PERMISSIONS"})
for _, perm := range perms {
p := strings.Join(perm.Permissions, ",")
table.Append([]string{perm.Username, p})
}
table.Render()
return nil
}
// PermCreate create user perms.
func (d *DryccCmd) PermCreate(appID, username, permissions string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Adding user %s as a collaborator for %s... ", username, permissions)
quit := progress(d.WOut)
err = perms.Create(s.Client, appID, username, permissions)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
// PermUpdate update user perms.
func (d *DryccCmd) PermUpdate(appID, username, permissions string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Updating user %s as a collaborator for %s... ", username, permissions)
quit := progress(d.WOut)
err = perms.Update(s.Client, appID, username, permissions)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
// PermDelete removes a user from an app.
func (d *DryccCmd) PermDelete(appID, username string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Removing user permission... ")
quit := progress(d.WOut)
err = perms.Delete(s.Client, appID, username)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}