blob: cd0189107e4b69576f123e82afa35d03813a6680 [file] [log] [blame]
Samuel A. Falvo IIf9ffaa12014-02-21 15:14:29 -08001// +build acceptance
2
3package monitoring
4
5import (
6 "fmt"
Jon Perritt5eb55b12014-08-18 14:48:23 -05007 identity "github.com/rackspace/gophercloud/openstack/identity/v2"
Samuel A. Falvo IIf9ffaa12014-02-21 15:14:29 -08008 "github.com/rackspace/gophercloud/openstack/utils"
9 "github.com/rackspace/gophercloud/rackspace/monitoring"
10 "github.com/rackspace/gophercloud/rackspace/monitoring/notificationPlans"
Jon Perritt5eb55b12014-08-18 14:48:23 -050011 "testing"
Samuel A. Falvo IIf9ffaa12014-02-21 15:14:29 -080012)
13
14func TestRBACPermissions(t *testing.T) {
15 ao, err := utils.AuthOptions()
16 if err != nil {
17 t.Fatal(err)
18 }
19
20 ao.AllowReauth = true
21 r, err := identity.Authenticate(ao)
22 if err != nil {
23 t.Fatal(err)
24 }
25
26 // Find the cloud monitoring API
27
28 sc, err := identity.GetServiceCatalog(r)
29 if err != nil {
30 t.Fatal(err)
31 }
32
33 ces, err := sc.CatalogEntries()
34 if err != nil {
35 t.Fatal(err)
36 }
37
38 monUrl, err := findMonitoringEndpoint(ces)
39 if err != nil {
40 t.Fatal(err)
41 }
42
43 // Build ourselves an interface to cloud monitoring!
44
45 np := notificationPlans.NewClient(monitoring.Options{
46 Endpoint: monUrl,
47 AuthOptions: ao,
48 Authentication: r,
49 })
50
51 // Try to delete a bogus notification plan
52
53 dr, err := np.Delete("ajkhdlkajhdflkajshdf")
54 if err != nil {
55 fmt.Printf("%#v\n", err)
56 }
57 fmt.Printf("%#v\n", dr)
58}
59
60func findMonitoringEndpoint(ces []identity.CatalogEntry) (string, error) {
61 for _, ce := range ces {
62 if ce.Type == "rax:monitor" {
63 return ce.Endpoints[0].PublicURL, nil
64 }
65 }
66 return "", fmt.Errorf("No monitoring API in the service catalog")
67}