forked from wavefrontHQ/go-wavefront-management-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roles_example_test.go
80 lines (70 loc) · 1.66 KB
/
roles_example_test.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
79
80
package wavefront_test
import (
"log"
"github.com/WavefrontHQ/go-wavefront-management-api"
)
func ExampleRoles() {
config := &wavefront.Config{
Address: "test.wavefront.com",
Token: "xxxx-xxxx-xxxx-xxxx-xxxx",
}
client, err := wavefront.NewClient(config)
if err != nil {
log.Fatal(err)
}
client.Debug(true)
roles := client.Roles()
role := wavefront.Role{
Name: "test role",
Permissions: []string{
wavefront.AGENT_MANAGEMENT,
wavefront.ALERTS_MANAGEMENT,
wavefront.DASHBOARD_MANAGEMENT,
},
Description: "testing something",
}
// Create the role on Wavefront
err = roles.Create(&role)
if err != nil {
log.Fatal(err)
}
/**
The following Add/Remove Assignees will return an error if the assignee does not exist in wavefront
An assignee is either a UserGroup or User
*/
// Add an assignee
err = roles.AddAssignees([]string{"[email protected]"}, &role)
if err != nil {
log.Fatal(err)
}
// Remove an assignee
err = roles.RemoveAssignees([]string{"[email protected]"}, &role)
if err != nil {
log.Fatal(err)
}
// Revoke a permission
err = roles.RevokePermission(wavefront.ALERTS_MANAGEMENT, []*wavefront.Role{&role})
if err != nil {
log.Fatal(err)
}
// Grant a permission
err = roles.GrantPermission(wavefront.EVENTS_MANAGEMENT, []*wavefront.Role{&role})
if err != nil {
log.Fatal(err)
}
// Get an target by ID
err = roles.Get(&wavefront.Role{ID: role.ID})
if err != nil {
log.Fatal(err)
}
// The ID field is now set, so we can update or delete the Target
role.Description = "new description"
err = roles.Update(&role)
if err != nil {
log.Fatal(err)
}
err = roles.Delete(&role)
if err != nil {
log.Fatal(err)
}
}