-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathperms.go
More file actions
114 lines (86 loc) · 2.31 KB
/
perms.go
File metadata and controls
114 lines (86 loc) · 2.31 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package cmd
import (
"github.com/deis/controller-sdk-go/perms"
"github.com/deis/workflow-cli/pkg/git"
"github.com/deis/workflow-cli/settings"
)
// PermsList prints which users have permissions.
func (d *DeisCmd) PermsList(appID string, admin bool, results int) error {
s, appID, err := permsLoad(d.ConfigFile, appID, admin)
if err != nil {
return err
}
var users []string
var count int
if admin {
if results == defaultLimit {
results = s.Limit
}
users, count, err = perms.ListAdmins(s.Client, results)
} else {
users, err = perms.List(s.Client, appID)
}
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
if admin {
d.Printf("=== Administrators%s", limitCount(len(users), count))
} else {
d.Printf("=== %s's Users\n", appID)
}
for _, user := range users {
d.Println(user)
}
return nil
}
// PermCreate adds a user to an app or makes them an administrator.
func (d *DeisCmd) PermCreate(appID string, username string, admin bool) error {
s, appID, err := permsLoad(d.ConfigFile, appID, admin)
if err != nil {
return err
}
if admin {
d.Printf("Adding %s to system administrators... ", username)
err = perms.NewAdmin(s.Client, username)
} else {
d.Printf("Adding %s to %s collaborators... ", username, appID)
err = perms.New(s.Client, appID, username)
}
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
// PermDelete removes a user from an app or revokes admin privileges.
func (d *DeisCmd) PermDelete(appID, username string, admin bool) error {
s, appID, err := permsLoad(d.ConfigFile, appID, admin)
if err != nil {
return err
}
if admin {
d.Printf("Removing %s from system administrators... ", username)
err = perms.DeleteAdmin(s.Client, username)
} else {
d.Printf("Removing %s from %s collaborators... ", username, appID)
err = perms.Delete(s.Client, appID, username)
}
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
func permsLoad(cf, appID string, admin bool) (*settings.Settings, string, error) {
s, err := settings.Load(cf)
if err != nil {
return nil, "", err
}
if !admin && appID == "" {
appID, err = git.DetectAppName(git.DefaultCmd, s.Client.ControllerURL.Host)
if err != nil {
return nil, "", err
}
}
return s, appID, err
}